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" }
2
2
3
3
import cli.Cmd
4
4
5
- main =
5
+ main ! = | _args |
6
6
7
7
# generate glue for builtins and platform
8
8
# Cmd.exec "roc" ["glue", "glue.roc", "host/", "platform/main.roc"]
9
9
# |> Task.mapErr! ErrGeneratingGlue
10
10
11
11
# get the native target
12
- native = getNativeTarget!
12
+ native = get_native_target!({})?
13
13
14
14
# build the target
15
- buildGoTarget! { target: native, hostDir : " host" , platformDir : " platform" }
15
+ build_for_legacy_linker!( { target: native, host_dir : " host" , platform_dir : " platform" })?
16
16
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!({})
19
19
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) =
21
24
when target is
22
25
MacosArm64 -> (" darwin" , " arm64" , " macos-arm64.a" )
23
26
MacosX64 -> (" darwin" , " amd64" , " macos-x64" )
@@ -26,14 +29,15 @@ buildGoTarget = \{ target, hostDir, platformDir } ->
26
29
WindowsArm64 -> (" windows" , " arm64" , " windows-arm64.a" )
27
30
WindowsX64 -> (" windows" , " amd64" , " windows-x64" )
28
31
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 )))?
34
38
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 )) )
37
41
38
42
RocTarget : [
39
43
MacosArm64 ,
@@ -44,42 +48,65 @@ RocTarget : [
44
48
WindowsX64 ,
45
49
]
46
50
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 !()
49
65
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 )))?
56
67
57
68
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 )))?
71
84
72
85
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()
79
88
80
89
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(" " )))
0 commit comments