Skip to content

Commit 170a602

Browse files
authored
Merge pull request #6 from adomurad/0.9.0
0.9.0
2 parents 1f1bcd8 + b67f3a4 commit 170a602

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3938
-3284
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ app
1414
*.obj
1515

1616
host/libhost.h
17+
platform/dynhost
18+
platform/linux-x64.rh
19+
metadata_linux-x64.rm
1720

1821
generated files
1922
# host/roc

app.roc

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
app [testCases, config] { r2e: platform "https://github.com/adomurad/r2e-platform/releases/download/0.8.0/o-YITMnvpJZg-zxL2xKiCxBFlJzlEoEwdRY5a39WFZ0.tar.br" }
1+
# app [testCases, config] { r2e: platform "https://github.com/adomurad/r2e-platform/releases/download/0.8.0/o-YITMnvpJZg-zxL2xKiCxBFlJzlEoEwdRY5a39WFZ0.tar.br" }
2+
app [test_cases, config] { r2e: platform "./platform/main.roc" }
23

34
import r2e.Test exposing [test]
45
import r2e.Config
@@ -7,22 +8,25 @@ import r2e.Browser
78
import r2e.Element
89
import r2e.Assert
910

10-
config = Config.defaultConfig
11+
config = Config.default_config
1112

12-
testCases = [test1]
13+
test_cases = [test1]
1314

14-
test1 = test "use roc repl" \browser ->
15-
# go to roc-lang.org
16-
browser |> Browser.navigateTo! "http://roc-lang.org"
17-
# find repl input
18-
replInput = browser |> Browser.findElement! (Css "#source-input")
19-
# wait for the repl to initialize
20-
Debug.wait! 200
21-
# send keys to repl
22-
replInput |> Element.inputText! "0.1+0.2{enter}"
23-
# find repl output element
24-
outputEl = browser |> Browser.findElement! (Css ".output")
25-
# get output text
26-
outputText = outputEl |> Element.getText!
27-
# assert text - fail for demo purpose
28-
outputText |> Assert.shouldBe "0.3000000001 : Frac *"
15+
test1 = test(
16+
"use roc repl",
17+
|browser|
18+
# go to roc-lang.org
19+
browser |> Browser.navigate_to!("http://roc-lang.org")?
20+
# find repl input
21+
repl_input = browser |> Browser.find_element!(Css("#source-input"))?
22+
# wait for the repl to initialize
23+
Debug.wait!(200)
24+
# send keys to repl
25+
repl_input |> Element.input_text!("0.1+0.2{enter}")?
26+
# find repl output element
27+
output_el = browser |> Browser.find_element!(Css(".output"))?
28+
# get output text
29+
output_text = output_el |> Element.get_text!?
30+
# assert text - fail for demo purpose
31+
output_text |> Assert.should_be("0.3000000001 : Frac *"),
32+
)

build.roc

