Skip to content

Commit b01b03d

Browse files
committed
fix
1 parent e3841fa commit b01b03d

10 files changed

Lines changed: 209 additions & 0 deletions

File tree

pkgs/roc/lib/Display.roc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module [str, matrix]
2+
str : List (List Str) -> Str
3+
str = |lines|
4+
lines
5+
|> List.map (|ws| Str.join_with(ws, "\t"))
6+
|> Str.join_with("\n")
7+
matrix : List I128 -> List (List Str)
8+
matrix = |list|
9+
List.range { start: At 0, end: At (Result.with_default(List.get(list, 0), 10) - 1) }
10+
|> List.map
11+
(|r|
12+
List.range { start: At 0, end: At (Result.with_default(List.get(list, 1), 10) - 1) }
13+
|> List.map
14+
(|c|
15+
Str.join_with
16+
[
17+
Str.repeat
18+
"0"
19+
(
20+
Str.count_utf8_bytes(
21+
Num.to_str
22+
(
23+
(
24+
Result.with_default(List.get(list, 0), 10)
25+
*
26+
Result.with_default(List.get(list, 1), 10)
27+
)
28+
- 1
29+
),
30+
)
31+
-
32+
Str.count_utf8_bytes(
33+
Num.to_str
34+
(
35+
r * Result.with_default(List.get(list, 1), 10) + c
36+
),
37+
)
38+
),
39+
Num.to_str (r * Result.with_default(List.get(list, 1), 10) + c),
40+
]
41+
""
42+
)
43+
)

pkgs/roc/lib/Hello.roc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module [str]
2+
import Square exposing [f64]
3+
num : F64
4+
num = 8192.0125
5+
str : Str -> Str
6+
str = |language|
7+
Str.join_with(
8+
[
9+
Str.join_with(["Roc loves", language], " "),
10+
Str.join_with([Num.to_str(num), "^2=", Num.to_str(f64(num))], ""),
11+
Str.join_with(["This is a Roc application running on ", language, "."], ""),
12+
"It imports a Roc module and calls a function from it.",
13+
],
14+
"\n",
15+
)

pkgs/roc/lib/Square.roc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module [i128, i64, f64]
2+
i128 : I128 -> I128
3+
i128 = |x| x * x
4+
i64 : I64 -> I64
5+
i64 = |x| x * x
6+
f64 : F64 -> F64
7+
f64 = |x| x * x

pkgs/roc/lib/all.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2086,SC2154
3+
set -exuo pipefail
4+
./hello roc-lang_rust-basic-cli
5+
./hello go-basic-cli
6+
./display go-basic-cli
7+
./hello rust-basic-cli
8+
echo "Done"

pkgs/roc/lib/build.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2086,SC2154
3+
set -exuo pipefail
4+
echo "$0 $*"
5+
usage() {
6+
echo "usage: $0 [--platform p] [--app a] [--static] [--skip-run]"
7+
exit 1
8+
}
9+
trap 'echo aborted; exit 1' INT ERR
10+
platform=${PLATFORM:-go-basic-cli}
11+
application=${APPLICATION:-hello}
12+
static=0
13+
skip_run=0
14+
eval set -- "$(getopt -o "" --long platform:,app:,static,skip-run,help -- "$@")"
15+
if [[ $# -gt 1 ]]; then
16+
while true; do
17+
case ${1:""} in
18+
--platform)
19+
platform=$2
20+
shift 2
21+
;;
22+
--application)
23+
application=$2
24+
shift 2
25+
;;
26+
--app)
27+
application=$2
28+
shift 2
29+
;;
30+
--static)
31+
static=1
32+
shift
33+
;;
34+
--skip-run)
35+
skip_run=1
36+
shift
37+
;;
38+
--help) usage ;;
39+
--)
40+
shift
41+
# break
42+
;;
43+
# *) usage ;;
44+
*)
45+
if [ -z "$1" ]; then
46+
usage
47+
fi
48+
application=$1
49+
shift
50+
if [ "$#" -lt 1 ]; then
51+
break
52+
fi
53+
platform=$1
54+
shift
55+
break
56+
;;
57+
esac
58+
done
59+
fi
60+
platform=${platform:-go-basic-cli}
61+
application=${application:-hello}
62+
platform_path=${PLATFORM_PATH:-./platforms/${platform}}
63+
app_path=${APPLICATION_PATH:-./applications/${application}/${platform}}
64+
app_lib=$app_path/libapp.so
65+
if [[ ! -d $app_path ]]; then
66+
echo "missing dir: $app_path"
67+
exit 1
68+
fi
69+
if [ ! -d "$app_path/Lib" ]; then
70+
ln -s ../../../lib "$app_path/Lib"
71+
fi
72+
app_main=$app_path/main.roc
73+
rm -f "$app_lib" 2>/dev/null || true
74+
roc build --lib "$app_main" --output "$app_lib"
75+
if [[ -d "$platform_path" ]]; then
76+
platform_roc_path="$platform_path"
77+
if [[ -d "$platform_path/platform" ]]; then
78+
platform_roc_path="$platform_path/platform"
79+
fi
80+
if [ ! -d "$platform_roc_path/Lib" ]; then
81+
82+
ln -s ../../../lib "$platform_roc_path/Lib"
83+
fi
84+
host_main=$platform_roc_path/main.roc
85+
abs_app_dir=$(realpath "$app_path")
86+
rel_app_dir="../applications/${application}/${platform}"
87+
pushd "$platform_path" >/dev/null
88+
host_bin=$platform_path/dynhost
89+
roc_build_file="build.roc"
90+
if [[ -e "$roc_build_file" ]]; then
91+
# nix_file="flake.nix"
92+
# if [[ -f "$nix_file" ]] && command -v nix && eval "nix eval --json .#devShell.x86_64-linux >/dev/null 2>&1"; then
93+
# nix develop --command "roc \"$roc_build_file\""
94+
# else
95+
roc "$roc_build_file"
96+
# fi
97+
if [ -d "target/release" ]; then
98+
host_bin="$platform_path/target/release/host"
99+
fi
100+
elif [[ $platform_path == *go-* ]] || [[ $platform_path == *-go ]]; then
101+
# TODO: build.roc?
102+
rm -f "$host_bin" 2>/dev/null || true
103+
export CGO_LDFLAGS="-L${abs_app_dir} -Wl,-rpath,'\$ORIGIN/${rel_app_dir}'"
104+
ldflags=()
105+
((static)) && ldflags=(-ldflags "-extldflags=-static")
106+
go build -buildmode=pie "${ldflags[@]}" -o "$(basename "$host_bin")"
107+
unset CGO_LDFLAGS
108+
fi
109+
popd >/dev/null
110+
roc preprocess-host "$host_bin" "$host_main" "$app_lib"
111+
fi
112+
((skip_run)) || roc "$app_main"

pkgs/roc/lib/display.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2086,SC2154
3+
set -exuo pipefail
4+
./build display "${@}"

pkgs/roc/lib/format.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
set -exuo pipefail
3+
shopt -s globstar nullglob
4+
files=(**/*.roc *.roc)
5+
roc format "${files[@]}"

pkgs/roc/lib/hello.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2086,SC2154
3+
set -exuo pipefail
4+
./build hello "${@}"

pkgs/roc/lib/main.roc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package [
2+
Display,
3+
Hello,
4+
Square,
5+
] {}

pkgs/roc/lib/scripts.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
set -exuo pipefail
3+
chmod +x lib/*.sh
4+
for script in lib/*.sh; do
5+
ln -sf "$script" "$(basename "$script" | sed 's/\.sh$//')"
6+
done

0 commit comments

Comments
 (0)