Skip to content

Commit 4894cb8

Browse files
Merge #840
840: Re-enable wasm32-unknown-emscripten target. r=Emilgardis a=Alexhuszagh 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. Co-authored-by: Alex Huszagh <[email protected]>
2 parents e0a5342 + a9ac138 commit 4894cb8

File tree

4 files changed

+89
-10
lines changed

4 files changed

+89
-10
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ jobs:
182182
- { target: x86_64-linux-android, os: ubuntu-latest, cpp: 1, std: 1, run: 1, runners: qemu-user }
183183
- { target: x86_64-pc-windows-gnu, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
184184
- { target: i686-pc-windows-gnu, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
185-
# Disabled for now, see https://github.com/rust-lang/rust/issues/85821
185+
# Disabled for now, see https://github.com/rust-lang/rust/issues/98216
186186
#- { target: asmjs-unknown-emscripten, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
187-
#- { target: wasm32-unknown-emscripten, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
187+
- { target: wasm32-unknown-emscripten, os: ubuntu-latest, cpp: 1, std: 1, run: 1 }
188188
- { target: x86_64-unknown-dragonfly, os: ubuntu-latest, cpp: 1, dylib: 1, std: 1, build-std: 1 }
189189
- { target: i686-unknown-freebsd, os: ubuntu-latest, dylib: 1, std: 1 }
190190
- { target: x86_64-unknown-freebsd, os: ubuntu-latest, dylib: 1, std: 1 }

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,24 +355,24 @@ terminate.
355355
| `riscv64gc-unknown-linux-gnu` | 2.27 | 7.5.0 || 6.1.0 ||
356356
| `s390x-unknown-linux-gnu` | 2.23 | 5.4.0 || 5.1.0 ||
357357
| `sparc64-unknown-linux-gnu` | 2.23 | 5.4.0 || 5.1.0 ||
358+
| `sparcv9-sun-solaris` | 1.22.7 | 8.4.0 || N/A | |
358359
| `thumbv6m-none-eabi` [4] | 2.2.0 | 4.9.3 | | N/A | |
359360
| `thumbv7em-none-eabi` [4] | 2.2.0 | 4.9.3 | | N/A | |
360361
| `thumbv7em-none-eabihf` [4] | 2.2.0 | 4.9.3 | | N/A | |
361362
| `thumbv7m-none-eabi` [4] | 2.2.0 | 4.9.3 | | N/A | |
362363
| `thumbv7neon-linux-androideabi` [1] | 9.0.8 | 9.0.8 || 6.1.0 ||
363364
| `thumbv7neon-unknown-linux-gnueabihf`| 2.23 | 5.4.0 || 5.1.0 ||
365+
| `wasm32-unknown-emscripten` [6] | 3.1.10 | 15.0.0 || N/A ||
364366
| `x86_64-linux-android` [1] | 9.0.8 | 9.0.8 || 6.1.0 ||
365367
| `x86_64-pc-windows-gnu` | N/A | 7.3 || N/A ||
368+
| `x86_64-sun-solaris` | 1.22.7 | 8.4.0 || N/A | |
366369
| `x86_64-unknown-freebsd` | 1.5 | 6.4.0 || N/A | |
367370
| `x86_64-unknown-dragonfly` [2] [3] | 6.0.1 | 5.3.0 || N/A | |
368371
| `x86_64-unknown-linux-gnu` | 2.23 | 5.4.0 || 5.1.0 ||
369372
| `x86_64-unknown-linux-gnu:centos` [5] | 2.17 | 4.8.5 || 4.2.1 ||
370373
| `x86_64-unknown-linux-musl` | 1.1.24 | 9.2.0 || N/A ||
371374
| `x86_64-unknown-netbsd` [3] | 9.2.0 | 9.4.0 || N/A | |
372-
<!--| `asmjs-unknown-emscripten` [6] | 1.2.2 | 3.1.10 | ✓ | N/A | ✓ |-->
373-
<!--| `wasm32-unknown-emscripten` [6] | 1.2.2 | 3.1.10 | ✓ | N/A | ✓ |-->
374-
<!--| `sparcv9-sun-solaris` [3] | 2.11 | 5.3.0 | ✓ | N/A | |-->
375-
<!--| `x86_64-sun-solaris` [3] | 2.11 | 5.3.0 | ✓ | N/A | |-->
375+
<!--| `asmjs-unknown-emscripten` [7] | 1.2.2 | 3.1.10 | ✓ | N/A | ✓ |-->
376376

377377
[1] libc = bionic; Only works with native tests, that is, tests that do not depends on the
378378
Android Runtime. For i686 some tests may fails with the error `assertion
@@ -389,8 +389,10 @@ terminate.
389389

390390
[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.
391391

392-
<!--[6] libc = musl, gcc = emcc. The Docker images for these targets are currently not built automatically
393-
due to a [compiler bug](https://github.com/rust-lang/rust/issues/85821), you will have to build them yourself for now.-->
392+
[6] libc = emscripten and GCC = clang
393+
394+
<!--[7] libc = emscripten and GCC = clang. The Docker images for these targets are currently not built automatically
395+
due to a [compiler bug](https://github.com/rust-lang/rust/issues/98216), you will have to build them yourself for now.-->
394396

395397
Additional Dockerfiles for other targets can be found in [cross-toolchains](https://github.com/cross-rs/cross-toolchains).
396398
These include MSVC and Apple Darwin targets, which we cannot ship pre-built images of.

docker/Dockerfile.wasm32-unknown-emscripten

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ RUN apt-get update && apt-get install --assume-yes --no-install-recommends \
1616
python
1717

1818
ENV CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_RUNNER=node \
19-
BINDGEN_EXTRA_CLANG_ARGS_wasm32_unknown_emscripten="--sysroot=/emsdk/upstream/emscripten/cache/sysroot"
19+
BINDGEN_EXTRA_CLANG_ARGS_wasm32_unknown_emscripten="--sysroot=/emsdk/upstream/emscripten/cache/sysroot" \
20+
EMCC_CFLAGS="-s ERROR_ON_UNDEFINED_SYMBOLS=0 --no-entry ${EMCC_CFLAGS}"

xtask/src/target_info.sh

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,48 @@ max_glibc_version() {
6262
echo "${major}.${minor}"
6363
}
6464

65+
max_solaris_libc_version() {
66+
# solaris libc versions have the following format:
67+
# 67: 0000000000000000 0 OBJECT GLOBAL DEFAULT ABS SUNW_1.21.1
68+
local major=0
69+
local minor=0
70+
local patch=0
71+
local version
72+
local x
73+
local y
74+
local z
75+
local is_larger
76+
77+
for version in "${@}"; do
78+
x=$(echo "${version}" | cut -d '.' -f 1)
79+
y=$(echo "${version}" | cut -d '.' -f 2)
80+
z=$(echo "${version}" | cut -d '.' -f 3)
81+
is_larger=
82+
83+
if [ "${x}" -gt "${major}" ]; then
84+
is_larger=1
85+
elif [ "${x}" -eq "${major}" ] && [ "${y}" -gt "${minor}" ]; then
86+
is_larger=1
87+
elif [ -z "${patch}" ]; then
88+
is_larger=1
89+
elif [ -n "${z}" ] && [ "${x}" -eq "${major}" ] && [ "${y}" -eq "${minor}" ] && [ "${z}" -gt "${patch}" ]; then
90+
is_larger=1
91+
fi
92+
93+
if [ -n "${is_larger}" ]; then
94+
major="${x}"
95+
minor="${y}"
96+
patch="${z}"
97+
fi
98+
done
99+
100+
result="${major}.${minor}"
101+
if [ -n "${patch}" ]; then
102+
result="${result}.${patch}"
103+
fi
104+
echo "${result}"
105+
}
106+
65107
readelf_all() {
66108
# weirdly, readelf -a can produce a non-zero error code.
67109
set +e
@@ -104,6 +146,12 @@ case "${target}" in
104146
*-*-dragonfly)
105147
cc_regex=".*gcc \(GCC\) ([0-9]+.[0-9]+.[0-9]+).*"
106148
;;
149+
*-*-solaris)
150+
cc_regex=".*gcc \(GCC\) ([0-9]+.[0-9]+.[0-9]+).*"
151+
;;
152+
*-*-emscripten)
153+
cc_regex="clang version ([0-9]+.[0-9]+.[0-9]+).*"
154+
;;
107155
*-none-*)
108156
cc_regex=".*gcc \(.*\) ([0-9]+.[0-9]+.[0-9]+).*"
109157
;;
@@ -150,11 +198,14 @@ case "${target}" in
150198
cc_bin=arm-none-eabi-gcc
151199
cxx_bin=arm-none-eabi-g++
152200
;;
201+
*-*-emscripten)
202+
cc_bin="${EMSDK}/upstream/bin/clang"
203+
cxx_bin="${cc_bin}"
204+
;;
153205
*)
154206
cc_bin="${!cc_var}"
155207
cxx_bin="${!cxx_var}"
156208
;;
157-
158209
esac
159210
cc=$(extract_regex_version "${cc_bin}" "${cc_regex}" compiler)
160211
if command -v "${cxx_bin}" &>/dev/null; then
@@ -169,6 +220,12 @@ EOT
169220
if [[ "${target}" == *-none-* ]]; then
170221
cxx_flags=("${cxx_flags[@]}" "-nostartfiles")
171222
fi
223+
if [[ "${target}" == *-*-emscripten ]]; then
224+
# need to switch to the real c++ compiler here, not the wrapper
225+
cxx_bin=emcc
226+
# shellcheck disable=SC2206
227+
cxx_flags=($EMCC_CFLAGS)
228+
fi
172229
if "${cxx_bin}" "${cxx_flags[@]}" main.cc >/dev/null 2>&1; then
173230
cxx=1
174231
fi
@@ -287,6 +344,25 @@ case "${target}" in
287344
exit 1
288345
fi
289346
;;
347+
*-*-solaris)
348+
# we can read the libc version from the libc symbols
349+
# first, we need to use our compiler name to get the libdir
350+
# 67: 0000000000000000 0 OBJECT GLOBAL DEFAULT ABS SUNW_1.21.1
351+
# there will be many of these, so we want to grab the highest one.
352+
prefix="${cc_bin//-gcc/}"
353+
libdir="/usr/local/${prefix}/lib"
354+
lines=$(readelf_all "${libdir}"/libc.so | grep 'ABS SUNW_')
355+
lines=$(echo "${lines}" | grep -o 'ABS .*')
356+
# shellcheck disable=SC2207
357+
libc_versions=($(echo "$lines" | cut -d ' ' -f 2 | cut -d '_' -f 2))
358+
libc=$(max_solaris_libc_version "${libc_versions[@]}")
359+
;;
360+
*-*-emscripten)
361+
# we want the emsdk version, which is the image version
362+
libc_cmd=emcc
363+
libc_regex="emcc \(.* GNU ld) ([0-9]+.[0-9]+.[0-9]+).*"
364+
libc=$(extract_regex_version "${libc_cmd}" "${libc_regex}" libc)
365+
;;
290366
thumb*-none-eabi* | arm*-none-eabi*)
291367
# newlib kinda sucks. just query for the install package
292368
pkg=$(dpkg --get-selections | grep -v deinstall | grep newlib | head -n 1)

0 commit comments

Comments
 (0)