diff --git a/.github/cross-linux-riscv64/Dockerfile b/.github/cross-linux-riscv64/Dockerfile new file mode 100644 index 00000000000..6f942ad5671 --- /dev/null +++ b/.github/cross-linux-riscv64/Dockerfile @@ -0,0 +1,61 @@ +FROM debian:sid AS openssl_riscv64 +#FROM ghcr.io/cross-rs/aarch64-unknown-linux-gnu:edge + +# set CROSS_DOCKER_IN_DOCKER to inform `cross` that it is executed from within a container +ENV CROSS_DOCKER_IN_DOCKER=true + +RUN apt-get update && \ + apt-get install --assume-yes --no-install-recommends \ + ca-certificates \ + curl \ + cpio \ + sharutils \ + gnupg \ + build-essential \ + libc6-dev + +COPY install_deb.sh / + +#install libssl-dev for riscv64! +RUN /install_deb.sh riscv64 libssl-dev +ENV RISCV64GC_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR=/usr/include +ENV RISCV64GC_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR=/usr/lib/riscv64-linux-gnu + + +# install rust tools +RUN curl --proto "=https" --tlsv1.2 --retry 3 -sSfL https://sh.rustup.rs | sh -s -- -y +ENV PATH="/root/.cargo/bin:${PATH}" +RUN rustup -v toolchain install 1.65 +# add docker the manual way +COPY install_docker.sh / +RUN /install_docker.sh + +RUN apt-get update && \ + apt-get install --assume-yes --no-install-recommends \ + docker-ce \ + docker-ce-cli \ + containerd.io \ + docker-buildx-plugin \ + docker-compose-plugin + +RUN apt-get update && apt-get install -y --no-install-recommends \ + gcc-riscv64-linux-gnu \ + g++-riscv64-linux-gnu \ + qemu-user-static \ + libssl-dev \ + pkg-config \ + libc6-dev-riscv64-cross + +ENV CROSS_TOOLCHAIN_PREFIX=riscv64-linux-gnu- +ENV CROSS_SYSROOT=/usr/riscv64-linux-gnu +ENV CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER="$CROSS_TOOLCHAIN_PREFIX"gcc \ + AR_riscv64gc_unknown_linux_gnu="$CROSS_TOOLCHAIN_PREFIX"ar \ + CC_riscv64gc_unknown_linux_gnu="$CROSS_TOOLCHAIN_PREFIX"gcc \ + CXX_riscv64gc_unknown_linux_gnu="$CROSS_TOOLCHAIN_PREFIX"g++ \ + CFLAGS_riscv64gc_unknown_linux_gnu="-march=rv64gc -mabi=lp64d" \ + BINDGEN_EXTRA_CLANG_ARGS_riscv64gc_unknown_linux_gnu="--sysroot=$CROSS_SYSROOT" \ + QEMU_LD_PREFIX="$CROSS_SYSROOT" \ + RUST_TEST_THREADS=1 \ + PKG_CONFIG_PATH="/usr/lib/riscv64-linux-gnu/pkgconfig/:${PKG_CONFIG_PATH}" + +RUN rustup target add riscv64gc-unknown-linux-gnu --toolchain 1.65-x86_64-unknown-linux-gnu diff --git a/.github/cross-linux-riscv64/install_deb.sh b/.github/cross-linux-riscv64/install_deb.sh new file mode 100755 index 00000000000..a38715c2762 --- /dev/null +++ b/.github/cross-linux-riscv64/install_deb.sh @@ -0,0 +1,56 @@ +#!/bin/bash +set -x +set -euo pipefail + +arch="${1}" +shift + +# need to install certain local dependencies +export DEBIAN_FRONTEND=noninteractive +apt-get update +apt-get install --assume-yes --no-install-recommends \ + ca-certificates \ + curl \ + cpio \ + sharutils \ + gnupg + +# Add port from sid to get some riscv packages +debsource="deb http://deb.debian.org/debian-ports sid main" + +# temporarily use debian sources rather than ubuntu. +touch /etc/apt/sources.list +mv /etc/apt/sources.list /etc/apt/sources.list.bak +echo -e "${debsource}" > /etc/apt/sources.list + +dpkg --add-architecture "${arch}" || echo "foreign-architecture ${arch}" \ + > /etc/dpkg/dpkg.cfg.d/multiarch + +# Add Debian keys. +curl --retry 3 -sSfL 'https://ftp-master.debian.org/keys/archive-key-{7.0,8,9,10}.asc' -O +curl --retry 3 -sSfL 'https://ftp-master.debian.org/keys/archive-key-{8,9,10}-security.asc' -O +curl --retry 3 -sSfL 'https://ftp-master.debian.org/keys/release-{7,8,9,10}.asc' -O +curl --retry 3 -sSfL 'https://www.ports.debian.org/archive_{2020,2021,2022,2023}.key' -O + +for key in *.asc *.key; do + apt-key add "${key}" + rm "${key}" +done + +# allow apt-get to retry downloads +echo 'APT::Acquire::Retries "3";' > /etc/apt/apt.conf.d/80-retries + +apt-get update +for dep in $@; do + apt-get install "${dep}:${arch}" --assume-yes +done + +# restore our old sources list +mv -f /etc/apt/sources.list.bak /etc/apt/sources.list +if [ -f /etc/dpkg/dpkg.cfg.d/multiarch.bak ]; then + mv /etc/dpkg/dpkg.cfg.d/multiarch.bak /etc/dpkg/dpkg.cfg.d/multiarch +fi + +# can fail if arch is used (amd64 and/or i386) +dpkg --remove-architecture "${arch}" || true +apt-get update \ No newline at end of file diff --git a/.github/cross-linux-riscv64/install_docker.sh b/.github/cross-linux-riscv64/install_docker.sh new file mode 100755 index 00000000000..ea7e7aef2fe --- /dev/null +++ b/.github/cross-linux-riscv64/install_docker.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -x +set -euo pipefail + +mkdir -m 0755 -p /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg + +echo \ + "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ + "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ + tee /etc/apt/sources.list.d/docker.list > /dev/null diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1aa29a0eaff..d995995c442 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -401,8 +401,73 @@ jobs: if-no-files-found: error retention-days: 2 + linux_riscv64: + name: Linux riscv64 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + with: + target: riscv64gc-unknown-linux-gnu + - name: Build cross image + run: | + docker build -t wasmer/riscv64 ${GITHUB_WORKSPACE}/.github/cross-linux-riscv64/ + env: + CROSS_DOCKER_IN_DOCKER: true + - name: Build Wasmer binary + run: | + make build-wasmer + env: + CARGO_BINARY: docker run -v /var/run/docker.sock:/var/run/docker.sock -v ${GITHUB_WORKSPACE}:/project -w /project wasmer/riscv64:latest cargo + CROSS_DOCKER_IN_DOCKER: true + CARGO_TARGET: riscv64gc-unknown-linux-gnu + PKG_CONFIG_PATH: /usr/lib/riscv64-linux-gnu/pkgconfig + PKG_CONFIG_ALLOW_CROSS: true + ENABLE_LLVM: 0 + - name: Build C API headless + shell: bash + run: | + make package-capi-headless + env: + CARGO_BINARY: docker run -v /var/run/docker.sock:/var/run/docker.sock -v ${GITHUB_WORKSPACE}:/project -w /project wasmer/riscv64:latest cargo + CROSS_DOCKER_IN_DOCKER: true + CARGO_TARGET: riscv64gc-unknown-linux-gnu + PKG_CONFIG_PATH: /usr/lib/riscv64-linux-gnu/pkgconfig + PKG_CONFIG_ALLOW_CROSS: true + ENABLE_LLVM: 0 + TARGET: riscv64gc-unknown-linux-gnu + TARGET_DIR: target/riscv64gc-unknown-linux-gnu/release + - name: Build C API + run: | + make build-capi + env: + CARGO_BINARY: docker run -v /var/run/docker.sock:/var/run/docker.sock -v ${GITHUB_WORKSPACE}:/project -w /project wasmer/riscv64:latest cargo + CROSS_DOCKER_IN_DOCKER: true + CARGO_TARGET: riscv64gc-unknown-linux-gnu + PKG_CONFIG_PATH: /usr/lib/riscv64-linux-gnu/pkgconfig + PKG_CONFIG_ALLOW_CROSS: true + ENABLE_LLVM: 0 + - name: Dist + run: | + make distribution + env: + CARGO_BINARY: docker run -v /var/run/docker.sock:/var/run/docker.sock -v ${GITHUB_WORKSPACE}:/project -w /project wasmer/riscv64:latest cargo + CROSS_DOCKER_IN_DOCKER: true + CARGO_TARGET: riscv64gc-unknown-linux-gnu + PKG_CONFIG_PATH: /usr/lib/riscv64-linux-gnu/pkgconfig + PKG_CONFIG_ALLOW_CROSS: true + TARGET: riscv64gc-unknown-linux-gnu + TARGET_DIR: target/riscv64gc-unknown-linux-gnu/release + - name: Upload Artifacts + uses: actions/upload-artifact@v3 + with: + name: wasmer-linux-riscv64 + path: dist + if-no-files-found: error + retention-days: 2 + release: - needs: [setup, build, linux_aarch64, windows_gnu] + needs: [setup, build, linux_aarch64, windows_gnu, linux_riscv64] runs-on: ubuntu-latest if: needs.setup.outputs.DOING_RELEASE == '1' || github.event.inputs.release != '' steps: @@ -456,6 +521,15 @@ jobs: asset_path: artifacts/wasmer-linux-aarch64/wasmer.tar.gz asset_name: wasmer-linux-aarch64.tar.gz asset_content_type: application/gzip + - name: Upload Release Asset Linux riscv64 + 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-linux-riscv64/wasmer.tar.gz + asset_name: wasmer-linux-riscv64.tar.gz + asset_content_type: application/gzip - name: Upload Release Asset Windows gnu64 uses: actions/upload-release-asset@v1 env: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e533cdfa85b..b39dc7fa473 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -150,7 +150,7 @@ jobs: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable with: - toolchain: 1.61 + toolchain: 1.65 target: aarch64-unknown-linux-gnu - name: Build cross image run: | @@ -188,6 +188,64 @@ jobs: if-no-files-found: error retention-days: 2 + build_linux_riscv64: + name: ${{ matrix.build-what.name }} on linux-riscv64 + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + build-what: [ + { + key: capi, + build-cmd: 'make build-capi && make package-capi', + name: 'Build C-API' + }, + { + key: wasmer, + build-cmd: 'make build-wasmer && make package-wasmer && make tar-wasmer', + name: 'Build wasmer-cli' + } + ] + steps: + - uses: actions/checkout@v3 + #- uses: dtolnay/rust-toolchain@stable + # with: + # toolchain: 1.65 + # target: riscv64gc-unknown-linux-gnu + - name: Build cross image + run: | + docker build -t wasmer/riscv64 ${GITHUB_WORKSPACE}/.github/cross-linux-riscv64/ + env: + CROSS_DOCKER_IN_DOCKER: true + - name: Build ${{ matrix.build-what.key }} + run: | + ${{ matrix.build-what.build-cmd }} + env: + CARGO_BINARY: docker run -v /var/run/docker.sock:/var/run/docker.sock -v ${GITHUB_WORKSPACE}:/project -w /project wasmer/riscv64 cargo + CROSS_DOCKER_IN_DOCKER: true + CARGO_TARGET: riscv64gc-unknown-linux-gnu + ENABLE_LLVM: 0 + - name: Dist + if: ${{ matrix.build-what.key == 'capi' }} + run: | + make distribution + env: + CARGO_BINARY: docker run -v /var/run/docker.sock:/var/run/docker.sock -v ${GITHUB_WORKSPACE}:/project -w /project wasmer/riscv64 cargo + CROSS_DOCKER_IN_DOCKER: true + CARGO_TARGET: riscv64gc-unknown-linux-gnu + PKG_CONFIG_PATH: /usr/lib/riscv64-linux-gnu/pkgconfig + PKG_CONFIG_ALLOW_CROSS: true + TARGET: riscv64gc-unknown-linux-gnu + TARGET_DIR: target/riscv64gc-unknown-linux-gnu/release + - name: Upload Artifacts + if: ${{ matrix.build-what.key == 'capi' }} + uses: actions/upload-artifact@v3 + with: + name: capi-linux-riscv64 + path: dist + if-no-files-found: error + retention-days: 2 + build: name: ${{ matrix.build-what.name }} on ${{ matrix.metadata.build }} runs-on: ${{ matrix.metadata.os }} @@ -544,7 +602,7 @@ jobs: test_integration_cli: name: CLI integration tests on ${{ matrix.build }} runs-on: ${{ matrix.os }} - needs: [build, build_linux_aarch64] + needs: [build, build_linux_aarch64, build_linux_riscv64] strategy: fail-fast: false matrix: @@ -634,6 +692,10 @@ jobs: with: name: capi-linux-x64 path: package/cache/wasmercache5 + - uses: actions/download-artifact@v3 + with: + name: capi-linux-riscv64 + path: package/cache/wasmercache6 - name: Copy .tar.gz files to proper location shell: bash run: | @@ -647,6 +709,7 @@ jobs: cp package/cache/wasmercache3/build-capi.tar.gz package/cache/wasmer-darwin-arm64.tar.gz cp package/cache/wasmercache4/build-capi.tar.gz package/cache/wasmer-darwin-amd64.tar.gz cp package/cache/wasmercache5/build-capi.tar.gz package/cache/wasmer-linux-amd64.tar.gz + cp package/cache/wasmercache6/wasmer.tar.gz package/cache/wasmer-linux-riscv64.tar.gz - uses: actions/download-artifact@v3 if: ${{ matrix.build == 'windows-x64' }} with: diff --git a/Makefile b/Makefile index 0148d811f53..36c1311dc7a 100644 --- a/Makefile +++ b/Makefile @@ -85,7 +85,7 @@ else # We use spaces instead of tabs to indent `$(error)` # otherwise it's considered as a command outside a # target and it will fail. - $(error Unrecognized architecture, expect `x86_64`, `aarch64` or `arm64`) + $(error Unrecognized architecture, expect `x86_64`, `aarch64`, `arm64`, 'riscv64') endif # Libc diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index f6b09488bf2..6fcfb1b55cc 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -199,6 +199,10 @@ bin-dir = "bin/{ bin }" pkg-url = "{ repo }/releases/download/v{ version }/wasmer-linux-aarch64.{ archive-format }" bin-dir = "bin/{ bin }" +[package.metadata.binstall.overrides.riscv64gc-unknown-linux-gnu] +pkg-url = "{ repo }/releases/download/v{ version }/wasmer-linux-riscv64gc.{ archive-format }" +bin-dir = "bin/{ bin }" + [package.metadata.binstall.overrides.x86_64-unknown-linux-gnu] pkg-url = "{ repo }/releases/download/v{ version }/wasmer-linux-amd64.{ archive-format }" bin-dir = "bin/{ bin }"