Lines changed: 73 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
app [main] { cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br" }
1+
app [main!] { cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br" }
22

33
import cli.Cmd
44

5-
main =
5+
main! = |_args|
66

77
# generate glue for builtins and platform
88
# Cmd.exec "roc" ["glue", "glue.roc", "host/", "platform/main.roc"]
99
# |> Task.mapErr! ErrGeneratingGlue
1010

1111
# get the native target
12-
native = getNativeTarget!
12+
native = get_native_target!({})?
1313

1414
# build the target
15-
buildGoTarget! { target: native, hostDir: "host", platformDir: "platform" }
15+
build_for_legacy_linker!({ target: native, host_dir: "host", platform_dir: "platform" })?
1616

17-
buildGoTarget : { target : RocTarget, hostDir : Str, platformDir : Str } -> Task {} _
18-
buildGoTarget = \{ target, hostDir, platformDir } ->
17+
# surgical is built only for linux 64 for now
18+
build_for_surgical_linker!({})
1919

20-
(goos, goarch, prebuiltBinary) =
20+
build_for_legacy_linker! : { target : RocTarget, host_dir : Str, platform_dir : Str } => Result {} _
21+
build_for_legacy_linker! = |{ target, host_dir, platform_dir }|
22+
23+
(goos, goarch, prebuilt_binary) =
2124
when target is
2225
MacosArm64 -> ("darwin", "arm64", "macos-arm64.a")
2326
MacosX64 -> ("darwin", "amd64", "macos-x64")
@@ -26,14 +29,15 @@ buildGoTarget = \{ target, hostDir, platformDir } ->
2629
WindowsArm64 -> ("windows", "arm64", "windows-arm64.a")
2730
WindowsX64 -> ("windows", "amd64", "windows-x64")
2831

29-
Cmd.new "go"
30-
|> Cmd.envs [("GOOS", goos), ("GOARCH", goarch), ("CC", "zig cc")]
31-
|> Cmd.args ["build", "-C", hostDir, "-buildmode=c-archive", "-o", "libhost.a"]
32-
|> Cmd.status
33-
|> Task.mapErr! \err -> BuildErr goos goarch (Inspect.toStr err)
32+
_ =
33+
Cmd.new("go")
34+
|> Cmd.envs([("GOOS", goos), ("GOARCH", goarch), ("CC", "zig cc")])
35+
|> Cmd.args(["build", "-C", host_dir, "-buildmode=c-archive", "-o", "libhost.a", "-tags=legacy,netgo"])
36+
|> Cmd.status!()
37+
|> Result.map_err(|err| BuildErr(goos, goarch, Inspect.to_str(err)))?
3438

35-
Cmd.exec "cp" ["$(hostDir)/libhost.a", "$(platformDir)/$(prebuiltBinary)"]
36-
|> Task.mapErr! \err -> CpErr (Inspect.toStr err)
39+
Cmd.exec!("cp", ["${host_dir}/libhost.a", "${platform_dir}/${prebuilt_binary}"])
40+
|> Result.map_err(|err| CpErr(Inspect.to_str(err)))
3741

3842
RocTarget : [
3943
MacosArm64,
@@ -44,42 +48,65 @@ RocTarget : [
4448
WindowsX64,
4549
]
4650

47-
getNativeTarget : Task RocTarget _
48-
getNativeTarget =
51+
get_native_target! : {} => Result RocTarget _
52+
get_native_target! = |_|
53+
54+
arch_from_str = |bytes|
55+
when Str.from_utf8(bytes) is
56+
Ok(str) if str == "arm64\n" -> Arm64
57+
Ok(str) if str == "x86_64\n" -> X64
58+
Ok(str) -> UnsupportedArch(str)
59+
_ -> crash("invalid utf8 from uname -m")
60+
61+
cmd_output =
62+
Cmd.new("uname")
63+
|> Cmd.arg("-m")
64+
|> Cmd.output!()
4965

50-
archFromStr = \bytes ->
51-
when Str.fromUtf8 bytes is
52-
Ok str if str == "arm64\n" -> Arm64
53-
Ok str if str == "x86_64\n" -> X64
54-
Ok str -> UnsupportedArch str
55-
_ -> crash "invalid utf8 from uname -m"
66+
_ = cmd_output.status |> Result.map_err(|err| ErrGettingNativeArch(Inspect.to_str(err)))?
5667

5768
arch =
58-
Cmd.new "uname"
59-
|> Cmd.arg "-m"
60-
|> Cmd.output
61-
|> Task.map .stdout
62-
|> Task.map archFromStr
63-
|> Task.mapErr! \err -> ErrGettingNativeArch (Inspect.toStr err)
64-
65-
osFromStr = \bytes ->
66-
when Str.fromUtf8 bytes is
67-
Ok str if str == "Darwin\n" -> Macos
68-
Ok str if str == "Linux\n" -> Linux
69-
Ok str -> UnsupportedOS str
70-
_ -> crash "invalid utf8 from uname -s"
69+
cmd_output.stdout |> arch_from_str()
70+
71+
os_from_str = |bytes|
72+
when Str.from_utf8(bytes) is
73+
Ok(str) if str == "Darwin\n" -> Macos
74+
Ok(str) if str == "Linux\n" -> Linux
75+
Ok(str) -> UnsupportedOS(str)
76+
_ -> crash("invalid utf8 from uname -s")
77+
78+
os_output =
79+
Cmd.new("uname")
80+
|> Cmd.arg("-s")
81+
|> Cmd.output!()
82+
83+
_ = os_output.status |> Result.map_err(|err| ErrGettingNativeOS(Inspect.to_str(err)))?
7184

7285
os =
73-
Cmd.new "uname"
74-
|> Cmd.arg "-s"
75-
|> Cmd.output
76-
|> Task.map .stdout
77-
|> Task.map osFromStr
78-
|> Task.mapErr! \err -> ErrGettingNativeOS (Inspect.toStr err)
86+
os_output.stdout
87+
|> os_from_str()
7988

8089
when (os, arch) is
81-
(Macos, Arm64) -> Task.ok MacosArm64
82-
(Macos, X64) -> Task.ok MacosX64
83-
(Linux, Arm64) -> Task.ok LinuxArm64
84-
(Linux, X64) -> Task.ok LinuxX64
85-
_ -> Task.err (UnsupportedNative os arch)
90+
(Macos, Arm64) -> Ok(MacosArm64)
91+
(Macos, X64) -> Ok(MacosX64)
92+
(Linux, Arm64) -> Ok(LinuxArm64)
93+
(Linux, X64) -> Ok(LinuxX64)
94+
_ -> Err(UnsupportedNative(os, arch))
95+
96+
build_for_surgical_linker! = |_|
97+
build_libapp_so!({})?
98+
build_dynhost!({})?
99+
preprocess!({})
100+
101+
build_libapp_so! = |_|
102+
Cmd.exec!("roc", ("build --lib ./app.roc --output host/libapp.so" |> Str.split_on(" ")))
103+
104+
build_dynhost! = |_|
105+
Cmd.new("go")
106+
|> Cmd.args(("build -C host -buildmode pie -o ../platform/dynhost" |> Str.split_on(" ")))
107+
|> Cmd.envs([("GOOS", "linux"), ("GOARCH", "amd64"), ("CC", "zig cc")])
108+
|> Cmd.status!
109+
|> Result.map_ok(|_| {})
110+
111+
preprocess! = |_|
112+
Cmd.exec!("roc", ("preprocess-host platform/dynhost platform/main.roc host/libapp.so" |> Str.split_on(" ")))

build_ci.roc

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,50 @@
1-
app [main] { cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br" }
1+
app [main!] { cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br" }
22

33
import cli.Cmd
44
import cli.Stdout
55

6-
main =
7-
buildForLegacyLinker!
6+
main! = |_args|
7+
build_for_legacy_linker!({})?
8+
build_for_surgical_linker!({})
89

9-
buildForLegacyLinker =
10+
build_for_legacy_linker! = |{}|
1011
[MacosArm64, MacosX64, LinuxArm64, LinuxX64, WindowsArm64, WindowsX64]
11-
|> List.map \target -> buildDotA target
12-
|> Task.sequence
13-
|> Task.map \_ -> {}
14-
|> Task.mapErr! \_ -> BuildForLegacyLinker
12+
|> List.for_each_try!(
13+
|target|
14+
build_dot_a!(target) |> Result.map_ok(|_| {}) |> Result.map_err(|_| BuildForLegacyLinker),
15+
)
16+
|> Result.map_err(|_| BuildForLegacyLinker)
1517

16-
buildDotA = \target ->
17-
(goos, goarch, zigTarget, prebuiltBinary) =
18+
build_dot_a! = |target|
19+
(goos, goarch, zig_target, prebuilt_binary) =
1820
when target is
1921
MacosArm64 -> ("darwin", "arm64", "aarch64-macos", "macos-arm64.a")
2022
MacosX64 -> ("darwin", "amd64", "x86_64-macos", "macos-x64.a")
2123
LinuxArm64 -> ("linux", "arm64", "aarch64-linux", "linux-arm64.a")
2224
LinuxX64 -> ("linux", "amd64", " x86_64-linux", "linux-x64.a")
2325
WindowsArm64 -> ("windows", "arm64", "aarch64-windows", "windows-arm64.obj")
2426
WindowsX64 -> ("windows", "amd64", "x86_64-windows", "windows-x64.obj")
25-
Stdout.line! "build host for $(Inspect.toStr target)"
26-
Cmd.new "go"
27-
|> Cmd.envs [("GOOS", goos), ("GOARCH", goarch), ("CC", "zig cc -target $(zigTarget)"), ("CGO_ENABLED", "1")]
28-
|> Cmd.args ("build -C host -buildmode c-archive -o ../platform/$(prebuiltBinary) -tags legacy,netgo" |> Str.split " ")
29-
|> Cmd.status
30-
|> Task.mapErr! \err -> BuildErr target (Inspect.toStr err)
27+
Stdout.line!("build host for ${Inspect.to_str(target)}")?
28+
Cmd.new("go")
29+
|> Cmd.envs([("GOOS", goos), ("GOARCH", goarch), ("CC", "zig cc -target ${zig_target}"), ("CGO_ENABLED", "1")])
30+
|> Cmd.args(("build -C host -buildmode c-archive -o ../platform/${prebuilt_binary} -tags legacy,netgo" |> Str.split_on(" ")))
31+
|> Cmd.status!()
32+
|> Result.map_err(|err| BuildErr(target, Inspect.to_str(err)))
33+
34+
build_for_surgical_linker! = |_|
35+
build_libapp_so!({})?
36+
build_dynhost!({})?
37+
preprocess!({})
38+
39+
build_libapp_so! = |_|
40+
Cmd.exec!("roc", ("build --lib ./app.roc --output host/libapp.so" |> Str.split_on(" ")))
41+
42+
build_dynhost! = |_|
43+
Cmd.new("go")
44+
|> Cmd.args(("build -C host -buildmode pie -o ../platform/dynhost" |> Str.split_on(" ")))
45+
|> Cmd.envs([("GOOS", "linux"), ("GOARCH", "amd64"), ("CC", "zig cc")])
46+
|> Cmd.status!
47+
|> Result.map_ok(|_| {})
48+
49+
preprocess! = |_|
50+
Cmd.exec!("roc", ("preprocess-host platform/dynhost platform/main.roc host/libapp.so" |> Str.split_on(" ")))

host/main-for-legacy.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build legacy
2+
3+
package main
4+
5+
//#cgo CFLAGS: -Wno-main-return-type
6+
import "C"
7+
8+
//export main
9+
func main() {
10+
entry()
11+
}

host/main-for-surgical.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build !legacy
2+
3+
package main
4+
5+
func main() {
6+
entry()
7+
}

host/main.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package main
22

3-
//#cgo CFLAGS: -Wno-main-return-type
4-
import "C"
5-
63
import (
74
"flag"
85
"os"
@@ -11,8 +8,7 @@ import (
118
"host/roc"
129
)
1310

14-
//export main
15-
func main() {
11+
func entry() {
1612
setupOnly := flag.Bool("setup", false, "run only browser and driver setup (useful in CI)")
1713
printBrowserVersionOnly := flag.Bool("print-browser-version-only", false, "print the version of used broweser (useful in CI)")
1814
verbose := flag.Bool("verbose", false, "run with pauses between actions and visualize actions in browser")

0 commit comments

Comments
 (0)