From e2daa84a339979273a6acb1c35ee70f1f524a859 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 1 Mar 2023 21:53:03 +0200 Subject: [PATCH] ci: add windows and macos jobs for checking the wasm backend too (#17451) --- .github/workflows/wasm_backend_tests_ci.yml | 66 ++++++++++++++------- cmd/tools/install_binaryen.vsh | 16 +++-- vlib/v/gen/wasm/binaryen/binaryen.c.v | 17 ++++-- 3 files changed, 69 insertions(+), 30 deletions(-) diff --git a/.github/workflows/wasm_backend_tests_ci.yml b/.github/workflows/wasm_backend_tests_ci.yml index bc326b3ce1..460ec0f6a0 100644 --- a/.github/workflows/wasm_backend_tests_ci.yml +++ b/.github/workflows/wasm_backend_tests_ci.yml @@ -72,24 +72,48 @@ jobs: - name: Build examples run: VTEST_ONLY=wasm ./v build-examples -## wasm-backend-macos: -## runs-on: macOS-12 -## if: github.event_name != 'push' || github.event.ref == 'refs/heads/master' || github.event.repository.full_name != 'vlang/v' -## timeout-minutes: 121 -## steps: -## - uses: actions/checkout@v3 -## -## - name: Build V -## run: make -j4 && ./v symlink -githubci -## -## - name: Install binaryen as build dependency for the V WASM backend -## run: ./v cmd/tools/install_binaryen.vsh -## -## - name: Build the V WASM backend -## run: ./v -cc clang -showcc -v cmd/tools/builders/wasm_builder.v -## -## - name: Test the WASM backend -## run: ./v test vlib/v/gen/wasm/tests/ -## -## - name: Build examples -## run: VTEST_ONLY=wasm ./v build-examples + wasm-backend-macos: + runs-on: macOS-12 + if: github.event_name != 'push' || github.event.ref == 'refs/heads/master' || github.event.repository.full_name != 'vlang/v' + timeout-minutes: 121 + steps: + - uses: actions/checkout@v3 + + - name: Build V + run: make -j4 && ./v symlink -githubci + + - name: Install binaryen as build dependency for the V WASM backend + run: ./v cmd/tools/install_binaryen.vsh + + - name: Build the V WASM backend + run: ./v -cc clang -showcc -v cmd/tools/builders/wasm_builder.v + + - name: Test the WASM backend + run: ./v test vlib/v/gen/wasm/tests/ + + - name: Build examples + run: VTEST_ONLY=wasm ./v build-examples + + wasm-backend-windows: + runs-on: windows-2022 + if: github.event_name != 'push' || github.event.ref == 'refs/heads/master' || github.event.repository.full_name != 'vlang/v' + timeout-minutes: 121 + steps: + - uses: actions/checkout@v3 + + - name: Build V + run: .\make.bat -msvc + - name: Symlink V + run: .\v.exe symlink -githubci + + - name: Install binaryen as build dependency for the V WASM backend + run: v cmd/tools/install_binaryen.vsh + + - name: Build the V WASM backend + run: v -cc msvc -showcc -v cmd/tools/builders/wasm_builder.v + + - name: Test the WASM backend + run: v -stats test vlib/v/gen/wasm/tests/ + + - name: Build examples + run: $env:VTEST_ONLY='wasm'; v build-examples diff --git a/cmd/tools/install_binaryen.vsh b/cmd/tools/install_binaryen.vsh index 50d40fa7cf..72546c037c 100755 --- a/cmd/tools/install_binaryen.vsh +++ b/cmd/tools/install_binaryen.vsh @@ -1,8 +1,9 @@ #!/usr/bin/env -S v -raw-vsh-tmp-prefix tmp -import net.http -import json import os +import net.http + +const github_job = os.getenv('GITHUB_JOB') struct JQ { tag_name string @@ -21,8 +22,16 @@ fn main() { exit(1) } + /* + // TODO: add retries here, github requests can fail jq := http.get_text('https://api.github.com/repos/WebAssembly/binaryen/releases/latest') tag := json.decode(JQ, jq)!.tag_name + if github_job != '' { + dump(jq) + dump(tag) + } + */ + tag := 'version_112' name := $if windows { 'x86_64-windows' @@ -50,9 +59,6 @@ fn main() { // defer { os.rm(saveloc) or {}! } } - mkdir_all(loc)! - println(loc) - println('Extracting `${tloc}/${fname}` to `${tloc}/binaryen` ...') cmd := 'tar -xvf ${saveloc} --directory ${tloc}' if os.system(cmd) != 0 { diff --git a/vlib/v/gen/wasm/binaryen/binaryen.c.v b/vlib/v/gen/wasm/binaryen/binaryen.c.v index 3685931dc7..f6632d3193 100644 --- a/vlib/v/gen/wasm/binaryen/binaryen.c.v +++ b/vlib/v/gen/wasm/binaryen/binaryen.c.v @@ -1,10 +1,19 @@ [translated] module binaryen -#flag -I@VEXEROOT/thirdparty/binaryen/include -#flag -L@VEXEROOT/thirdparty/binaryen/lib -#flag -lbinaryen -lstdc++ -#flag darwin -Wl,-rpath,/opt/homebrew/lib -Wl,-rpath,@VEXEROOT/thirdparty/binaryen/lib +$if dynamic_binaryen ? { + #flag -lbinaryen +} $else { + #flag -lbinaryen + #flag -I@VEXEROOT/thirdparty/binaryen/include + #flag -L@VEXEROOT/thirdparty/binaryen/lib + + #flag darwin -lc++ -Wl,-rpath,"@executable_path/../../../thirdparty/binaryen/lib" + // the following, allows linking to the binaryen package from `brew install binaryen`, without having to run cmd/tools/install_binaryen.vsh first + #flag darwin -I/opt/homebrew/include -L/opt/homebrew/lib -Wl,-rpath,"/opt/homebrew/lib" + + #flag linux -lstdc++ +} type Index = u32 type Type = u64