11app [main] {
2- cli: platform " https://github.com/roc-lang/basic-cli/releases/download/0.12.0/cf_TpThUd4e69C7WzHxCbgsagnDmk3xlb_HmEKXTICw.tar.br" ,
3- weaver: " https://github.com/smores56/weaver/releases/download/0.2.0/BBDPvzgGrYp-AhIDw0qmwxT0pWZIQP_7KOrUrZfp_xw.tar.br" ,
2+ cli: platform " TODO use updated basic-cli 0.12.0 (requires changes from github.com/roc-lang/basic-cli/pull/224)" ,
43}
54
65import cli.Task exposing [Task ]
76import cli.Cmd
87import cli.Stdout
98import cli.Env
109import cli.Arg
11- import weaver.Opt
12- import weaver.Cli
13-
10+ import cli.Arg . Opt as Opt
11+ import cli.Arg . Cli as Cli
12+
13+ ## Builds the basic-cli [platform](https://www.roc-lang.org/platforms).
14+ ##
15+ ## run with: roc ./build.roc --release
16+ ##
17+ main : Task {} _
1418main =
1519
1620 cliParser =
17- Cli . weave {
18- release : <- Opt . flag { short: " r" , long: " release" , help: " Release build" },
19- maybeRoc: <- Opt . maybeStr { short: " c " , long: " cli " , help: " Path to the roc cli " },
21+ Cli . build {
22+ releaseMode : <- Opt . flag { short: " r" , long: " release" , help: " Release build. Passes `--release` to `cargo build`. " },
23+ maybeRoc: <- Opt . maybeStr { short: " p " , long: " roc " , help: " Path to the roc executable. Can be just `roc` or a full path. " },
2024 }
2125 |> Cli . finish {
22- name: " basic-webserver " ,
26+ name: " basic-cli-builder " ,
2327 version: " " ,
2428 authors: [" Luke Boswell <https://github.com/lukewilliamboswell>" ],
25- description: " This build script generates the binaries and packages the platform for distribution ." ,
29+ description: " Generates all files needed by Roc to use this basic-cli platform ." ,
2630 }
2731 |> Cli . assertValid
2832
2933 when Cli . parseOrDisplayMessage cliParser (Arg . list !) is
3034 Ok args -> run args
31- Err message -> Task . err (Exit 1 message )
35+ Err errMsg -> Task . err (Exit 1 errMsg )
3236
33- run = \{ release, maybeRoc } ->
37+ run : { releaseMode : Bool , maybeRoc : Result Str err} -> Task {} _
38+ run = \{ releaseMode, maybeRoc } ->
3439
3540 roc = maybeRoc |> Result . withDefault " roc"
3641
@@ -39,39 +44,40 @@ run = \{ release, maybeRoc } ->
3944 |> Cmd . exec [" glue" , " glue.roc" , " crates/" , " platform/main.roc" ]
4045 |> Task . mapErr ! ErrGeneratingGlue
4146
47+ # target is MacosArm64, LinuxX64,...
4248 info! " Getting the native target ..."
4349 target =
4450 Env . platform
4551 |> Task . await ! getNativeTarget
4652
47- stubPath = " platform/libapp.$( stubExt target) "
53+ stubPath = " platform/libapp.$( stubFileExtension target) "
4854
4955 info! " Building stubbed app shared library ..."
5056 roc
5157 |> Cmd . exec [" build" , " --lib" , " platform/libapp.roc" , " --output" , stubPath]
5258 |> Task . mapErr ! ErrBuildingAppStub
5359
54- (cargoBuildArgs, message ) =
55- if release then
60+ (cargoBuildArgs, infoMessage ) =
61+ if releaseMode then
5662 ([" build" , " --release" ], " Building host in RELEASE mode ..." )
5763 else
5864 ([" build" ], " Building host in DEBUG mode ..." )
5965
60- info! message
66+ info! infoMessage
6167 " cargo"
6268 |> Cmd . exec cargoBuildArgs
6369 |> Task . mapErr ! ErrBuildingHostBinaries
6470
65- hostBuildPath = if release then " target/release/libhost.a" else " target/debug/libhost.a"
66- hostDestPath = " platform/$( prebuiltStaticLibrary target) "
71+ hostBuildPath = if releaseMode then " target/release/libhost.a" else " target/debug/libhost.a"
72+ hostDestPath = " platform/$( prebuiltStaticLibFile target) "
6773
6874 info! " Moving the prebuilt binary from $( hostBuildPath) to $( hostDestPath) ..."
6975 " cp"
7076 |> Cmd . exec [hostBuildPath, hostDestPath]
7177 |> Task . mapErr ! ErrMovingPrebuiltLegacyBinary
7278
7379 info! " Preprocessing surgical host ..."
74- surgicalBuildPath = if release then " target/release/host" else " target/debug/host"
80+ surgicalBuildPath = if releaseMode then " target/release/host" else " target/debug/host"
7581 roc
7682 |> Cmd . exec [" preprocess-host" , surgicalBuildPath, " platform/main.roc" , stubPath]
7783 |> Task . mapErr ! ErrPreprocessingSurgicalBinary
@@ -96,15 +102,15 @@ getNativeTarget =\{os, arch} ->
96102 (LINUX , X64 ) -> Task . ok LinuxX64
97103 _ -> Task . err (UnsupportedNative os arch)
98104
99- stubExt : RocTarget -> Str
100- stubExt = \target ->
105+ stubFileExtension : RocTarget -> Str
106+ stubFileExtension = \target ->
101107 when target is
102108 MacosX64 | MacosArm64 -> " dylib"
103109 LinuxArm64 | LinuxX64 -> " so"
104110 WindowsX64 | WindowsArm64 -> " dll"
105111
106- prebuiltStaticLibrary : RocTarget -> Str
107- prebuiltStaticLibrary = \target ->
112+ prebuiltStaticLibFile : RocTarget -> Str
113+ prebuiltStaticLibFile = \target ->
108114 when target is
109115 MacosArm64 -> " macos-arm64.a"
110116 MacosX64 -> " macos-x64.a"
0 commit comments