Skip to content

Commit 70fd2d4

Browse files
Ekleogtaiki-e
andauthored
Add wasm-bindgen (#383)
Co-authored-by: Taiki Endo <[email protected]>
1 parent 41e81ec commit 70fd2d4

File tree

6 files changed

+276
-77
lines changed

6 files changed

+276
-77
lines changed

.github/.cspell/project-dictionary.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
almalinux
2+
bindgen
23
binstall
34
coreutils
45
distro

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ https://spdx.org/licenses
114114
| [**shfmt**](https://github.com/mvdan/sh) | `/usr/local/bin` | [GitHub Releases](https://github.com/mvdan/sh/releases) | Linux, macOS, Windows | [BSD-3-Clause](https://github.com/mvdan/sh/blob/HEAD/LICENSE) |
115115
| [**syft**](https://github.com/anchore/syft) | `/usr/local/bin` | [Github Releases](https://github.com/anchore/syft/releases) | Linux, macOS, Windows | [Apache-2.0](https://github.com/anchore/syft/blob/HEAD/LICENSE) |
116116
| [**valgrind**](https://valgrind.org) | `/snap/bin` | [snap](https://snapcraft.io/install/valgrind/ubuntu) | Linux | [GPL-2.0-or-later](https://valgrind.org/docs/manual/license.gpl.html) |
117+
| [**wasm-bindgen**](https://github.com/rustwasm/wasm-bindgen) | `$CARGO_HOME/bin` | [GitHub Releases](https://github.com/rustwasm/wasm-bindgen/releases) | Linux, macOS, Windows | [Apache-2.0](https://github.com/rustwasm/wasm-bindgen/blob/HEAD/LICENSE-APACHE) OR [MIT](https://github.com/rustwasm/wasm-bindgen/blob/HEAD/LICENSE-MIT) |
117118
| [**wasm-pack**](https://github.com/rustwasm/wasm-pack) | `$CARGO_HOME/bin` | [GitHub Releases](https://github.com/rustwasm/wasm-pack/releases) | Linux, macOS, Windows | [Apache-2.0](https://github.com/rustwasm/wasm-pack/blob/HEAD/LICENSE-APACHE) OR [MIT](https://github.com/rustwasm/wasm-pack/blob/HEAD/LICENSE-MIT) |
118119
| [**wasmtime**](https://github.com/bytecodealliance/wasmtime) | `$CARGO_HOME/bin` | [GitHub Releases](https://github.com/bytecodealliance/wasmtime/releases) | Linux, macOS, Windows | [Apache-2.0 WITH LLVM-exception](https://github.com/bytecodealliance/wasmtime/blob/HEAD/LICENSE) |
119120
| [**xbuild**](https://github.com/rust-mobile/xbuild) | `$CARGO_HOME/bin` | [GitHub Releases](https://github.com/rust-mobile/xbuild/releases) | Linux, macOS, Windows | Apache-2.0 OR MIT |

main.sh

+98-59
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,26 @@ download_and_checksum() {
5454
}
5555
download_and_extract() {
5656
local url="$1"
57-
local checksum="$2"
58-
local bin_dir="$3"
59-
local bin_in_archive="$4" # path to bin in archive
57+
shift
58+
local checksum="$1"
59+
shift
60+
local bin_dir="$1"
61+
shift
62+
local bin_in_archive=("$@") # path to bin in archive
6063
if [[ "${bin_dir}" == "${install_action_dir}/bin" ]]; then
6164
init_install_action_bin_dir
6265
fi
6366

64-
local installed_bin
65-
# xbuild's binary name is "x", as opposed to the usual crate name
67+
installed_bin=()
68+
local tmp
6669
case "${tool}" in
67-
xbuild) installed_bin="${bin_dir}/x" ;;
68-
*) installed_bin="${bin_dir}/$(basename "${bin_in_archive}")" ;;
70+
# xbuild's binary name is "x", as opposed to the usual crate name
71+
xbuild) installed_bin=("${bin_dir}/x") ;;
72+
*)
73+
for tmp in "${bin_in_archive[@]}"; do
74+
installed_bin+=("${bin_dir}/$(basename "${tmp}")")
75+
done
76+
;;
6977
esac
7078

7179
local tar_args=()
@@ -119,29 +127,35 @@ download_and_extract() {
119127
download_and_checksum "${url}" "${checksum}"
120128
if [[ ${#tar_args[@]} -gt 0 ]]; then
121129
tar_args+=("tmp")
122-
local components
123-
components=$(tr <<<"${bin_in_archive}" -cd '/' | wc -c)
124-
if [[ "${components}" != "0" ]]; then
125-
tar_args+=(--strip-components "${components}")
126-
fi
127-
tar "${tar_args[@]}" -C "${bin_dir}" "${bin_in_archive}"
130+
tar "${tar_args[@]}"
131+
for tmp in "${bin_in_archive[@]}"; do
132+
mv "${tmp}" "${bin_dir}/"
133+
done
128134
else
129135
case "${url}" in
130136
*.zip)
131137
unzip -q tmp "${bin_in_archive#\./}"
132-
mv "${bin_in_archive}" "${bin_dir}/"
138+
for tmp in "${bin_in_archive[@]}"; do
139+
mv "${tmp}" "${bin_dir}/"
140+
done
141+
;;
142+
*)
143+
for tmp in "${installed_bin[@]}"; do
144+
mv tmp "${tmp}"
145+
done
133146
;;
134-
*) mv tmp "${installed_bin}" ;;
135147
esac
136148
fi
137149
)
138150
rm -rf "${tmp_dir}"
139151

140152
case "${host_os}" in
141153
linux | macos)
142-
if [[ ! -x "${installed_bin}" ]]; then
143-
chmod +x "${installed_bin}"
144-
fi
154+
for tmp in "${installed_bin[@]}"; do
155+
if [[ ! -x "${tmp}" ]]; then
156+
chmod +x "${tmp}"
157+
fi
158+
done
145159
;;
146160
esac
147161
}
@@ -198,15 +212,31 @@ read_download_info() {
198212
fi
199213
checksum=$(call_jq <<<"${download_info}" -r '.checksum')
200214
url=$(call_jq <<<"${download_info}" -r '.url')
215+
local tmp
216+
bin_in_archive=()
201217
if [[ "${url}" == "null" ]]; then
202218
local template
203219
template=$(call_jq -r ".template.${host_platform}" "${manifest_dir}/${tool}.json")
204220
url=$(call_jq <<<"${template}" -r '.url')
205221
url="${url//\$\{version\}/${exact_version}}"
206-
bin_in_archive=$(call_jq <<<"${template}" -r '.bin')
207-
bin_in_archive="${bin_in_archive//\$\{version\}/${exact_version}}"
222+
tmp=$(call_jq <<<"${template}" -r '.bin' | sed -E "s/\\$\\{version\\}/${exact_version}/g")
223+
if [[ "${tmp}" == *"["* ]]; then
224+
# shellcheck disable=SC2207
225+
bin_in_archive=($(call_jq <<<"${template}" -r '.bin[]' | sed -E "s/\\$\\{version\\}/${exact_version}/g"))
226+
fi
208227
else
209-
bin_in_archive=$(call_jq <<<"${download_info}" -r '.bin')
228+
tmp=$(call_jq <<<"${download_info}" -r '.bin')
229+
if [[ "${tmp}" == *"["* ]]; then
230+
# shellcheck disable=SC2207
231+
bin_in_archive=($(call_jq <<<"${download_info}" -r '.bin[]'))
232+
fi
233+
fi
234+
if [[ ${#bin_in_archive[@]} -eq 0 ]]; then
235+
if [[ "${tmp}" == "null" ]]; then
236+
bin_in_archive=("${tool}${exe}")
237+
else
238+
bin_in_archive=("${tmp}")
239+
fi
210240
fi
211241
if [[ "${rust_crate}" == "null" ]]; then
212242
if [[ "${host_os}" == "windows" ]] || [[ ! -e /usr/local/bin ]]; then
@@ -217,17 +247,14 @@ read_download_info() {
217247
else
218248
bin_dir="${cargo_bin}"
219249
fi
220-
if [[ "${bin_in_archive}" == "null" ]]; then
221-
bin_in_archive="${tool}${exe}"
222-
fi
223250
}
224251
download_from_manifest() {
225252
read_manifest "$@"
226253
download_from_download_info "$@"
227254
}
228255
download_from_download_info() {
229256
read_download_info "$@"
230-
download_and_extract "${url}" "${checksum}" "${bin_dir}" "${bin_in_archive}"
257+
download_and_extract "${url}" "${checksum}" "${bin_dir}" "${bin_in_archive[@]}"
231258
}
232259
install_cargo_binstall() {
233260
local binstall_version
@@ -540,6 +567,7 @@ for tool in "${tools[@]}"; do
540567
else
541568
version="latest"
542569
fi
570+
installed_bin=()
543571
case "${tool}" in
544572
protoc)
545573
info "installing ${tool}@${version}"
@@ -576,6 +604,7 @@ for tool in "${tools[@]}"; do
576604
fi
577605
)
578606
rm -rf "${tmp_dir}"
607+
installed_bin=("${tool}${exe}")
579608
;;
580609
valgrind)
581610
info "installing ${tool}@${version}"
@@ -593,6 +622,7 @@ for tool in "${tools[@]}"; do
593622
# Use snap to install the latest Valgrind
594623
# https://snapcraft.io/install/valgrind/ubuntu
595624
snap_install valgrind --classic
625+
installed_bin=("${tool}${exe}")
596626
;;
597627
cargo-binstall)
598628
case "${version}" in
@@ -651,41 +681,50 @@ for tool in "${tools[@]}"; do
651681
;;
652682
esac
653683

654-
case "${tool}" in
655-
xbuild) tool_bin="x" ;;
656-
*) tool_bin="${tool}" ;;
657-
esac
658-
installed_at=$(type -P "${tool_bin}${exe}" || echo "")
659-
if [[ -n "${installed_at}" ]]; then
660-
tool_bin="${tool_bin}${exe}"
661-
else
684+
tool_bin_stems=()
685+
for tool_bin in "${installed_bin[@]}"; do
686+
tool_bin=$(basename "${tool_bin}")
687+
tool_bin_stem="${tool_bin%.exe}"
662688
installed_at=$(type -P "${tool_bin}" || echo "")
663-
fi
664-
if [[ -n "${installed_at}" ]]; then
665-
info "${tool} installed at ${installed_at}"
666-
else
667-
warn "${tool} should be installed at ${bin_dir:+"${bin_dir}/"}${tool_bin}${exe}; but ${tool_bin}${exe} not found in path"
668-
fi
669-
# cargo-udeps 0.1.30 and wasm-pack 0.12.0 do not support --version option.
670-
case "${tool}" in
671-
biome) rx "${tool_bin}" --version || true ;; # biome up to 1.2.2 exits with 1 on --version and --help
672-
cargo-careful | cargo-machete) ;; # cargo-careful 0.3.4 and cargo-machete 0.5.0 do not support neither --version nor --help option.
673-
cargo-*)
674-
case "${tool}" in
675-
cargo-valgrind) rx "${tool_bin}" "${tool#cargo-}" --help ;; # cargo-valgrind 2.1.0's --version option just calls cargo's --version option
676-
*)
677-
if ! rx "${tool_bin}" "${tool#cargo-}" --version; then
678-
rx "${tool_bin}" "${tool#cargo-}" --help
679-
fi
680-
;;
681-
esac
682-
;;
683-
*)
684-
if ! rx "${tool_bin}" --version; then
685-
rx "${tool_bin}" --help
686-
fi
687-
;;
688-
esac
689+
if [[ -z "${installed_at}" ]]; then
690+
tool_bin="${tool_bin_stem}"
691+
installed_at=$(type -P "${tool_bin}" || echo "")
692+
fi
693+
if [[ -n "${installed_at}" ]]; then
694+
info "${tool_bin_stem} installed at ${installed_at}"
695+
else
696+
warn "${tool_bin_stem} should be installed at ${bin_dir:+"${bin_dir}/"}${tool_bin}${exe}; but ${tool_bin}${exe} not found in path"
697+
fi
698+
tool_bin_stems+=("${tool_bin_stem}")
699+
done
700+
for tool_bin_stem in "${tool_bin_stems[@]}"; do
701+
# cargo-udeps 0.1.30 and wasm-pack 0.12.0 do not support --version flag.
702+
case "${tool_bin_stem}" in
703+
# biome up to 1.2.2 exits with 1 on both --version and --help flags.
704+
# cargo-machete up to 0.6.0 does not support --version flag.
705+
biome | cargo-machete) rx "${tool_bin_stem}" --version || true ;;
706+
# these packages support neither --version nor --help flag.
707+
cargo-careful | wasm-bindgen-test-runner) ;;
708+
# wasm2es6js does not support --version flag and --help flag doesn't contains version info.
709+
wasm2es6js) ;;
710+
cargo-*)
711+
case "${tool_bin_stem}" in
712+
# cargo-valgrind 2.1.0's --version flag just calls cargo's --version flag
713+
cargo-valgrind) rx "${tool_bin_stem}" "${tool_bin_stem#cargo-}" --help ;;
714+
*)
715+
if ! rx "${tool_bin_stem}" "${tool_bin_stem#cargo-}" --version; then
716+
rx "${tool_bin_stem}" "${tool_bin_stem#cargo-}" --help
717+
fi
718+
;;
719+
esac
720+
;;
721+
*)
722+
if ! rx "${tool_bin_stem}" --version; then
723+
rx "${tool_bin_stem}" --help
724+
fi
725+
;;
726+
esac
727+
done
689728
echo
690729
done
691730

manifests/wasm-bindgen.json

+119
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/codegen/base/wasm-bindgen.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"repository": "https://github.com/rustwasm/wasm-bindgen",
3+
"tag_prefix": "",
4+
"rust_crate": "wasm-bindgen-cli",
5+
"version_range": ">= 0.2.88",
6+
"asset_name": "wasm-bindgen-${version}-${rust_target}.tar.gz",
7+
"bin": [
8+
"wasm-bindgen-${version}-${rust_target}/wasm-bindgen-test-runner${exe}",
9+
"wasm-bindgen-${version}-${rust_target}/wasm-bindgen${exe}",
10+
"wasm-bindgen-${version}-${rust_target}/wasm2es6js${exe}"
11+
],
12+
"platform": {
13+
"x86_64_linux_musl": {},
14+
"x86_64_macos": {},
15+
"x86_64_windows": {},
16+
"aarch64_linux_gnu": {},
17+
"aarch64_macos": {}
18+
}
19+
}

0 commit comments

Comments
 (0)