diff --git a/examples/GoPlatform/.gitignore b/examples/GoPlatform/.gitignore index 5e9b945..746cd7b 100644 --- a/examples/GoPlatform/.gitignore +++ b/examples/GoPlatform/.gitignore @@ -1,5 +1,11 @@ -platform/libapp.so -platform/dynhost -platform/*.rh -platform/*.rm +host/libapp.so +host/dynhost +host/*.rh +host/*.rm +host/libhost* + +platform/*.a + *.tar.br + +build diff --git a/examples/GoPlatform/build.roc b/examples/GoPlatform/build.roc new file mode 100644 index 0000000..b2c2e33 --- /dev/null +++ b/examples/GoPlatform/build.roc @@ -0,0 +1,51 @@ +app "build-platform-prebuilt-binaries" + packages { + cli: "../../../basic-cli/platform/main.roc", + } + imports [ + cli.Stdout, + cli.Cmd, + cli.Task.{ Task }, + ] + provides [main] to cli + +SupportedTarget : [ + MacosArm64, + MacosX64, + LinuxArm64, + LinuxX64, + WindowsArm64, + WindowsX64, +] + +main = + + buildGoTarget! MacosArm64 + + # TODO -- why is this failing with "build constraints exclude all Go files"? + buildGoTarget! MacosX64 + + # buildGoTarget! LinuxArm64 + # etc + + Stdout.line "DONE" + +buildGoTarget : SupportedTarget -> Task {} _ +buildGoTarget = \target -> + + (goos, goarch, prebuiltBinary) = when target is + MacosArm64 -> ("darwin", "arm64", "macos-arm64.a") + MacosX64 -> ("darwin", "amd64", "macos-x64") + LinuxArm64 -> ("linux", "arm64", "linux-arm64.a") + LinuxX64 -> ("linux", "amd64", "linux-x64.a") + WindowsArm64 -> ("windows", "arm64", "windows-arm64.a") + WindowsX64 -> ("windows", "amd64", "windows-x64") + + Cmd.new "go" + |> Cmd.envs [("GOOS", goos), ("GOARCH", goarch)] + |> Cmd.args ["build", "-C", "host", "-buildmode=c-archive", "-o","libhost.a"] + |> Cmd.status + |> Task.mapErr! \err -> BuildErr goos goarch (Inspect.toStr err) + + Cmd.exec "cp" ["host/libhost.a", "platform/$(prebuiltBinary)"] + |> Task.mapErr! \err -> CpErr (Inspect.toStr err) \ No newline at end of file diff --git a/examples/GoPlatform/build.sh b/examples/GoPlatform/build.sh new file mode 100644 index 0000000..c0d21aa --- /dev/null +++ b/examples/GoPlatform/build.sh @@ -0,0 +1,4 @@ +GOOS=linux GOARCH=arm64 go build -C host -buildmode=c-archive -o libhost.a +cp host/libhost.a platform/macos-arm64.a + +roc dev --prebuilt-platform main.roc \ No newline at end of file diff --git a/examples/GoPlatform/host/go.mod b/examples/GoPlatform/host/go.mod new file mode 100644 index 0000000..86f0587 --- /dev/null +++ b/examples/GoPlatform/host/go.mod @@ -0,0 +1,3 @@ +module host + +go 1.23 diff --git a/examples/GoPlatform/platform/main.go b/examples/GoPlatform/host/host.go similarity index 96% rename from examples/GoPlatform/platform/main.go rename to examples/GoPlatform/host/host.go index 7b2555a..4ac4217 100644 --- a/examples/GoPlatform/platform/main.go +++ b/examples/GoPlatform/host/host.go @@ -1,7 +1,7 @@ package main /* -#cgo LDFLAGS: -L. -lapp +#cgo CFLAGS: -Wno-main-return-type #include "./host.h" */ import "C" @@ -12,6 +12,7 @@ import ( "unsafe" ) +//export main func main() { var str C.struct_RocStr C.roc__mainForHost_1_exposed_generic(&str) diff --git a/examples/GoPlatform/platform/host.h b/examples/GoPlatform/host/host.h similarity index 100% rename from examples/GoPlatform/platform/host.h rename to examples/GoPlatform/host/host.h diff --git a/examples/GoPlatform/platform/go.mod b/examples/GoPlatform/platform/go.mod deleted file mode 100644 index a2b986a..0000000 --- a/examples/GoPlatform/platform/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module roc-with-go - -go 1.21.5