-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Roman Volosatovs <[email protected]>
- Loading branch information
1 parent
aa88a3b
commit 164d130
Showing
26 changed files
with
269 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,8 @@ jobs: | |
strategy: | ||
matrix: | ||
target: | ||
- aarch64-unknown-linux-musl | ||
- aarch64-linux-android | ||
- aarch64-unknown-linux-musl | ||
- riscv64gc-unknown-linux-gnu | ||
- x86_64-pc-windows-gnu | ||
- x86_64-unknown-linux-musl | ||
|
@@ -49,22 +49,24 @@ jobs: | |
matrix: | ||
config: | ||
- os: macos-13 | ||
lib: x86_64-darwin | ||
target: x86_64-apple-darwin | ||
sdk: 10.12 | ||
|
||
- os: macos-14 | ||
lib: aarch64-darwin | ||
target: aarch64-apple-darwin | ||
sdk: 11.0 | ||
|
||
name: west-${{ matrix.config.target }} | ||
runs-on: ${{ matrix.config.os }} | ||
steps: | ||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
- uses: ./.github/actions/install-nix | ||
with: | ||
cachixAuthToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' | ||
- run: nix build -L | ||
- run: nix run -L --inputs-from . 'nixpkgs#coreutils' -- --coreutils-prog=cp -RLv ./result artifact | ||
- run: rustup show | ||
- uses: Swatinem/[email protected] | ||
- run: cargo build -p west-sys --release --target ${{ matrix.config.target }} | ||
env: | ||
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.config.sdk }} | ||
- run: mkdir -p artifact/lib | ||
- run: mv target/${{ matrix.config.target }}/release/libwest_sys.a artifact/lib/libwest_sys.a | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: west-${{ matrix.config.target }} | ||
|
@@ -93,26 +95,43 @@ jobs: | |
- os: ubuntu-latest | ||
lib: x86_64-linux | ||
target: x86_64-unknown-linux-musl | ||
shell: bash | ||
|
||
- os: windows-latest | ||
lib: x86_64-windows | ||
target: x86_64-pc-windows-gnu | ||
shell: msys2 | ||
|
||
- os: macos-13 | ||
lib: x86_64-darwin | ||
target: x86_64-apple-darwin | ||
shell: bash | ||
|
||
- os: macos-14 | ||
lib: aarch64-darwin | ||
target: aarch64-apple-darwin | ||
shell: bash | ||
|
||
name: test-release-${{ matrix.config.target }} | ||
name: test-release (${{ matrix.config.os }}) | ||
needs: | ||
- build-ffi | ||
- build-ffi-darwin | ||
- build-wasm | ||
runs-on: ${{ matrix.config.os }} | ||
defaults: | ||
run: | ||
shell: ${{ matrix.config.shell }} {0} | ||
steps: | ||
- uses: msys2/setup-msys2@v2 | ||
if: matrix.config.os == 'windows-latest' | ||
with: | ||
update: true | ||
install: mingw-w64-x86_64-toolchain | ||
msystem: MINGW64 | ||
path-type: inherit | ||
- run: git config --global core.autocrlf input | ||
if: matrix.config.os == 'windows-latest' | ||
|
||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 | ||
with: | ||
|
@@ -124,46 +143,73 @@ jobs: | |
- run: mv lib/libwest_sys.a "lib/${{ matrix.config.lib }}/libwest.a" | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
go-version-file: go.mod | ||
if: matrix.config.os != 'windows-latest' | ||
- run: rustup show | ||
if: matrix.config.os != 'windows-latest' | ||
- uses: Swatinem/[email protected] | ||
if: matrix.config.os != 'windows-latest' | ||
- uses: cargo-bins/[email protected] | ||
- run: cargo binstall -y [email protected] | ||
- run: go generate ./tests/go/... | ||
- run: go test ./... | ||
- run: go test -failfast ./... | ||
env: | ||
GOGC: 1 | ||
WEST_LOG: trace | ||
continue-on-error: ${{ matrix.config.os == 'ubuntu-latest' || matrix.config.os == 'windows-latest' }} # TODO: remove | ||
continue-on-error: ${{ matrix.config.os == 'ubuntu-latest' }} # TODO: remove | ||
- run: git diff --exit-code | ||
|
||
test-dev: | ||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
- windows-latest | ||
- macos-13 | ||
- macos-14 | ||
|
||
name: test-dev-${{ matrix.os }} | ||
runs-on: ${{ matrix.os }} | ||
config: | ||
- os: ubuntu-latest | ||
shell: bash | ||
|
||
- os: windows-latest | ||
shell: msys2 | ||
|
||
- os: macos-13 | ||
shell: bash | ||
|
||
- os: macos-14 | ||
shell: bash | ||
|
||
runs-on: ${{ matrix.config.os }} | ||
defaults: | ||
run: | ||
shell: ${{ matrix.config.shell }} {0} | ||
steps: | ||
- uses: msys2/setup-msys2@v2 | ||
if: matrix.config.os == 'windows-latest' | ||
with: | ||
update: true | ||
install: mingw-w64-x86_64-toolchain | ||
msystem: MINGW64 | ||
path-type: inherit | ||
- run: git config --global core.autocrlf input | ||
if: matrix.config.os == 'windows-latest' | ||
|
||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
go-version-file: go.mod | ||
|
||
- run: rustup set default-host x86_64-pc-windows-gnu | ||
if: matrix.config.os == 'windows-latest' | ||
- run: rustup show | ||
|
||
- uses: Swatinem/[email protected] | ||
- uses: cargo-bins/[email protected] | ||
- run: cargo binstall -y [email protected] | ||
- run: cargo test --workspace --all-targets | ||
if: matrix.config.os != 'windows-latest' | ||
- run: go generate -tags=dev ./... | ||
- run: go test -tags=dev ./... | ||
- run: go test -failfast -tags=dev ./... | ||
env: | ||
GOGC: 1 | ||
WEST_LOG: trace | ||
continue-on-error: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'windows-latest' }} # TODO: remove | ||
continue-on-error: ${{ matrix.config.os == 'ubuntu-latest' }} # TODO: remove | ||
- run: git diff --exit-code | ||
|
||
gofmt: | ||
|
@@ -172,7 +218,7 @@ jobs: | |
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
go-version-file: go.mod | ||
- run: gofmt -w -s **/*.go | ||
- run: git diff --exit-code | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/target | ||
*.wasm | ||
*.a | ||
*.lib | ||
west_bindings_test.go | ||
/go/internal/tests/*/bindings/* |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//go:build !dev | ||
|
||
//go:generate go run ./internal/generate | ||
|
||
package west |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//go:build dev | ||
|
||
//go:generate go run -tags=dev ./internal/generate | ||
|
||
package west |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//go:build !dev | ||
|
||
package main | ||
|
||
import ( | ||
"path/filepath" | ||
) | ||
|
||
func TargetPath(target string) string { | ||
if target == "" { | ||
return filepath.Join(TargetDir, "release") | ||
} | ||
return filepath.Join(TargetDir, target, "release") | ||
} | ||
|
||
func CargoBuild(target string, args ...string) error { | ||
base := []string{"build", "--release"} | ||
if target != "" { | ||
base = append(base, "--target", target) | ||
} | ||
return RunCargo(append(base, args...)...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//go:build dev | ||
|
||
package main | ||
|
||
import ( | ||
"path/filepath" | ||
) | ||
|
||
func TargetPath(target string) string { | ||
if target == "" { | ||
return filepath.Join(TargetDir, "debug") | ||
} | ||
return filepath.Join(TargetDir, target, "debug") | ||
} | ||
|
||
func CargoBuild(target string, args ...string) error { | ||
base := []string{"build"} | ||
if target != "" { | ||
base = append(base, "--target", target) | ||
} | ||
return RunCargo(append(base, args...)...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"runtime" | ||
) | ||
|
||
var ( | ||
Root = func() string { | ||
_, f, _, _ := runtime.Caller(0) | ||
return filepath.Join(f, "..", "..", "..") | ||
}() | ||
|
||
TargetDir = filepath.Join(Root, "target") | ||
LibDir = filepath.Join(Root, "lib") | ||
) | ||
|
||
func init() { | ||
log.SetFlags(0) | ||
flag.Parse() | ||
} | ||
|
||
func Run(cmd *exec.Cmd) error { | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
return cmd.Run() | ||
} | ||
|
||
func RunCargo(args ...string) error { | ||
return Run(exec.Command("cargo", args...)) | ||
} | ||
|
||
func main() { | ||
if err := Run(exec.Command( | ||
"go", | ||
"run", | ||
"github.com/bytecodealliance/wasm-tools-go/cmd/wit-bindgen-go", | ||
"generate", | ||
"-w", | ||
"imports", | ||
"-o", | ||
"bindings", | ||
filepath.Join(Root, "wit"), | ||
)); err != nil { | ||
log.Fatalf("failed to generate WIT bindings: %s", err) | ||
} | ||
if err := CargoBuild(CARGO_TARGET, "-p", "west-sys"); err != nil { | ||
log.Fatalf("failed to build FFI: %s", err) | ||
} | ||
libTarget := filepath.Join(LibTargetDir, "libwest.a") | ||
if err := os.RemoveAll(libTarget); err != nil { | ||
log.Fatalf("failed to remove FFI: %s", err) | ||
} | ||
if err := os.Link( | ||
filepath.Join(TargetPath(CARGO_TARGET), "libwest_sys.a"), | ||
libTarget, | ||
); err != nil { | ||
log.Fatalf("failed to hard link FFI: %s", err) | ||
} | ||
if err := CargoBuild("wasm32-unknown-unknown", "-p", "west-passthrough"); err != nil { | ||
log.Fatalf("failed to build passthrough component: %s", err) | ||
} | ||
if err := Run(exec.Command( | ||
"wasm-tools", | ||
"component", | ||
"new", | ||
filepath.Join(TargetPath("wasm32-unknown-unknown"), "west_passthrough.wasm"), | ||
"-o", | ||
filepath.Join(LibDir, "passthrough.wasm"), | ||
)); err != nil { | ||
log.Fatalf("failed to create passthrough component: %s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "path/filepath" | ||
|
||
const CARGO_TARGET = "aarch64-linux-android" | ||
|
||
var LibTargetDir = filepath.Join(LibDir, "aarch64-android") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "path/filepath" | ||
|
||
const CARGO_TARGET = "x86_64-apple-darwin" | ||
|
||
var LibTargetDir = filepath.Join(LibDir, "x86_64-darwin") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "path/filepath" | ||
|
||
const CARGO_TARGET = "aarch64-apple-darwin" | ||
|
||
var LibTargetDir = filepath.Join(LibDir, "aarch64-darwin") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "path/filepath" | ||
|
||
const CARGO_TARGET = "x86_64-unknown-linux-gnu" | ||
|
||
var LibTargetDir = filepath.Join(LibDir, "x86_64-linux") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "path/filepath" | ||
|
||
const CARGO_TARGET = "aarch64-unknown-linux-gnu" | ||
|
||
var LibTargetDir = filepath.Join(LibDir, "aarch64-linux") |
Oops, something went wrong.