diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index c2ee1f8cc64..e7a7c31632d 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -38,7 +38,7 @@ jobs: strategy: fail-fast: false matrix: - build: [linux, macos, windows, linux-aarch64] + build: [linux, macos, macos-arm64, windows, linux-aarch64] include: - build: linux os: ubuntu-18.04 @@ -55,6 +55,11 @@ jobs: artifact_name: 'wasmer-macos-amd64' cross_compilation_artifact_name: 'cross_compiled_from_mac' run_integration_tests: true + - build: macos-arm64 + os: macos-11.0 + rust: nightly + target: aarch64-apple-darwin + artifact_name: 'wasmer-macos-arm64' - build: windows os: windows-latest rust: 1.47.0 @@ -83,42 +88,16 @@ jobs: uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.rust }} + target: ${{ matrix.target }} override: true - - name: Configure cargo data directory - # After this point, all cargo registry and crate data is stored in - # $GITHUB_WORKSPACE/.cargo_home. This allows us to cache only the files - # that are needed during the build process. Additionally, this works - # around a bug in the 'cache' action that causes directories outside of - # the workspace dir to be saved/restored incorrectly. - run: echo "CARGO_HOME=$(pwd)/.cargo_home" >> $GITHUB_ENV - - name: Cache - uses: actions/cache@master - with: - # Note: crates from the git repo always get rebuilt - # so we cache only those subdirectories of target/{debug|release} that - # contain the build output for crates that come from the registry. - path: |- - .cargo_home - target/*/.* - target/*/build - target/*/deps - key: ${{ matrix.os }}-${{ matrix.rust }}-${{ hashFiles('Cargo.lock') }} - restore-keys: | - ${{ matrix.os }}-${{ matrix.rust }}- - # # Install sccache - # - uses: actions/cache@master - # with: - # path: ${{ runner.tool_cache }}/cargo-sccache - # key: cargo-sccache-bin-${{ env.CARGO_SCCACHE_VERSION }} - # - name: Install sccache - # run: | - # echo "${{ runner.tool_cache }}/cargo-sccache/bin" >> $GITHUB_PATH - # cargo install sccache --version ${{ env.CARGO_SCCACHE_VERSION }} --root ${{ runner.tool_cache }}/cargo-sccache - # - name: Start sccache - # run: | - # ${{ runner.tool_cache }}/cargo-sccache/bin/sccache --start-server - # ${{ runner.tool_cache }}/cargo-sccache/bin/sscache -s - # echo "RUSTC_WRAPPER=${{ runner.tool_cache }}/cargo-sccache/bin/sccache" >> $GITHUB_ENV + - name: Setup Rust target + run: | + cat << EOF > .cargo/config.toml + [build] + target = "${{ matrix.target }}" + EOF + if: matrix.target + - uses: Swatinem/rust-cache@v1 - name: Install LLVM (Windows) if: matrix.os == 'windows-latest' shell: cmd @@ -131,7 +110,7 @@ jobs: # echo "LLVM_SYS_100_PREFIX=C:/llvm-10" >> $GITHUB_ENV # echo "LIBCLANG_PATH=C:/llvm-10/bin/libclang.dll" >> $GITHUB_ENV - name: Install LLVM (Unix) - if: matrix.os != 'windows-latest' + if: matrix.os != 'windows-latest' && matrix.target != 'aarch64-apple-darwin' run: | curl --proto '=https' --tlsv1.2 -sSf ${{ matrix.llvm_url }} -L -o llvm.tar.xz mkdir -p ${{ env.LLVM_DIR }} @@ -141,14 +120,25 @@ jobs: env: LLVM_DIR: ${{ github.workspace }}/llvm-10 - name: Set up dependencies for Mac OS - run: brew install automake - if: matrix.os == 'macos-latest' - - run: make test - - name: Build and Test C API + run: | + brew install automake + if: matrix.os == 'macos-latest' || matrix.os == 'macos-11.0' + - name: Test + run: | + make test + if: matrix.target != 'aarch64-apple-darwin' + - name: Test C API run: | make test-capi + if: matrix.os != 'windows-latest' && matrix.target != 'aarch64-apple-darwin' # we can't test yet on Apple Silicon or Windows + - name: Build C API + run: | make build-capi - if: matrix.os != 'windows-latest' + if: matrix.os != 'windows-latest' && matrix.target != 'aarch64-apple-darwin' + - name: Build C API + run: | + make build-capi-cranelift-system-libffi + if: matrix.target == 'aarch64-apple-darwin' - name: Build C API on Windows run: make build-capi if: matrix.os == 'windows-latest' @@ -158,14 +148,20 @@ jobs: - name: Build Wapm binary run: | make build-wapm - if: needs.setup.outputs.DOING_RELEASE == '1' - - name: Package Wasmer for integration tests - run: make package-without-wapm-for-integration-tests - if: needs.setup.outputs.DOING_RELEASE != '1' - - name: Package Wasmer + # if: needs.setup.outputs.DOING_RELEASE == '1' + - name: Copy target binaries run: | - make package - if: needs.setup.outputs.DOING_RELEASE == '1' + mkdir -p target/release + cp target/${{matrix.target}}/release/wasmer* target/release + cp target/${{matrix.target}}/release/libwasmer* target/release + if [ -d "wapm-cli" ]; then + mkdir -p wapm-cli/target/release + cp wapm-cli/target/${{matrix.target}}/release/wapm* wapm-cli/target/release + fi + if: matrix.target + - name: Dist + run: | + make distribution - name: Run integration tests (Windows) shell: cmd run: | @@ -220,7 +216,6 @@ jobs: path: cross - name: Upload Artifacts uses: actions/upload-artifact@v2 - if: needs.setup.outputs.DOING_RELEASE == '1' with: name: ${{ matrix.artifact_name }} path: dist @@ -300,7 +295,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps - asset_path: artifacts/wasmer-windows-amd64/wasmer-windows.exe + asset_path: artifacts/wasmer-windows-amd64/WasmerInstaller.exe asset_name: wasmer-windows.exe asset_content_type: application/vnd.microsoft.portable-executable - name: Upload Release Asset Linux amd64 @@ -310,19 +305,29 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: artifacts/wasmer-linux-amd64/wasmer-linux-amd64.tar.gz + asset_path: artifacts/wasmer-linux-amd64/wasmer.tar.gz asset_name: wasmer-linux-amd64.tar.gz asset_content_type: application/gzip - - name: Upload Release Asset Mac - id: upload-release-asset-mac + - name: Upload Release Asset Mac amd64 + id: upload-release-asset-mac-amd64 uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: artifacts/wasmer-macos-amd64/wasmer-darwin-amd64.tar.gz + asset_path: artifacts/wasmer-macos-amd64/wasmer.tar.gz asset_name: wasmer-darwin-amd64.tar.gz asset_content_type: application/gzip + - name: Upload Release Asset Mac arm64 + id: upload-release-asset-mac-arm64 + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: artifacts/wasmer-macos-amd64/wasmer.tar.gz + asset_name: wasmer-darwin-arm64.tar.gz + asset_content_type: application/gzip - name: Upload Release Asset Linux aarch64 id: upload-release-asset-linux-aarch64 uses: actions/upload-release-asset@v1 @@ -330,7 +335,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: artifacts/wasmer-linux-aarch64/wasmer-linux-aarch64.tar.gz + asset_path: artifacts/wasmer-linux-aarch64/wasmer.tar.gz asset_name: wasmer-linux-aarch64.tar.gz asset_content_type: application/gzip diff --git a/CHANGELOG.md b/CHANGELOG.md index a7996cd9356..2819a3b6781 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Added +- [#1831](https://github.com/wasmerio/wasmer/pull/1831) Added support for Apple Silicon chips (`arm64-apple-darwin`) - [#1649](https://github.com/wasmerio/wasmer/pull/1649) Add outline of migration to 1.0.0 docs. ### Changed diff --git a/Cargo.lock b/Cargo.lock index 1e0b100d90a..4bed42bb8db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,30 +129,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bindgen" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1c85344eb535a31b62f0af37be84441ba9e7f0f4111eb0530f43d15e513fe57" -dependencies = [ - "bitflags", - "cexpr", - "cfg-if 0.1.10", - "clang-sys", - "clap", - "env_logger", - "lazy_static", - "lazycell", - "log", - "peeking_take_while", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "which 3.1.1", -] - [[package]] name = "bitflags" version = "1.2.1" @@ -247,15 +223,6 @@ version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1770ced377336a88a67c473594ccc14eca6f4559217c34f64aac8f83d641b40" -[[package]] -name = "cexpr" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fce5b5fb86b0c57c20c834c1b412fd09c77c8a59b9473f86272709e78874cd1d" -dependencies = [ - "nom 4.2.3", -] - [[package]] name = "cfg-if" version = "0.1.10" @@ -268,17 +235,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "clang-sys" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81de550971c976f176130da4b2978d3b524eaa0fd9ac31f3ceb5ae1231fb4853" -dependencies = [ - "glob", - "libc", - "libloading 0.5.2", -] - [[package]] name = "clap" version = "2.33.3" @@ -352,7 +308,16 @@ version = "0.67.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f065f6889758f817f61a230220d1811ba99a9762af2fb69ae23048314f75ff2" dependencies = [ - "cranelift-entity", + "cranelift-entity 0.67.0", +] + +[[package]] +name = "cranelift-bforest" +version = "0.68.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9221545c0507dc08a62b2d8b5ffe8e17ac580b0a74d1813b496b8d70b070fbd0" +dependencies = [ + "cranelift-entity 0.68.0", ] [[package]] @@ -362,28 +327,58 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "510aa2ab4307644100682b94e449940a0ea15c5887f1d4b9678b8dd5ef31e736" dependencies = [ "byteorder", - "cranelift-bforest", - "cranelift-codegen-meta", - "cranelift-codegen-shared", - "cranelift-entity", + "cranelift-bforest 0.67.0", + "cranelift-codegen-meta 0.67.0", + "cranelift-codegen-shared 0.67.0", + "cranelift-entity 0.67.0", "gimli 0.21.0", "hashbrown 0.7.2", "log", - "regalloc", + "regalloc 0.0.30", "serde", "smallvec", "target-lexicon", "thiserror", ] +[[package]] +name = "cranelift-codegen" +version = "0.68.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e9936ea608b6cd176f107037f6adbb4deac933466fc7231154f96598b2d3ab1" +dependencies = [ + "byteorder", + "cranelift-bforest 0.68.0", + "cranelift-codegen-meta 0.68.0", + "cranelift-codegen-shared 0.68.0", + "cranelift-entity 0.68.0", + "gimli 0.22.0", + "hashbrown 0.9.1", + "log", + "regalloc 0.0.31", + "smallvec", + "target-lexicon", + "thiserror", +] + [[package]] name = "cranelift-codegen-meta" version = "0.67.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4cb0c7e87c60d63b35f9670c15479ee4a5e557dd127efab88b2f9b2ca83c9a0" dependencies = [ - "cranelift-codegen-shared", - "cranelift-entity", + "cranelift-codegen-shared 0.67.0", + "cranelift-entity 0.67.0", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.68.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ef2b2768568306540f4c8db3acce9105534d34c4a1e440529c1e702d7f8c8d7" +dependencies = [ + "cranelift-codegen-shared 0.68.0", + "cranelift-entity 0.68.0", ] [[package]] @@ -392,23 +387,35 @@ version = "0.67.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60636227098693e06de8d6d88beea2a7d32ecf8a8030dacdb57c68e06f381826" +[[package]] +name = "cranelift-codegen-shared" +version = "0.68.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6759012d6d19c4caec95793f052613e9d4113e925e7f14154defbac0f1d4c938" + [[package]] name = "cranelift-entity" version = "0.67.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6156db73e0c9f65f80c512988d63ec736be0dee3dd66bf951e3e28aed9dc02d3" + +[[package]] +name = "cranelift-entity" +version = "0.68.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86badbce14e15f52a45b666b38abe47b204969dd7f8fb7488cb55dd46b361fa6" dependencies = [ "serde", ] [[package]] name = "cranelift-frontend" -version = "0.67.0" +version = "0.68.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e09cd158c9a820a4cc14a34076811da225cce1d31dc6d03c5ef85b91aef560b9" +checksum = "b608bb7656c554d0a4cf8f50c7a10b857e80306f6ff829ad6d468a7e2323c8d8" dependencies = [ - "cranelift-codegen", - "hashbrown 0.7.2", + "cranelift-codegen 0.68.0", + "hashbrown 0.9.1", "log", "smallvec", "target-lexicon", @@ -670,19 +677,6 @@ dependencies = [ "syn", ] -[[package]] -name = "env_logger" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - [[package]] name = "erased-serde" version = "0.3.12" @@ -746,7 +740,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" dependencies = [ "typenum", - "version_check 0.9.2", + "version_check", ] [[package]] @@ -787,6 +781,15 @@ name = "gimli" version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c" +dependencies = [ + "indexmap", +] + +[[package]] +name = "gimli" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" dependencies = [ "fallible-iterator", "indexmap", @@ -865,15 +868,6 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" -[[package]] -name = "humantime" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error", -] - [[package]] name = "ident_case" version = "1.0.1" @@ -1004,12 +998,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "leb128" version = "0.2.4" @@ -1024,9 +1012,9 @@ checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" [[package]] name = "libffi" -version = "0.9.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c18efe55925cc7f83bf60a61394696a734ae90e668d1f2bbd954354416fec6f2" +checksum = "bafef83ee22d51c27348aaf6b2da007a32b9f5004809d09271432e5ea2a795dd" dependencies = [ "abort_on_panic", "libc", @@ -1035,24 +1023,12 @@ dependencies = [ [[package]] name = "libffi-sys" -version = "0.9.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f00e48ce437c5741a4da3b51738498343b5158c37bfa02bcb969efcc44e4e06" +checksum = "3b6d65142f1c3b06ca3f4216da4d32b3124d14d932cef8dfd8792037acd2160b" dependencies = [ - "bindgen", "cc", "make-cmd", - "pkg-config", -] - -[[package]] -name = "libloading" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" -dependencies = [ - "cc", - "winapi", ] [[package]] @@ -1190,16 +1166,6 @@ dependencies = [ "void", ] -[[package]] -name = "nom" -version = "4.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" -dependencies = [ - "memchr", - "version_check 0.1.5", -] - [[package]] name = "nom" version = "5.1.2" @@ -1207,7 +1173,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" dependencies = [ "memchr", - "version_check 0.9.2", + "version_check", ] [[package]] @@ -1350,12 +1316,6 @@ dependencies = [ "proc-macro-hack", ] -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - [[package]] name = "pest" version = "2.1.3" @@ -1440,7 +1400,7 @@ dependencies = [ "proc-macro2", "quote", "syn", - "version_check 0.9.2", + "version_check", ] [[package]] @@ -1451,7 +1411,7 @@ checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ "proc-macro2", "quote", - "version_check 0.9.2", + "version_check", ] [[package]] @@ -1469,12 +1429,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - [[package]] name = "quote" version = "1.0.7" @@ -1708,6 +1662,17 @@ dependencies = [ "smallvec", ] +[[package]] +name = "regalloc" +version = "0.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "571f7f397d61c4755285cd37853fe8e03271c243424a907415909379659381c5" +dependencies = [ + "log", + "rustc-hash", + "smallvec", +] + [[package]] name = "regex" version = "1.4.2" @@ -1934,12 +1899,6 @@ dependencies = [ "serde", ] -[[package]] -name = "shlex" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" - [[package]] name = "smallvec" version = "1.4.2" @@ -2025,15 +1984,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "termcolor" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" -dependencies = [ - "winapi-util", -] - [[package]] name = "test-generator" version = "0.1.0" @@ -2209,12 +2159,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" -[[package]] -name = "version_check" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" - [[package]] name = "version_check" version = "0.9.2" @@ -2430,9 +2374,10 @@ dependencies = [ name = "wasmer-compiler-cranelift" version = "1.0.0-alpha5" dependencies = [ - "cranelift-codegen", + "cranelift-codegen 0.67.0", + "cranelift-codegen 0.68.0", "cranelift-frontend", - "gimli 0.21.0", + "gimli 0.22.0", "hashbrown 0.9.1", "lazy_static", "more-asserts", @@ -2553,7 +2498,7 @@ dependencies = [ "bincode", "cfg-if 0.1.10", "leb128", - "libloading 0.6.5", + "libloading", "serde", "tempfile", "tracing", @@ -2562,7 +2507,7 @@ dependencies = [ "wasmer-object", "wasmer-types", "wasmer-vm", - "which 4.0.2", + "which", ] [[package]] @@ -2572,7 +2517,7 @@ dependencies = [ "bincode", "cfg-if 0.1.10", "leb128", - "libloading 0.6.5", + "libloading", "serde", "tempfile", "tracing", @@ -2605,7 +2550,7 @@ dependencies = [ name = "wasmer-types" version = "1.0.0-alpha5" dependencies = [ - "cranelift-entity", + "cranelift-entity 0.68.0", "serde", ] @@ -2814,15 +2759,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "which" -version = "3.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" -dependencies = [ - "libc", -] - [[package]] name = "which" version = "4.0.2" @@ -2882,7 +2818,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3a481cfdefd35e1c50073ae33a8000d695c98039544659f5dc5dd71311b0d01" dependencies = [ - "nom 5.1.2", + "nom", ] [[package]] diff --git a/Makefile b/Makefile index 3a564329ac3..a138e0bda7d 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,10 @@ ifeq ($(ARCH), aarch64) endif endif +ifeq ($(ARCH), arm64) + test_compilers_engines += cranelift-jit +endif + compilers := $(filter-out ,$(compilers)) test_compilers_engines := $(filter-out ,$(test_compilers_engines)) @@ -82,10 +86,17 @@ build-wasmer: build-wasmer-debug: cargo build --manifest-path lib/cli/Cargo.toml $(compiler_features) -WAPM_VERSION = v0.5.0 -build-wapm: - git clone --branch $(WAPM_VERSION) https://github.com/wasmerio/wapm-cli.git +WAPM_VERSION = master # v0.5.0 +get-wapm: + [ -d "wapm-cli" ] || git clone --branch $(WAPM_VERSION) https://github.com/wasmerio/wapm-cli.git + +build-wapm: get-wapm +ifeq ($(UNAME_S), Darwin) + # We build it without bundling sqlite, as is included by default in macos + cargo build --release --manifest-path wapm-cli/Cargo.toml --no-default-features --features "packagesigning telemetry update-notifications" +else cargo build --release --manifest-path wapm-cli/Cargo.toml --features "telemetry update-notifications" +endif build-docs: cargo doc --release $(compiler_features) --document-private-items --no-deps --workspace @@ -257,13 +268,13 @@ test-integration: ############# package-wapm: +ifneq ($(OS), Windows_NT) mkdir -p "package/bin" - cp ./wapm-cli/target/release/wapm package/bin/ -ifeq ($(OS), Windows_NT) - echo "" -else - echo "#!/bin/bash\nwapm execute \"\$$@\"" > package/bin/wax - chmod +x package/bin/wax + if [ -d "wapm-cli" ]; then \ + cp wapm-cli/target/release/wapm package/bin/; \ + echo "#!/bin/bash\nwapm execute \"\$$@\"" > package/bin/wax; \ + chmod +x package/bin/wax; \ + fi endif package-wasmer: @@ -307,22 +318,21 @@ package-docs: build-docs build-docs-capi echo '' > package/docs/crates/index.html package: package-wapm package-wasmer package-capi + +distribution: package cp LICENSE package/LICENSE cp ATTRIBUTIONS.md package/ATTRIBUTIONS mkdir -p dist ifeq ($(OS), Windows_NT) iscc scripts/windows-installer/wasmer.iss - cp scripts/windows-installer/WasmerInstaller.exe dist/wasmer-windows.exe + cp scripts/windows-installer/WasmerInstaller.exe dist/ else cp LICENSE package/LICENSE cp ATTRIBUTIONS.md package/ATTRIBUTIONS tar -C package -zcvf wasmer.tar.gz bin lib include LICENSE ATTRIBUTIONS - cp ./wasmer.tar.gz ./dist/$(shell ./scripts/binary-name.sh) + mv wasmer.tar.gz dist/ endif -# command for simulating installing Wasmer without wapm. -package-without-wapm-for-integration-tests: package-wasmer package-capi - ################# # Miscellaneous # ################# diff --git a/examples/engine_cross_compilation.rs b/examples/engine_cross_compilation.rs index 272da2cfcee..7396bf0f9d1 100644 --- a/examples/engine_cross_compilation.rs +++ b/examples/engine_cross_compilation.rs @@ -99,7 +99,11 @@ fn main() -> Result<(), Box> { } #[test] -#[cfg(not(windows))] +#[cfg(not(any( + windows, + // We don't support yet crosscompilation in macOS with Apple Silicon + all(target_os = "macos", target_arch = "aarch64") +)))] fn test_cross_compilation() -> Result<(), Box> { main() } diff --git a/lib/c-api/Cargo.toml b/lib/c-api/Cargo.toml index b3d904c8c26..b355db4495a 100644 --- a/lib/c-api/Cargo.toml +++ b/lib/c-api/Cargo.toml @@ -30,7 +30,7 @@ wasmer-types = { version = "1.0.0-alpha5", path = "../wasmer-types" } cfg-if = "1.0" lazy_static = "1" libc = { version = "^0.2", default-features = false } -libffi = { version = "0.9", optional = true } +libffi = { version = "1.0", optional = true } serde = { version = "1", optional = true, features = ["derive"] } thiserror = "1" typetag = { version = "0.1", optional = true } diff --git a/lib/cli/src/commands/compile.rs b/lib/cli/src/commands/compile.rs index 2d4e0c4065a..7e85bce2e74 100644 --- a/lib/cli/src/commands/compile.rs +++ b/lib/cli/src/commands/compile.rs @@ -87,7 +87,7 @@ impl Compile { if ext != recommended_extension { warning!("the output file has a wrong extension. We recommend using `{}.{}` for the chosen target", &output_filename, &recommended_extension) } - }, + } None => { warning!("the output file has no extension. We recommend using `{}.{}` for the chosen target", &output_filename, &recommended_extension) } diff --git a/lib/compiler-cranelift/Cargo.toml b/lib/compiler-cranelift/Cargo.toml index a32658c9193..3b4ccf7de61 100644 --- a/lib/compiler-cranelift/Cargo.toml +++ b/lib/compiler-cranelift/Cargo.toml @@ -15,14 +15,14 @@ edition = "2018" wasmer-compiler = { path = "../compiler", version = "1.0.0-alpha5", features = ["translator"], default-features = false } wasmer-vm = { path = "../vm", version = "1.0.0-alpha5" } wasmer-types = { path = "../wasmer-types", version = "1.0.0-alpha5", default-features = false, features = ["std"] } -cranelift-codegen = { version = "0.67", default-features = false, features = ["x86", "arm64"] } -cranelift-frontend = { version = "0.67", default-features = false } +cranelift-codegen = { version = "0.68", default-features = false, features = ["x86", "arm64"] } +cranelift-frontend = { version = "0.68", default-features = false } tracing = "0.1" hashbrown = { version = "0.9", optional = true } rayon = "1.5" serde = { version = "1.0", features = ["derive"] } more-asserts = "0.2" -gimli = { version = "0.21", optional = true } +gimli = { version = "0.22", optional = true } smallvec = "1.0.0" [dev-dependencies] diff --git a/lib/compiler-cranelift/src/translator/unwind.rs b/lib/compiler-cranelift/src/translator/unwind.rs index 50b61b0e9af..052ea85923e 100644 --- a/lib/compiler-cranelift/src/translator/unwind.rs +++ b/lib/compiler-cranelift/src/translator/unwind.rs @@ -49,6 +49,6 @@ pub(crate) fn compiled_function_unwind_info( Ok(CraneliftUnwindInfo::WindowsX64(data)) } Some(UnwindInfo::SystemV(unwind)) => Ok(CraneliftUnwindInfo::FDE(unwind)), - None => Ok(CraneliftUnwindInfo::None), + Some(_) | None => Ok(CraneliftUnwindInfo::None), } } diff --git a/lib/deprecated/runtime-core/Cargo.lock b/lib/deprecated/runtime-core/Cargo.lock index d971b374ec1..c686070e50c 100644 --- a/lib/deprecated/runtime-core/Cargo.lock +++ b/lib/deprecated/runtime-core/Cargo.lock @@ -6,7 +6,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" dependencies = [ - "gimli 0.22.0", + "gimli", ] [[package]] @@ -134,25 +134,25 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" [[package]] name = "cranelift-bforest" -version = "0.67.0" +version = "0.68.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f065f6889758f817f61a230220d1811ba99a9762af2fb69ae23048314f75ff2" +checksum = "9221545c0507dc08a62b2d8b5ffe8e17ac580b0a74d1813b496b8d70b070fbd0" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.67.0" +version = "0.68.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "510aa2ab4307644100682b94e449940a0ea15c5887f1d4b9678b8dd5ef31e736" +checksum = "7e9936ea608b6cd176f107037f6adbb4deac933466fc7231154f96598b2d3ab1" dependencies = [ "byteorder", "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", "cranelift-entity", - "gimli 0.21.0", + "gimli", "log", "regalloc", "smallvec", @@ -162,9 +162,9 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.67.0" +version = "0.68.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4cb0c7e87c60d63b35f9670c15479ee4a5e557dd127efab88b2f9b2ca83c9a0" +checksum = "4ef2b2768568306540f4c8db3acce9105534d34c4a1e440529c1e702d7f8c8d7" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -172,24 +172,24 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" -version = "0.67.0" +version = "0.68.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60636227098693e06de8d6d88beea2a7d32ecf8a8030dacdb57c68e06f381826" +checksum = "6759012d6d19c4caec95793f052613e9d4113e925e7f14154defbac0f1d4c938" [[package]] name = "cranelift-entity" -version = "0.67.0" +version = "0.68.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6156db73e0c9f65f80c512988d63ec736be0dee3dd66bf951e3e28aed9dc02d3" +checksum = "86badbce14e15f52a45b666b38abe47b204969dd7f8fb7488cb55dd46b361fa6" dependencies = [ "serde", ] [[package]] name = "cranelift-frontend" -version = "0.67.0" +version = "0.68.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e09cd158c9a820a4cc14a34076811da225cce1d31dc6d03c5ef85b91aef560b9" +checksum = "b608bb7656c554d0a4cf8f50c7a10b857e80306f6ff829ad6d468a7e2323c8d8" dependencies = [ "cranelift-codegen", "log", @@ -396,21 +396,15 @@ dependencies = [ [[package]] name = "gimli" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c" +checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" dependencies = [ "fallible-iterator", "indexmap", "stable_deref_trait", ] -[[package]] -name = "gimli" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" - [[package]] name = "goblin" version = "0.2.3" @@ -822,9 +816,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "regalloc" -version = "0.0.30" +version = "0.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2041c2d34f6ff346d6f428974f03d8bf12679b0c816bb640dc5eb1d48848d8d1" +checksum = "571f7f397d61c4755285cd37853fe8e03271c243424a907415909379659381c5" dependencies = [ "log", "rustc-hash", @@ -1166,7 +1160,7 @@ version = "1.0.0-alpha5" dependencies = [ "cranelift-codegen", "cranelift-frontend", - "gimli 0.21.0", + "gimli", "more-asserts", "rayon", "serde", diff --git a/lib/deprecated/runtime/Cargo.lock b/lib/deprecated/runtime/Cargo.lock index a3584c5886e..b7baa2a4ba9 100644 --- a/lib/deprecated/runtime/Cargo.lock +++ b/lib/deprecated/runtime/Cargo.lock @@ -6,7 +6,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" dependencies = [ - "gimli 0.22.0", + "gimli", ] [[package]] @@ -134,25 +134,25 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" [[package]] name = "cranelift-bforest" -version = "0.67.0" +version = "0.68.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f065f6889758f817f61a230220d1811ba99a9762af2fb69ae23048314f75ff2" +checksum = "9221545c0507dc08a62b2d8b5ffe8e17ac580b0a74d1813b496b8d70b070fbd0" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.67.0" +version = "0.68.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "510aa2ab4307644100682b94e449940a0ea15c5887f1d4b9678b8dd5ef31e736" +checksum = "7e9936ea608b6cd176f107037f6adbb4deac933466fc7231154f96598b2d3ab1" dependencies = [ "byteorder", "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", "cranelift-entity", - "gimli 0.21.0", + "gimli", "log", "regalloc", "smallvec", @@ -162,9 +162,9 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.67.0" +version = "0.68.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4cb0c7e87c60d63b35f9670c15479ee4a5e557dd127efab88b2f9b2ca83c9a0" +checksum = "4ef2b2768568306540f4c8db3acce9105534d34c4a1e440529c1e702d7f8c8d7" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -172,24 +172,24 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" -version = "0.67.0" +version = "0.68.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60636227098693e06de8d6d88beea2a7d32ecf8a8030dacdb57c68e06f381826" +checksum = "6759012d6d19c4caec95793f052613e9d4113e925e7f14154defbac0f1d4c938" [[package]] name = "cranelift-entity" -version = "0.67.0" +version = "0.68.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6156db73e0c9f65f80c512988d63ec736be0dee3dd66bf951e3e28aed9dc02d3" +checksum = "86badbce14e15f52a45b666b38abe47b204969dd7f8fb7488cb55dd46b361fa6" dependencies = [ "serde", ] [[package]] name = "cranelift-frontend" -version = "0.67.0" +version = "0.68.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e09cd158c9a820a4cc14a34076811da225cce1d31dc6d03c5ef85b91aef560b9" +checksum = "b608bb7656c554d0a4cf8f50c7a10b857e80306f6ff829ad6d468a7e2323c8d8" dependencies = [ "cranelift-codegen", "log", @@ -396,21 +396,15 @@ dependencies = [ [[package]] name = "gimli" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c" +checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" dependencies = [ "fallible-iterator", "indexmap", "stable_deref_trait", ] -[[package]] -name = "gimli" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" - [[package]] name = "goblin" version = "0.2.3" @@ -822,9 +816,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "regalloc" -version = "0.0.30" +version = "0.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2041c2d34f6ff346d6f428974f03d8bf12679b0c816bb640dc5eb1d48848d8d1" +checksum = "571f7f397d61c4755285cd37853fe8e03271c243424a907415909379659381c5" dependencies = [ "log", "rustc-hash", @@ -1166,7 +1160,7 @@ version = "1.0.0-alpha5" dependencies = [ "cranelift-codegen", "cranelift-frontend", - "gimli 0.21.0", + "gimli", "more-asserts", "rayon", "serde", diff --git a/lib/engine-native/src/artifact.rs b/lib/engine-native/src/artifact.rs index 6a3a8f1549c..2cf7d5f6918 100644 --- a/lib/engine-native/src/artifact.rs +++ b/lib/engine-native/src/artifact.rs @@ -254,15 +254,32 @@ impl NativeArtifact { }; let is_cross_compiling = engine_inner.is_cross_compiling(); + let target_triple_str = { + let into_str = target_triple.to_string(); + // We have to adapt the target triple string, because otherwise + // Apple's clang will not recognize it. + if into_str == "aarch64-apple-darwin" { + "arm64-apple-darwin".to_string() + } else { + into_str + } + }; + let cross_compiling_args: Vec = if is_cross_compiling { vec![ - format!("--target={}", target_triple), + format!("--target={}", target_triple_str), "-fuse-ld=lld".to_string(), "-nodefaultlibs".to_string(), "-nostdlib".to_string(), ] } else { - vec![] + // We are explicit on the target when the host system is + // Apple Silicon, otherwise compilation fails. + if target_triple_str == "arm64-apple-darwin" { + vec![format!("--target={}", target_triple_str)] + } else { + vec![] + } }; let target_args = match (target_triple.operating_system, is_cross_compiling) { (OperatingSystem::Windows, true) => vec!["-Wl,/force:unresolved,/noentry"], @@ -271,7 +288,7 @@ impl NativeArtifact { }; trace!( "Compiling for target {} from host {}", - target_triple.to_string(), + target_triple_str, Triple::host().to_string(), ); diff --git a/lib/engine/src/resolver.rs b/lib/engine/src/resolver.rs index 4c36dab3141..be3e03e5849 100644 --- a/lib/engine/src/resolver.rs +++ b/lib/engine/src/resolver.rs @@ -163,7 +163,17 @@ pub fn resolve_imports( // TODO: We should check that the f.vmctx actually matches // the shape of `VMDynamicFunctionImportContext` } - VMFunctionKind::Static => f.address, + VMFunctionKind::Static => { + // The native ABI for functions fails when defining a function natively in + // macos (Darwin) with the Apple Silicon ARM chip, for functions with more than 10 args + // TODO: Cranelift should have a good ABI for the ABI + if cfg!(all(target_os = "macos", target_arch = "aarch64")) { + let num_params = f.signature.params().len(); + assert!(num_params < 9, "Only native functions with less than 9 arguments are allowed in Apple Silicon (for now). Received {} in the import {}.{}", num_params, module_name, field); + } + + f.address + } }; function_imports.push(VMFunctionImport { body: address, diff --git a/lib/object/src/module.rs b/lib/object/src/module.rs index fa7c3c53f21..5b1f84391b3 100644 --- a/lib/object/src/module.rs +++ b/lib/object/src/module.rs @@ -209,6 +209,12 @@ pub fn emit_compilation( RelocationKind::PltRelative, RelocationEncoding::X86Branch, ), + // Object doesn't fully support it yet + // Architecture::Aarch64(_) => ( + // 32, + // RelocationKind::PltRelative, + // RelocationEncoding::Generic, + // ), architecture => { return Err(ObjectError::UnsupportedArchitecture( architecture.to_string(), diff --git a/lib/vm/src/trap/traphandlers.rs b/lib/vm/src/trap/traphandlers.rs index 452e6ed61d9..de6582cf4b6 100644 --- a/lib/vm/src/trap/traphandlers.rs +++ b/lib/vm/src/trap/traphandlers.rs @@ -117,8 +117,8 @@ cfg_if::cfg_if! { let (stackaddr, stacksize) = thread_stack(); // The stack and its guard page covers the // range [stackaddr - guard pages .. stackaddr + stacksize). - // We assume the guard page is 1 page, and pages are 4KiB. - if stackaddr - 4096 <= addr && addr < stackaddr + stacksize { + // We assume the guard page is 1 page, and pages are 4KiB (or 16KiB in Apple Silicon) + if stackaddr - region::page::size() <= addr && addr < stackaddr + stacksize { Some(TrapCode::StackOverflow) } else { Some(TrapCode::HeapAccessOutOfBounds) @@ -202,9 +202,27 @@ cfg_if::cfg_if! { } else if #[cfg(all(target_os = "linux", target_arch = "aarch64"))] { let cx = &*(cx as *const libc::ucontext_t); cx.uc_mcontext.pc as *const u8 - } else if #[cfg(target_os = "macos")] { + } else if #[cfg(all(target_os = "macos", target_arch = "x86_64"))] { let cx = &*(cx as *const libc::ucontext_t); (*cx.uc_mcontext).__ss.__rip as *const u8 + } else if #[cfg(all(target_os = "macos", target_arch = "aarch64"))] { + use std::mem; + // TODO: This should be integrated into rust/libc + // Related issue: https://github.com/rust-lang/libc/issues/1977 + #[allow(non_camel_case_types)] + pub struct __darwin_arm_thread_state64 { + pub __x: [u64; 29], /* General purpose registers x0-x28 */ + pub __fp: u64, /* Frame pointer x29 */ + pub __lr: u64, /* Link register x30 */ + pub __sp: u64, /* Stack pointer x31 */ + pub __pc: u64, /* Program counter */ + pub __cpsr: u32, /* Current program status register */ + pub __pad: u32, /* Same size for 32-bit or 64-bit clients */ + }; + + let cx = &*(cx as *const libc::ucontext_t); + let uc_mcontext = mem::transmute::<_, *const __darwin_arm_thread_state64>(&(*cx.uc_mcontext).__ss); + (*uc_mcontext).__pc as *const u8 } else { compile_error!("unsupported platform"); } @@ -709,7 +727,6 @@ mod tls { #[cfg(unix)] fn setup_unix_sigaltstack() -> Result<(), Trap> { use std::cell::RefCell; - use std::convert::TryInto; use std::ptr::null_mut; thread_local! { @@ -738,7 +755,6 @@ fn setup_unix_sigaltstack() -> Result<(), Trap> { // already checked _ => return Ok(()), } - // Check to see if the existing sigaltstack, if it exists, is big // enough. If so we don't need to allocate our own. let mut old_stack = mem::zeroed(); @@ -751,7 +767,7 @@ fn setup_unix_sigaltstack() -> Result<(), Trap> { // ... but failing that we need to allocate our own, so do all that // here. - let page_size: usize = libc::sysconf(libc::_SC_PAGESIZE).try_into().unwrap(); + let page_size: usize = region::page::size(); let guard_size = page_size; let alloc_size = guard_size + MIN_STACK_SIZE; diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index fd4d426481e..365683450e7 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -30,6 +30,8 @@ pub use crate::utils::{get_wasi_version, is_wasi_module, WasiVersion}; use thiserror::Error; use wasmer::{imports, Function, ImportObject, Memory, Module, Store}; +#[cfg(all(target_os = "macos", target_arch = "aarch64",))] +use wasmer::{FunctionType, ValType}; use std::cell::UnsafeCell; use std::fmt; @@ -201,6 +203,34 @@ pub fn generate_import_object_from_env( } } +// Note: we use this wrapper because native functions with more than 9 params +// fail on Apple Silicon (with Cranelift). +fn get_path_open_for_store(store: &Store, env: WasiEnv) -> Function { + #[cfg(not(all(target_os = "macos", target_arch = "aarch64",)))] + let path_open = Function::new_native_with_env(store, env.clone(), path_open); + #[cfg(all(target_os = "macos", target_arch = "aarch64",))] + let path_open = Function::new_with_env( + store, + &FunctionType::new( + vec![ + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I32, + ValType::I64, + ValType::I64, + ValType::I32, + ValType::I32, + ], + vec![ValType::I32], + ), + env.clone(), + path_open_dynamic, + ); + path_open +} + /// Combines a state generating function with the import list for legacy WASI fn generate_import_object_snapshot0(store: &Store, env: WasiEnv) -> ImportObject { imports! { @@ -236,7 +266,7 @@ fn generate_import_object_snapshot0(store: &Store, env: WasiEnv) -> ImportObject "path_filestat_get" => Function::new_native_with_env(store, env.clone(), legacy::snapshot0::path_filestat_get), "path_filestat_set_times" => Function::new_native_with_env(store, env.clone(), path_filestat_set_times), "path_link" => Function::new_native_with_env(store, env.clone(), path_link), - "path_open" => Function::new_native_with_env(store, env.clone(), path_open), + "path_open" => get_path_open_for_store(store, env.clone()), "path_readlink" => Function::new_native_with_env(store, env.clone(), path_readlink), "path_remove_directory" => Function::new_native_with_env(store, env.clone(), path_remove_directory), "path_rename" => Function::new_native_with_env(store, env.clone(), path_rename), @@ -289,7 +319,7 @@ fn generate_import_object_snapshot1(store: &Store, env: WasiEnv) -> ImportObject "path_filestat_get" => Function::new_native_with_env(store, env.clone(), path_filestat_get), "path_filestat_set_times" => Function::new_native_with_env(store, env.clone(), path_filestat_set_times), "path_link" => Function::new_native_with_env(store, env.clone(), path_link), - "path_open" => Function::new_native_with_env(store, env.clone(), path_open), + "path_open" => get_path_open_for_store(store, env.clone()), "path_readlink" => Function::new_native_with_env(store, env.clone(), path_readlink), "path_remove_directory" => Function::new_native_with_env(store, env.clone(), path_remove_directory), "path_rename" => Function::new_native_with_env(store, env.clone(), path_rename), diff --git a/lib/wasi/src/ptr.rs b/lib/wasi/src/ptr.rs index a4c76e3e39e..430c2b6ec38 100644 --- a/lib/wasi/src/ptr.rs +++ b/lib/wasi/src/ptr.rs @@ -24,6 +24,12 @@ impl fmt::Debug for WasmPtr { } } +impl From for WasmPtr { + fn from(offset: i32) -> Self { + Self::new(offset as _) + } +} + unsafe impl FromToNativeWasmType for WasmPtr { type Native = as FromToNativeWasmType>::Native; diff --git a/lib/wasi/src/syscalls/mod.rs b/lib/wasi/src/syscalls/mod.rs index 26d592535ac..d174af20caf 100644 --- a/lib/wasi/src/syscalls/mod.rs +++ b/lib/wasi/src/syscalls/mod.rs @@ -28,7 +28,7 @@ use std::cell::Cell; use std::convert::{Infallible, TryInto}; use std::io::{self, Read, Seek, Write}; use tracing::{debug, trace}; -use wasmer::{Memory, RuntimeError}; +use wasmer::{Memory, RuntimeError, Value}; #[cfg(any( target_os = "freebsd", @@ -1884,6 +1884,33 @@ pub fn path_open( __WASI_ESUCCESS } +// Note: we define path_open_dynamic because native functions with more than 9 params +// fail on Apple Silicon (with Cranelift). +pub fn path_open_dynamic(env: &WasiEnv, params: &[Value]) -> Result, RuntimeError> { + let dirfd: __wasi_fd_t = params[0].unwrap_i32() as _; + let dirflags: __wasi_lookupflags_t = params[1].unwrap_i32() as _; + let path: WasmPtr = params[2].unwrap_i32().into(); + let path_len: u32 = params[3].unwrap_i32() as _; + let o_flags: __wasi_oflags_t = params[4].unwrap_i32() as _; + let fs_rights_base: __wasi_rights_t = params[5].unwrap_i64() as _; + let fs_rights_inheriting: __wasi_rights_t = params[6].unwrap_i64() as _; + let fs_flags: __wasi_fdflags_t = params[7].unwrap_i32() as _; + let fd: WasmPtr<__wasi_fd_t> = params[8].unwrap_i32().into(); + + Ok(vec![Value::I32(path_open( + env, + dirfd, + dirflags, + path, + path_len, + o_flags, + fs_rights_base, + fs_rights_inheriting, + fs_flags, + fd, + ) as i32)]) +} + /// ### `path_readlink()` /// Read the value of a symlink /// Inputs: diff --git a/lib/wasmer-types/Cargo.toml b/lib/wasmer-types/Cargo.toml index 2f0c2008e88..6e6e2a72d70 100644 --- a/lib/wasmer-types/Cargo.toml +++ b/lib/wasmer-types/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" [dependencies] # We use `cranelift-entity` here because it's a lightweight dependency and it contains # some useful data structures -cranelift-entity = "0.67" +cranelift-entity = "0.68" serde = { version = "1.0", features = ["derive"], optional = true, default-features = false } [features] diff --git a/scripts/binary-name.sh b/scripts/binary-name.sh deleted file mode 100755 index af7f63c470b..00000000000 --- a/scripts/binary-name.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh - -initArch() { - ARCH=$(uname -m) - if [ -n "$WASMER_ARCH" ]; then - ARCH="$WASMER_ARCH" - fi - # If you modify this list, please also modify install.sh - case $ARCH in - amd64|x86_64) ARCH="amd64";; - aarch64) ARCH="aarch64";; - # i386) ARCH="386";; - *) echo "Architecture ${ARCH} is not supported by this installation script"; exit 1;; - esac -} - -initOS() { - OS=$(uname | tr '[:upper:]' '[:lower:]') - if [ -n "$WASMER_OS" ]; then - echo "Using WASMER_OS (${WASMER_OS})" - OS="$WASMER_OS" - fi - case "$OS" in - darwin) OS='darwin';; - linux) OS='linux';; - freebsd) OS='freebsd';; - # mingw*) OS='windows';; - # msys*) OS='windows';; - *) echo "OS ${OS} is not supported by this installation script"; exit 1;; - esac -} - -# identify platform based on uname output -initArch -initOS - -# determine install directory if required -BINARY="wasmer-${OS}-${ARCH}.tar.gz" - -# add .exe if on windows -# if [ "$OS" = "windows" ]; then -# BINARY="$BINARY.exe" -# fi - -echo "${BINARY}" diff --git a/tests/compilers/native_functions.rs b/tests/compilers/native_functions.rs index c89567f54c5..cd2600eac1f 100644 --- a/tests/compilers/native_functions.rs +++ b/tests/compilers/native_functions.rs @@ -6,6 +6,34 @@ use std::rc::Rc; use wasmer::*; +fn long_f(a: u32, b: u32, c: u32, d: u32, e: u32, f: u16, g: u64, h: u64, i: u16, j: u32) -> u64 { + j as u64 + + i as u64 * 10 + + h * 100 + + g * 1000 + + f as u64 * 10000 + + e as u64 * 100000 + + d as u64 * 1000000 + + c as u64 * 10000000 + + b as u64 * 100000000 + + a as u64 * 1000000000 +} + +fn long_f_dynamic(values: &[Value]) -> Result, RuntimeError> { + Ok(vec![Value::I64( + values[9].unwrap_i32() as i64 + + values[8].unwrap_i32() as i64 * 10 + + values[7].unwrap_i64() * 100 + + values[6].unwrap_i64() * 1000 + + values[5].unwrap_i32() as i64 * 10000 + + values[4].unwrap_i32() as i64 * 100000 + + values[3].unwrap_i32() as i64 * 1000000 + + values[2].unwrap_i32() as i64 * 10000000 + + values[1].unwrap_i32() as i64 * 100000000 + + values[0].unwrap_i32() as i64 * 1000000000, + )]) +} + #[test] fn native_function_works_for_wasm() -> Result<()> { let store = get_store(false); @@ -50,6 +78,93 @@ fn native_function_works_for_wasm() -> Result<()> { Ok(()) } +// The native ABI for functions fails when defining a function natively in +// macos (Darwin) with the Apple Silicon ARM chip +// TODO: Cranelift should have a good ABI for the ABI +#[test] +#[cfg_attr( + all( + feature = "test-cranelift", + target_os = "macos", + target_arch = "aarch64", + ), + ignore +)] +fn native_function_works_for_wasm_function_manyparams() -> Result<()> { + let store = get_store(false); + let wat = r#"(module + (func $longf (import "env" "longf") (param i32 i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i64)) + (func (export "longf_pure") (param i32 i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i64) + (call $longf (local.get 0) (local.get 1) (local.get 2) (local.get 3) (local.get 4) (local.get 5) (local.get 6) (local.get 7) (local.get 8) (local.get 9))) + (func (export "longf") (result i64) + (call $longf (i32.const 1) (i32.const 2) (i32.const 3) (i32.const 4) (i32.const 5) (i32.const 6) (i64.const 7) (i64.const 8) (i32.const 9) (i32.const 0))) +)"#; + let module = Module::new(&store, wat).unwrap(); + + let import_object = imports! { + "env" => { + "longf" => Function::new_native(&store, long_f), + }, + }; + + let instance = Instance::new(&module, &import_object)?; + + { + let dyn_f: &Function = instance.exports.get("longf")?; + let f: NativeFunc<(), i64> = dyn_f.native().unwrap(); + let result = f.call()?; + assert_eq!(result, 1234567890); + } + + { + let dyn_f: &Function = instance.exports.get("longf_pure")?; + let f: NativeFunc<(u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), i64> = + dyn_f.native().unwrap(); + let result = f.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)?; + assert_eq!(result, 1234567890); + } + + Ok(()) +} + +#[test] +fn native_function_works_for_wasm_function_manyparams_dynamic() -> Result<()> { + let store = get_store(false); + let wat = r#"(module + (func $longf (import "env" "longf") (param i32 i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i64)) + (func (export "longf_pure") (param i32 i32 i32 i32 i32 i32 i64 i64 i32 i32) (result i64) + (call $longf (local.get 0) (local.get 1) (local.get 2) (local.get 3) (local.get 4) (local.get 5) (local.get 6) (local.get 7) (local.get 8) (local.get 9))) + (func (export "longf") (result i64) + (call $longf (i32.const 1) (i32.const 2) (i32.const 3) (i32.const 4) (i32.const 5) (i32.const 6) (i64.const 7) (i64.const 8) (i32.const 9) (i32.const 0))) +)"#; + let module = Module::new(&store, wat).unwrap(); + + let import_object = imports! { + "env" => { + "longf" => Function::new(&store, &FunctionType::new(vec![ValType::I32, ValType::I32, ValType::I32, ValType::I32, ValType::I32, ValType::I32, ValType::I64 , ValType::I64 ,ValType::I32, ValType::I32], vec![ValType::I64]), long_f_dynamic), + }, + }; + + let instance = Instance::new(&module, &import_object)?; + + { + let dyn_f: &Function = instance.exports.get("longf")?; + let f: NativeFunc<(), i64> = dyn_f.native().unwrap(); + let result = f.call()?; + assert_eq!(result, 1234567890); + } + + { + let dyn_f: &Function = instance.exports.get("longf_pure")?; + let f: NativeFunc<(u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), i64> = + dyn_f.native().unwrap(); + let result = f.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)?; + assert_eq!(result, 1234567890); + } + + Ok(()) +} + #[test] fn static_host_function_without_env() -> anyhow::Result<()> { let store = get_store(false); @@ -62,6 +177,25 @@ fn static_host_function_without_env() -> anyhow::Result<()> { Ok((d * 4.0, c * 3.0, b * 2, a * 1)) } + fn long_f( + a: u32, + b: u32, + c: u32, + d: u32, + e: u32, + f: u16, + g: u64, + h: u64, + i: u16, + j: u32, + ) -> (u32, u64, u32) { + ( + a + b * 10 + c * 100 + d * 1000 + e * 10000 + f as u32 * 100000, + g + h * 10, + i as u32 + j * 10, + ) + } + // Native static host function that returns a tuple. { let f = Function::new_native(&store, f); @@ -70,6 +204,17 @@ fn static_host_function_without_env() -> anyhow::Result<()> { assert_eq!(result, (28.0, 15.0, 6, 1)); } + // Native static host function that returns a tuple. + { + let long_f = Function::new_native(&store, long_f); + let long_f_native: NativeFunc< + (u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), + (u32, u64, u32), + > = long_f.native().unwrap(); + let result = long_f_native.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)?; + assert_eq!(result, (654321, 87, 09)); + } + // Native static host function that returns a result of a tuple. { let f = Function::new_native(&store, f_ok); diff --git a/tests/compilers/traps.rs b/tests/compilers/traps.rs index e84d98a9aea..1b7674abe37 100644 --- a/tests/compilers/traps.rs +++ b/tests/compilers/traps.rs @@ -421,7 +421,8 @@ fn mismatched_arguments() -> Result<()> { any( feature = "test-singlepass", feature = "test-llvm", - feature = "test-native" + feature = "test-native", + all(target_os = "macos", target_arch = "aarch64") ), ignore )]