Repository: wasmerio/winterjs (language: rust)

Issue:
Build Error on MacOS
## System Info
- M2 Macbook pro
- 14.2 Beta (23C5055b)
- Rustup 1.26.0 
- cargo 1.76.0

## Log
```
cargo install --git https://github.com/wasmerio/winterjs winterjs
    Updating git repository `https://github.com/wasmerio/winterjs`
  Installing winterjs v0.4.3 (https://github.com/wasmerio/winterjs#2af3bfa1)
    Updating git repository `https://github.com/wasix-org/h2.git`
    Updating git repository `https://github.com/wasix-org/hyper`
    Updating git repository `https://github.com/wasix-org/hyper-rustls.git`
    Updating git repository `https://github.com/wasix-org/libc.git`
    Updating git repository `https://github.com/wasix-org/mio.git`
    Updating git repository `https://github.com/wasix-org/rustls.git`
    Updating git repository `https://github.com/wasix-org/socket2.git`
    Updating git repository `https://github.com/wasix-org/tokio.git`
    Updating crates.io index
    Updating git repository `https://github.com/wasmerio/spiderfire.git`
    Updating git repository `https://github.com/wasmerio/mozjs.git`
    Updating git repository `https://github.com/wasix-org/static-web-server`
    Updating git repository `https://github.com/wasix-org/rustls-native-certs.git`
    Updating git repository `https://github.com/wasix-org/tokio-rustls.git`
    Updating git repository `https://github.com/wasix-org/ring.git`
    Updating git repository `https://github.com/wasix-org/sct.git`
    Updating git repository `https://github.com/wasix-org/webpki.git`
    Updating git repository `https://github.com/wasix-org/libc.git`
    Updating git repository `https://github.com/wasix-org/signal-hook.git`
    Updating git repository `https://github.com/wasix-org/webpki-roots.git`
   Compiling proc-macro2 v1.0.79
   Compiling unicode-ident v1.0.12
   Compiling libc v0.2.152 (https://github.com/wasix-org/libc.git?branch=v0.2.152#26f165f1)
   Compiling cfg-if v1.0.0
   Compiling version_check v0.9.4
   Compiling autocfg v1.1.0
   Compiling serde v1.0.197
   Compiling cc v1.0.90
   Compiling pin-project-lite v0.2.13
   Compiling memchr v2.7.1
   Compiling itoa v1.0.10
   Compiling regex-syntax v0.8.2
   Compiling once_cell v1.19.0
   Compiling aho-corasick v1.1.2
   Compiling lazy_static v1.4.0
   Compiling tracing-core v0.1.32
   Compiling smallvec v1.13.1
   Compiling typenum v1.17.0
   Compiling num-traits v0.2.18
   Compiling regex-automata v0.4.6
   Compiling generic-array v0.14.7
   Compiling futures-core v0.3.30
   Compiling tinyvec_macros v0.1.1
   Compiling tinyvec v1.6.0
   Compiling regex v1.10.3
   Compiling percent-encoding v2.3.1
   Compiling rand_core v0.6.4
   Compiling fnv v1.0.7
   Compiling siphasher v0.3.11
   Compiling phf_shared v0.11.2
   Compiling rand v0.8.5
   Compiling form_urlencoded v1.2.1
   Compiling unicode-normalization v0.1.23
   Compiling unicode-width v0.1.11
   Compiling unicode-bidi v0.3.15
   Compiling serde_json v1.0.114
   Compiling idna v0.5.0
   Compiling phf_generator v0.11.2
   Compiling ryu v1.0.17
   Compiling subtle v2.5.0
   Compiling hashbrown v0.14.3
   Compiling either v1.10.0
   Compiling quote v1.0.35
   Compiling syn v2.0.52
   Compiling url v2.5.0
   Compiling Inflector v0.11.4
   Compiling slab v0.4.9
   Compiling getrandom v0.2.12
   Compiling num_cpus v1.16.0
   Compiling uuid v1.7.0
   Compiling futures-sink v0.3.30
   Compiling glob v0.3.1
   Compiling anyhow v1.0.81
   Compiling num-bigint v0.4.4
   Compiling clang-sys v1.7.0
   Compiling unicode-id v0.3.4
   Compiling arc-swap v0.4.8
   Compiling new_debug_unreachable v1.0.4
   Compiling equivalent v1.0.1
   Compiling data-encoding v2.5.0
   Compiling rustix v0.38.31
   Compiling if_chain v1.0.2
   Compiling rustc-hash v1.1.0
   Compiling bitflags v2.4.2
   Compiling signal-hook-registry v1.1.1 (https://github.com/wasix-org/signal-hook.git?branch=registry-v1.1.1#3de7855b)
   Compiling errno v0.3.8
   Compiling indexmap v2.2.5
   Compiling num-integer v0.1.46
   Compiling futures-channel v0.3.30
   Compiling socket2 v0.5.5 (https://github.com/wasix-org/socket2.git?branch=v0.5.5#87e78d44)
   Compiling mio v0.8.9 (https://github.com/wasix-org/mio.git?branch=v0.8.9#f55de7d1)
   Compiling crypto-common v0.1.6
   Compiling block-buffer v0.10.4
   Compiling lock_api v0.4.11
   Compiling pin-utils v0.1.0
   Compiling parking_lot_core v0.9.9
   Compiling futures-task v0.3.30
   Compiling futures-io v0.3.30
   Compiling scoped-tls v1.0.1
   Compiling minimal-lexical v0.2.1
   Compiling thiserror v1.0.58
   Compiling nom v7.1.3
   Compiling better_scoped_tls v0.1.1
   Compiling libloading v0.8.3
   Compiling swc_macros_common v0.3.9
   Compiling digest v0.10.7
   Compiling cpufeatures v0.2.12
   Compiling atty v0.2.14
   Compiling unicase v2.7.0
   Compiling home v0.5.9
   Compiling log v0.4.21
   Compiling termcolor v1.4.1
   Compiling scopeguard v1.2.0
   Compiling bindgen v0.68.1
   Compiling rustversion v1.0.14
   Compiling which v4.4.2
   Compiling cexpr v0.6.0
   Compiling ring v0.17.7 (https://github.com/wasix-org/ring.git?branch=0.17.7#be27e9a6)
   Compiling core-foundation-sys v0.8.6
   Compiling pkg-config v0.3.30
   Compiling shlex v1.3.0
   Compiling serde_derive v1.0.197
   Compiling tracing-attributes v0.1.27
   Compiling phf_macros v0.11.2
   Compiling swc_visit_macros v0.5.11
   Compiling phf v0.11.2
   Compiling hstr v0.2.7
   Compiling tracing v0.1.40
   Compiling futures-macro v0.3.30
   Compiling tokio-macros v2.2.0 (https://github.com/wasix-org/tokio.git?branch=wasix-1.35.1#833de725)
   Compiling swc_eq_ignore_macros v0.1.3
   Compiling swc_visit v0.5.10
   Compiling futures-util v0.3.30
   Compiling from_variant v0.1.7
   Compiling ast_node v0.9.6
   Compiling is-macro v0.3.5
   Compiling string_enum v0.4.2
   Compiling thiserror-impl v1.0.58
   Compiling vcpkg v0.2.15
   Compiling peeking_take_while v0.1.2
   Compiling lazycell v1.3.0
   Compiling libz-sys v1.1.15
   Compiling psm v0.1.21
   Compiling bytes v1.5.0
   Compiling debugid v0.8.0
   Compiling swc_atoms v0.6.5
   Compiling base64 v0.21.7
   Compiling same-file v1.0.6
   Compiling tokio v1.35.1 (https://github.com/wasix-org/tokio.git?branch=wasix-1.35.1#833de725)
   Compiling http v0.2.12
   Compiling sourcemap v6.4.1
   Compiling swc_common v0.33.19
   Compiling encoding_c_mem v0.2.6
   Compiling encoding_c v0.9.8
   Compiling spin v0.9.8
   Compiling walkdir v2.5.0
   Compiling stacker v0.1.15
   Compiling smartstring v1.0.1
   Compiling ahash v0.8.11
   Compiling camino v1.1.6
   Compiling semver v1.0.22
   Compiling swc_ecma_ast v0.112.5
   Compiling unicode-segmentation v1.11.0
   Compiling httparse v1.8.0
   Compiling untrusted v0.9.0
   Compiling mozjs_sys v0.68.2 (https://github.com/wasmerio/mozjs.git?branch=wasi-gecko#91349dc0)
   Compiling encoding_rs v0.8.33
   Compiling typed-arena v2.0.2
   Compiling mime v0.3.17
   Compiling syn v1.0.109
   Compiling bitflags v1.3.2
   Compiling zerocopy v0.7.32
   Compiling static_assertions v1.1.0
   Compiling swc_ecma_visit v0.98.6
   Compiling mime_guess v2.0.4
   Compiling tokio-util v0.7.10 (https://github.com/wasix-org/tokio.git?branch=wasix-1.35.1#833de725)
error: failed to run custom build command for `mozjs_sys v0.68.2 (https://github.com/wasmerio/mozjs.git?branch=wasi-gecko#91349dc0)`

Caused by:
  process didn't exit successfully: `/var/folders/kz/yrcq8n4n6_v14nj1006m7r940000gn/T/cargo-install132gyE/release/build/mozjs_sys-6e1e5710c5169c96/build-script-build` (exit status: 101)
  --- stdout
  cargo:outdir=/var/folders/kz/yrcq8n4n6_v14nj1006m7r940000gn/T/cargo-install132gyE/release/build/mozjs_sys-e2942f4e27260e91/out/build
  [[ '/Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys'/mozjs/js/src/configure -ot '/Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys'/mozjs/js/src/configure.in ]] && touch '/Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys'/mozjs/js/src/configure || true
  [[ '/Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys'/mozjs/js/src/old-configure -ot '/Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys'/mozjs/js/src/old-configure.in ]] && touch '/Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys'/mozjs/js/src/old-configure || true
  ! [[ '/Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys'/mozjs/js/src/configure.in -ot '/Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys'/mozjs/js/src/configure ]] && touch '/Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys'/mozjs/js/src/configure || true
  ! [[ '/Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys'/mozjs/js/src/old-configure.in -ot '/Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys'/mozjs/js/src/old-configure ]] && touch '/Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys'/mozjs/js/src/old-configure || true
  if [[ '/Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys'/mozjs/js/src/configure -nt config.status ]] ; then \
  	  CC="cc" CFLAGS="" \
  	  CPP="cc -E" CPPFLAGS="-I/Users/eveeify/.cargo/registry/src/index.crates.io-6f17d22bba15001f/encoding_c_mem-0.2.6/include " \
  	  CXX="c++" CXXFLAGS="-stdlib=libc++" \
  	  AS="" AR="ar" \
  	  '/Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys'/mozjs/js/src/configure --disable-jemalloc --disable-js-shell --disable-tests --disable-export-js --disable-shared-js --build-backends=RecursiveMake --enable-js-streams || (cat config.log && exit 1) ; \
  	fi

  --- stderr
  Traceback (most recent call last):
    File "/Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys/mozjs/js/src/../../configure.py", line 35, in <module>
      from mozbuild.configure import TRACE, ConfigureSandbox
    File "/Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys/mozjs/python/mozbuild/mozbuild/configure/__init__.py", line 18, in <module>
      from six.moves import builtins as __builtin__
  ModuleNotFoundError: No module named 'six.moves'
  cat: config.log: No such file or directory
  make: *** [maybe-configure] Error 1
  thread 'main' panicked at /Users/eveeify/.cargo/git/checkouts/mozjs-e1c76167ba7c548f/91349dc/mozjs-sys/build.rs:272:5:
  assertion failed: result.success()
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: failed to compile `winterjs v0.4.3 (https://github.com/wasmerio/winterjs#2af3bfa1)`, intermediate artifacts can be found at `/var/folders/kz/yrcq8n4n6_v14nj1006m7r940000gn/T/cargo-install132gyE`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
```


Discussion / hints:
Could you tell me your Python version?
I encountered the same error on macOS, but it was resolved after changing the global Python version to 3.11.8 using pyenv and then installing six.

Here is my spec:
```
Hardware:

    Hardware Overview:

      Model Name: MacBook Air
      Model Identifier: Mac14,2
      Model Number: Z160001CJJ/A
      Chip: Apple M2
      Total Number of Cores: 8 (4 performance and 4 efficiency)
      Memory: 16 GB
      System Firmware Version: 10151.81.1
      OS Loader Version: 10151.81.1
```
I upgraded to the latest Python version (3.12.2, after first encountering the problem on 3.11.7) and I am still getting this same build error. `six` is installed on my machine via `brew`.

---

Seems like an issue with [wasmerio/mozjs](https://github.com/wasmerio/mozjs), which was fixed in the upstream repo - https://github.com/servo/mozjs/pull/426.
Thanks for reporting this!

@psimk the PR you linked mentions fixing the build on rust 1.73, which is odd since we've been using rustc 1.73 (and later 1.76) throughout most of the project's lifetime. I'll investigate the issue.
Yeah it's was something to do with rust i looked at the error log
> I upgraded to the latest Python version (3.12.2, after first encountering the problem on 3.11.7) and I am still getting this same build error. `six` is installed on my machine via `brew`.
> 
> 
> 
> ---
> 
> 
> 
> Seems like an issue with [wasmerio/mozjs](https://github.com/wasmerio/mozjs), which was fixed in the upstream repo - https://github.com/servo/mozjs/pull/426.

Yeah it the error was on python 3.12.2

Fix patch:
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index b65dbee25..213250d23 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -43,7 +43,7 @@ jobs:
           fi
 
           mkdir -p target/wasm32-wasmer-wasi/release
-          mv build-artifacts/winterjs-wasm/winterjs.wasm target/wasm32-wasmer-wasi/release/winterjs.wasm
+          mv build-artifacts/winterjs-wasix/winterjs.wasm target/wasm32-wasmer-wasi/release/winterjs.wasm
 
           wasmer publish --registry="wasmer.io" --token=${{ secrets.WAPM_PROD_TOKEN }} --non-interactive
 


Test patch:
diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml
index 9f2045560..1366a3c16 100644
--- a/.github/workflows/build-and-test.yml
+++ b/.github/workflows/build-and-test.yml
@@ -9,7 +9,50 @@ on:
 
 jobs:
   build-and-test:
-    runs-on: ubuntu-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        metadata: [
+          {
+            name: "Ubuntu (x86 native)",
+            os: ubuntu-latest,
+            bin-path: target/release-compact/winterjs,
+            artifact-name: winterjs-linux-x86,
+            target: native,
+          },
+          {
+            name: "macOS (arm native)",
+            os: macos-latest,
+            bin-path: target/release-compact/winterjs,
+            artifact-name: winterjs-macos-arm,
+            target: native,
+          },
+          {
+            name: "macOS (x86 native)",
+            os: macos-13,
+            bin-path: target/release-compact/winterjs,
+            artifact-name: winterjs-macos-x86,
+            target: native,
+          },
+          {
+            name: "Ubuntu (wasix)",
+            os: ubuntu-latest,
+            bin-path: target/wasm32-wasmer-wasi/release/winterjs.wasm,
+            artifact-name: winterjs-wasix,
+            target: wasix,
+            wasix-toolchain-release-asset: rust-toolchain-x86_64-unknown-linux-gnu.tar.gz
+          },
+          # {
+          #   name: "macOS (wasix)",
+          #   os: macos-latest,
+          #   bin-path: target/release-compact/winterjs,
+          #   artifact-name: winterjs-macos-wasix,
+          #   target: wasix,
+          #   wasix-toolchain-release-asset: rust-toolchain-aarch64-apple-darwin.tar.gz
+          # }
+        ]
+    name: Build and Test - ${{ matrix.metadata.name }}
+    runs-on: ${{ matrix.metadata.os }}
     steps:
       - name: Check out
         uses: actions/checkout@v3
@@ -17,6 +60,7 @@ jobs:
           submodules: "recursive"
 
       - name: OS Setup (Ubuntu)
+        if: ${{ matrix.metadata.os == 'ubuntu-latest' }}
         run: |
           sudo apt-get update
           sudo apt-get install -y build-essential python3.11 python3-distutils llvm-15 libclang-dev clang-15 wabt
@@ -30,6 +74,14 @@ jobs:
           sudo ln -s /usr/bin/llvm-ranlib-15 /usr/bin/llvm-ranlib
           sudo ln -s /usr/bin/llvm-objdump-15 /usr/bin/llvm-objdump
 
+      - name: OS Setup (macOS)
+        if: ${{ startsWith(matrix.metadata.os, 'macos-') }}
+        run: |
+          brew install wabt llvm@15
+          [ -d "/opt/homebrew" ] && echo PATH="/opt/homebrew/opt/llvm@15/bin:$PATH" >> $GITHUB_ENV
+          [ ! -d "/opt/homebrew" ] && echo PATH="/usr/local/opt/llvm@15/bin:$PATH" >> $GITHUB_ENV
+          npm i -g wasm-opt pnpm concurrently
+
       - name: Tool Versions
         run: |
           echo clang
@@ -60,9 +112,11 @@ jobs:
           components: "clippy,rustfmt"
 
       - name: Setup Wasmer
+        if: ${{ matrix.metadata.target == 'wasix' }}
         uses: wasmerio/setup-wasmer@v3.1
 
       - name: Download wasix-libc
+        if: ${{ matrix.metadata.target == 'wasix' }}
         uses: dsaltares/fetch-gh-release-asset@1.1.2
         with:
           repo: wasix-org/rust
@@ -70,57 +124,67 @@ jobs:
           target: sysroot/wasix-libc.tar.gz
 
       - name: Unpack wasix-libc
+        if: ${{ matrix.metadata.target == 'wasix' }}
         run: |
           cd sysroot
           tar xzf wasix-libc.tar.gz
 
       - name: Download wasix toolchain
+        if: ${{ matrix.metadata.target == 'wasix' }}
         uses: dsaltares/fetch-gh-release-asset@1.1.2
         with:
           repo: wasix-org/rust
-          file: rust-toolchain-x86_64-unknown-linux-gnu.tar.gz
+          file: ${{ matrix.metadata.wasix-toolchain-release-asset }}
           target: wasix-rust-toolchain/toolchain.tar.gz
 
       - name: Install wasix toolchain
+        if: ${{ matrix.metadata.target == 'wasix' }}
         run: |
           cd wasix-rust-toolchain
           tar xzf toolchain.tar.gz
           chmod +x bin/*
-          chmod +x lib/rustlib/x86_64-unknown-linux-gnu/bin/*
-          chmod +x lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld/*
+          chmod +x lib/rustlib/*/bin/*
+          chmod +x lib/rustlib/*/bin/gcc-ld/*
           rustup toolchain link wasix .
 
       - name: Build native
+        if: ${{ matrix.metadata.target == 'native' }}
         run: cargo build --profile release-compact
 
-      - name: Archive build native output
-        uses: actions/upload-artifact@v3
-        with:
-          name: winterjs-linux
-          path: target/release-compact/winterjs
-
-      - name: Build wasm
+      - name: Build wasix
+        if: ${{ matrix.metadata.target == 'wasix' }}
         run: |
           export WASI_SYSROOT=$(pwd)/sysroot/wasix-libc/sysroot32
           bash build.sh
 
+      - name: Archive build
+        uses: actions/upload-artifact@v3
+        with:
+          name: ${{ matrix.metadata.artifact-name }}
+          path: ${{ matrix.metadata.bin-path }}
+
       - name: build test suite JS app
         run: |
           cd test-suite/js-test-app
           pnpm i
           pnpm run build
 
-      - name: Run API test suite
+      - name: Run API test suite (wasix)
         # note: we're counting on wasmer compiling and running WinterJS faster
         # that cargo builds the test-suite app. This may not be the case forever.
+        if: ${{ matrix.metadata.target == 'wasix' }}
         run: |
           conc --kill-others --success "command-1" \
-            "wasmer run target/wasm32-wasmer-wasi/release/winterjs.wasm --net --mapdir /app:./test-suite/js-test-app/dist -- serve /app/bundle.js" \
+            "wasmer run . --net --mapdir /app:./test-suite/js-test-app/dist -- serve /app/bundle.js" \
             "sleep 10 && cd test-suite && cargo run"
           echo All tests are passing! 🎉
 
-      - name: Archive build wasm output
-        uses: actions/upload-artifact@v3
-        with:
-          name: winterjs-wasm
-          path: target/wasm32-wasmer-wasi/release/winterjs.wasm
+      - name: Run API test suite (native)
+        # note: we're counting on wasmer compiling and running WinterJS faster
+        # that cargo builds the test-suite app. This may not be the case forever.
+        if: ${{ matrix.metadata.target == 'native' }}
+        run: |
+          conc --kill-others --success "command-1" \
+            "./target/release-compact/winterjs serve ./test-suite/js-test-app/dist/bundle.js" \
+            "sleep 10 && cd test-suite && cargo run"
+          echo All tests are passing! 🎉