Skip to content

Commit b67f3a4

Browse files
authored
surgical linker for linux64 (#5)
1 parent 9a9bdbf commit b67f3a4

File tree

10 files changed

+78
-19
lines changed

10 files changed

+78
-19
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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# app [testCases, config] { r2e: platform "https://github.com/adomurad/r2e-platform/releases/download/0.8.0/o-YITMnvpJZg-zxL2xKiCxBFlJzlEoEwdRY5a39WFZ0.tar.br" }
2-
# app [main!] { r2e: platform "./platform/main.roc" }
32
app [test_cases, config] { r2e: platform "./platform/main.roc" }
43

54
import r2e.Test exposing [test]

build.roc

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ main! = |_args|
1212
native = get_native_target!({})?
1313

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

17-
build_go_target! : { target : RocTarget, host_dir : Str, platform_dir : Str } => Result {} _
18-
build_go_target! = |{ target, host_dir, platform_dir }|
17+
# surgical is built only for linux 64 for now
18+
build_for_surgical_linker!({})
19+
20+
build_for_legacy_linker! : { target : RocTarget, host_dir : Str, platform_dir : Str } => Result {} _
21+
build_for_legacy_linker! = |{ target, host_dir, platform_dir }|
1922

2023
(goos, goarch, prebuilt_binary) =
2124
when target is
@@ -29,7 +32,7 @@ build_go_target! = |{ target, host_dir, platform_dir }|
2932
_ =
3033
Cmd.new("go")
3134
|> Cmd.envs([("GOOS", goos), ("GOARCH", goarch), ("CC", "zig cc")])
32-
|> Cmd.args(["build", "-C", host_dir, "-buildmode=c-archive", "-o", "libhost.a"])
35+
|> Cmd.args(["build", "-C", host_dir, "-buildmode=c-archive", "-o", "libhost.a", "-tags=legacy,netgo"])
3336
|> Cmd.status!()
3437
|> Result.map_err(|err| BuildErr(goos, goarch, Inspect.to_str(err)))?
3538

@@ -89,3 +92,21 @@ get_native_target! = |_|
8992
(Linux, Arm64) -> Ok(LinuxArm64)
9093
(Linux, X64) -> Ok(LinuxX64)
9194
_ -> 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: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import cli.Cmd
44
import cli.Stdout
55

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

910
build_for_legacy_linker! = |{}|
1011
[MacosArm64, MacosX64, LinuxArm64, LinuxX64, WindowsArm64, WindowsX64]
1112
|> List.for_each_try!(
1213
|target|
1314
build_dot_a!(target) |> Result.map_ok(|_| {}) |> Result.map_err(|_| BuildForLegacyLinker),
1415
)
15-
# |> Result.map_err(|_| BuildForLegacyLinker)
16+
|> Result.map_err(|_| BuildForLegacyLinker)
1617

1718
build_dot_a! = |target|
1819
(goos, goarch, zig_target, prebuilt_binary) =
@@ -29,3 +30,21 @@ build_dot_a! = |target|
2930
|> Cmd.args(("build -C host -buildmode c-archive -o ../platform/${prebuilt_binary} -tags legacy,netgo" |> Str.split_on(" ")))
3031
|> Cmd.status!()
3132
|> 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")

host/roc/app.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package roc
22

3-
// #include "app.h"
3+
/*
4+
#include "app.h"
5+
#cgo LDFLAGS: -L.. -lapp
6+
*/
47
import "C"
58

69
import (

platform/InternalTest.roc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ run_tests! = |test_cases, config|
116116
117117
print_result_summary!(results)?
118118
119-
any_failures = results |> List.any(|{ result }| result |> Result.is_err)
119+
any_failures = results |> List.keep_if(|{ type }| type == FinalResult) |> List.any(|{ result }| result |> Result.is_err)
120120
if
121121
any_failures
122122
then

tests/run-all-tests.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ echo "Running roc tests"
1010
roc test ./platform/main.roc || exit 1;
1111

1212
echo "Running debug-tests.roc"
13-
roc --linker=legacy $TEST_DIR/debug-tests.roc --debug || exit 1;
13+
roc $TEST_DIR/debug-tests.roc --debug || exit 1;
1414

1515
echo "Running browser-tests.roc"
16-
roc --linker=legacy $TEST_DIR/browser-tests.roc --headless || exit 1;
16+
roc $TEST_DIR/browser-tests.roc --headless || exit 1;
1717

1818
echo "Running element-tests.roc"
1919
roc --linker=legacy $TEST_DIR/element-tests.roc --headless || exit 1;
@@ -22,7 +22,7 @@ echo "removing the test dir" # should auto remove?
2222
rm -rf testTestDir78
2323

2424
echo "Running configuration-tests.roc"
25-
roc --linker=legacy $TEST_DIR/configuration-tests.roc --headless || exit 1;
25+
roc $TEST_DIR/configuration-tests.roc --headless || exit 1;
2626

2727
if [ -e ./testTestDir78/basicRenamed/index.html ]; then
2828
echo "reports ok"
@@ -39,8 +39,8 @@ else
3939
fi
4040

4141
echo "Running element-assertion-tests.roc"
42-
roc --linker=legacy $TEST_DIR/element-assertion-tests.roc --headless || exit 1;
42+
roc $TEST_DIR/element-assertion-tests.roc --headless || exit 1;
4343

4444
echo "Running env-tests.roc"
45-
THIS_ENV_SHOULD_NOT_BE_EMPTY=secret_value roc --linker=legacy $TEST_DIR/env-tests.roc --headless || exit 1;
45+
THIS_ENV_SHOULD_NOT_BE_EMPTY=secret_value roc $TEST_DIR/env-tests.roc --headless || exit 1;
4646

0 commit comments

Comments
 (0)