Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions examples/GoPlatform/.gitignore
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions examples/GoPlatform/build.roc
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions examples/GoPlatform/build.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions examples/GoPlatform/host/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module host

go 1.23
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

/*
#cgo LDFLAGS: -L. -lapp
#cgo CFLAGS: -Wno-main-return-type
#include "./host.h"
*/
import "C"
Expand All @@ -12,6 +12,7 @@ import (
"unsafe"
)

//export main
func main() {
var str C.struct_RocStr
C.roc__mainForHost_1_exposed_generic(&str)
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions examples/GoPlatform/platform/go.mod

This file was deleted.