From f59d468a9865bad31189bb35e6b09db29d6a99a3 Mon Sep 17 00:00:00 2001 From: Alex Huszagh Date: Thu, 23 Jun 2022 16:38:01 -0500 Subject: [PATCH 1/2] Re-enable wasm32-unknown-emscripten target. Uses a trick described in rust-lang/rust/issues#85821#issuecomment-969369677. Note that this still allows it to run, despite there seemingly being no entry point: this has no effect on the resulting code. Related to #609. Partially fixes #839. --- .github/workflows/ci.yml | 4 ++-- docker/Dockerfile.wasm32-unknown-emscripten | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b9b511828..84a815d7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -182,9 +182,9 @@ jobs: - { target: x86_64-linux-android, os: ubuntu-latest, cpp: 1, std: 1, run: 1, runners: qemu-user } - { target: x86_64-pc-windows-gnu, os: ubuntu-latest, cpp: 1, std: 1, run: 1 } - { target: i686-pc-windows-gnu, os: ubuntu-latest, cpp: 1, std: 1, run: 1 } - # Disabled for now, see https://github.com/rust-lang/rust/issues/85821 + # Disabled for now, see https://github.com/rust-lang/rust/issues/98216 #- { target: asmjs-unknown-emscripten, os: ubuntu-latest, cpp: 1, std: 1, run: 1 } - #- { target: wasm32-unknown-emscripten, os: ubuntu-latest, cpp: 1, std: 1, run: 1 } + - { target: wasm32-unknown-emscripten, os: ubuntu-latest, cpp: 1, std: 1, run: 1 } - { target: x86_64-unknown-dragonfly, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, build-std: 1 } - { target: i686-unknown-freebsd, os: ubuntu-latest, dylib: 1, std: 1 } - { target: x86_64-unknown-freebsd, os: ubuntu-latest, dylib: 1, std: 1 } diff --git a/docker/Dockerfile.wasm32-unknown-emscripten b/docker/Dockerfile.wasm32-unknown-emscripten index 8b458cbaa..962f48c14 100644 --- a/docker/Dockerfile.wasm32-unknown-emscripten +++ b/docker/Dockerfile.wasm32-unknown-emscripten @@ -16,4 +16,5 @@ RUN apt-get update && apt-get install --assume-yes --no-install-recommends \ python ENV CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_RUNNER=node \ - BINDGEN_EXTRA_CLANG_ARGS_wasm32_unknown_emscripten="--sysroot=/emsdk/upstream/emscripten/cache/sysroot" + BINDGEN_EXTRA_CLANG_ARGS_wasm32_unknown_emscripten="--sysroot=/emsdk/upstream/emscripten/cache/sysroot" \ + EMCC_CFLAGS="-s ERROR_ON_UNDEFINED_SYMBOLS=0 --no-entry ${EMCC_CFLAGS}" From a9ac1388bfd97aed6b1fb86a414450b7fc8a7938 Mon Sep 17 00:00:00 2001 From: Alex Huszagh Date: Thu, 23 Jun 2022 22:47:40 -0500 Subject: [PATCH 2/2] Update README with target info for solaris and emscripten. Update `xtask target-info` to support solaris and emscripten targets, and update their info in the README, showing the targets are enabled and with their updated toolchain versions. --- README.md | 14 ++++---- xtask/src/target_info.sh | 78 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e4c070cec..6a33dcea6 100644 --- a/README.md +++ b/README.md @@ -355,24 +355,24 @@ terminate. | `riscv64gc-unknown-linux-gnu` | 2.27 | 7.5.0 | ✓ | 6.1.0 | ✓ | | `s390x-unknown-linux-gnu` | 2.23 | 5.4.0 | ✓ | 5.1.0 | ✓ | | `sparc64-unknown-linux-gnu` | 2.23 | 5.4.0 | ✓ | 5.1.0 | ✓ | +| `sparcv9-sun-solaris` | 1.22.7 | 8.4.0 | ✓ | N/A | | | `thumbv6m-none-eabi` [4] | 2.2.0 | 4.9.3 | | N/A | | | `thumbv7em-none-eabi` [4] | 2.2.0 | 4.9.3 | | N/A | | | `thumbv7em-none-eabihf` [4] | 2.2.0 | 4.9.3 | | N/A | | | `thumbv7m-none-eabi` [4] | 2.2.0 | 4.9.3 | | N/A | | | `thumbv7neon-linux-androideabi` [1] | 9.0.8 | 9.0.8 | ✓ | 6.1.0 | ✓ | | `thumbv7neon-unknown-linux-gnueabihf`| 2.23 | 5.4.0 | ✓ | 5.1.0 | ✓ | +| `wasm32-unknown-emscripten` [6] | 3.1.10 | 15.0.0 | ✓ | N/A | ✓ | | `x86_64-linux-android` [1] | 9.0.8 | 9.0.8 | ✓ | 6.1.0 | ✓ | | `x86_64-pc-windows-gnu` | N/A | 7.3 | ✓ | N/A | ✓ | +| `x86_64-sun-solaris` | 1.22.7 | 8.4.0 | ✓ | N/A | | | `x86_64-unknown-freebsd` | 1.5 | 6.4.0 | ✓ | N/A | | | `x86_64-unknown-dragonfly` [2] [3] | 6.0.1 | 5.3.0 | ✓ | N/A | | | `x86_64-unknown-linux-gnu` | 2.23 | 5.4.0 | ✓ | 5.1.0 | ✓ | | `x86_64-unknown-linux-gnu:centos` [5] | 2.17 | 4.8.5 | ✓ | 4.2.1 | ✓ | | `x86_64-unknown-linux-musl` | 1.1.24 | 9.2.0 | ✓ | N/A | ✓ | | `x86_64-unknown-netbsd` [3] | 9.2.0 | 9.4.0 | ✓ | N/A | | - - - - + [1] libc = bionic; Only works with native tests, that is, tests that do not depends on the Android Runtime. For i686 some tests may fails with the error `assertion @@ -389,8 +389,10 @@ terminate. [5] Must change `image = "x86_64-unknown-linux-gnu:main-centos"` in `Cross.toml` for `[target.x86_64-unknown-linux-gnu]` to use the CentOS7-compatible target. - +[6] libc = emscripten and GCC = clang + + Additional Dockerfiles for other targets can be found in [cross-toolchains](https://github.com/cross-rs/cross-toolchains). diff --git a/xtask/src/target_info.sh b/xtask/src/target_info.sh index b8fa90fe3..b6cc8e948 100755 --- a/xtask/src/target_info.sh +++ b/xtask/src/target_info.sh @@ -62,6 +62,48 @@ max_glibc_version() { echo "${major}.${minor}" } +max_solaris_libc_version() { + # solaris libc versions have the following format: + # 67: 0000000000000000 0 OBJECT GLOBAL DEFAULT ABS SUNW_1.21.1 + local major=0 + local minor=0 + local patch=0 + local version + local x + local y + local z + local is_larger + + for version in "${@}"; do + x=$(echo "${version}" | cut -d '.' -f 1) + y=$(echo "${version}" | cut -d '.' -f 2) + z=$(echo "${version}" | cut -d '.' -f 3) + is_larger= + + if [ "${x}" -gt "${major}" ]; then + is_larger=1 + elif [ "${x}" -eq "${major}" ] && [ "${y}" -gt "${minor}" ]; then + is_larger=1 + elif [ -z "${patch}" ]; then + is_larger=1 + elif [ -n "${z}" ] && [ "${x}" -eq "${major}" ] && [ "${y}" -eq "${minor}" ] && [ "${z}" -gt "${patch}" ]; then + is_larger=1 + fi + + if [ -n "${is_larger}" ]; then + major="${x}" + minor="${y}" + patch="${z}" + fi + done + + result="${major}.${minor}" + if [ -n "${patch}" ]; then + result="${result}.${patch}" + fi + echo "${result}" +} + readelf_all() { # weirdly, readelf -a can produce a non-zero error code. set +e @@ -104,6 +146,12 @@ case "${target}" in *-*-dragonfly) cc_regex=".*gcc \(GCC\) ([0-9]+.[0-9]+.[0-9]+).*" ;; + *-*-solaris) + cc_regex=".*gcc \(GCC\) ([0-9]+.[0-9]+.[0-9]+).*" + ;; + *-*-emscripten) + cc_regex="clang version ([0-9]+.[0-9]+.[0-9]+).*" + ;; *-none-*) cc_regex=".*gcc \(.*\) ([0-9]+.[0-9]+.[0-9]+).*" ;; @@ -150,11 +198,14 @@ case "${target}" in cc_bin=arm-none-eabi-gcc cxx_bin=arm-none-eabi-g++ ;; + *-*-emscripten) + cc_bin="${EMSDK}/upstream/bin/clang" + cxx_bin="${cc_bin}" + ;; *) cc_bin="${!cc_var}" cxx_bin="${!cxx_var}" ;; - esac cc=$(extract_regex_version "${cc_bin}" "${cc_regex}" compiler) if command -v "${cxx_bin}" &>/dev/null; then @@ -169,6 +220,12 @@ EOT if [[ "${target}" == *-none-* ]]; then cxx_flags=("${cxx_flags[@]}" "-nostartfiles") fi + if [[ "${target}" == *-*-emscripten ]]; then + # need to switch to the real c++ compiler here, not the wrapper + cxx_bin=emcc + # shellcheck disable=SC2206 + cxx_flags=($EMCC_CFLAGS) + fi if "${cxx_bin}" "${cxx_flags[@]}" main.cc >/dev/null 2>&1; then cxx=1 fi @@ -287,6 +344,25 @@ case "${target}" in exit 1 fi ;; + *-*-solaris) + # we can read the libc version from the libc symbols + # first, we need to use our compiler name to get the libdir + # 67: 0000000000000000 0 OBJECT GLOBAL DEFAULT ABS SUNW_1.21.1 + # there will be many of these, so we want to grab the highest one. + prefix="${cc_bin//-gcc/}" + libdir="/usr/local/${prefix}/lib" + lines=$(readelf_all "${libdir}"/libc.so | grep 'ABS SUNW_') + lines=$(echo "${lines}" | grep -o 'ABS .*') + # shellcheck disable=SC2207 + libc_versions=($(echo "$lines" | cut -d ' ' -f 2 | cut -d '_' -f 2)) + libc=$(max_solaris_libc_version "${libc_versions[@]}") + ;; + *-*-emscripten) + # we want the emsdk version, which is the image version + libc_cmd=emcc + libc_regex="emcc \(.* GNU ld) ([0-9]+.[0-9]+.[0-9]+).*" + libc=$(extract_regex_version "${libc_cmd}" "${libc_regex}" libc) + ;; thumb*-none-eabi* | arm*-none-eabi*) # newlib kinda sucks. just query for the install package pkg=$(dpkg --get-selections | grep -v deinstall | grep newlib | head -n 1)