Remove 'wasm-pack' Build Dependency#58618
Conversation
fa3e667 to
f7f427b
Compare
f7f427b to
eff99d8
Compare
fheinecke
left a comment
There was a problem hiding this comment.
LGTM provided this builds
There was a problem hiding this comment.
Should we try to pre-seed the dockerfile with these dependencies so that the make command is a no-op if the correct version is already present?
There was a problem hiding this comment.
Sure. Are you thinking just the wasm-opt dependency, or should we try to guess the right wasm-bindgen-cli version as well? I say "guess" because we can't actually tell at this stage exactly which version we need, but we can hardcode the current version and try to remember to keep it up to date. Any drift will get fixed at build time.
There was a problem hiding this comment.
Why can't we tell what version we need? Couldn't we run make -C .. print-wasm-bindgen-version and pass it in via an ARG?
There was a problem hiding this comment.
I got my wires crossed.
Added install automation for both wasm-opt and wasm-bindgen to the buildbox and node images.
Makefile
Outdated
| CARGO_TARGET_linux_arm64 := aarch64-unknown-linux-gnu | ||
| CARGO_TARGET_linux_386 := i686-unknown-linux-gnu | ||
| CARGO_TARGET_linux_amd64 := x86_64-unknown-linux-gnu | ||
| CARGO_TARGET_wasm := wasm32-unknown-unknown |
There was a problem hiding this comment.
These are meant to be named with OS and ARCH - see how RUST_TARGET_ARCH is defined. You seem to be using this var for different purposes, in which case it should probably be named differently and not be co-located with these vars.
Makefile
Outdated
| print-wasm-bindgen-version: NEED_VERSION = $(WASM_BINDGEN_VERSION) | ||
| print-wasm-bindgen-version: | ||
| @echo $(NEED_VERSION) |
There was a problem hiding this comment.
No need for the NEED_VERSION var here, just print directly:
print-wasm-bindgen-version:
@echo $(WASM_BINDGEN_VERSION)
Makefile
Outdated
| cargo build --package ironrdp --lib --target $(CARGO_TARGET_wasm) --release | ||
| wasm-opt target/$(CARGO_TARGET_wasm)/release/ironrdp.wasm -o target/$(CARGO_TARGET_wasm)/release/ironrdp.wasm -O | ||
| wasm-bindgen target/$(CARGO_TARGET_wasm)/release/ironrdp.wasm --out-dir $(ironrdp)/pkg --typescript --target web | ||
| @echo "*" > $(ironrdp)/pkg/.gitignore |
There was a problem hiding this comment.
Why is this being created in make? Can we just add /web/packages/shared/libs/ironrdp/pkg to the top-level .gitignore (or in web/.gitignore if preferred)?
There was a problem hiding this comment.
wasm-pack would write out this same .gitignore, so I included it here for parity.
But you're right, there's no reason to keep it here.
Makefile
Outdated
| @printf '%s\n' '{' \ | ||
| ' "name": "ironrdp",' \ | ||
| ' "version": "0.1.0",' \ | ||
| ' "module": "ironrdp.js",' \ | ||
| ' "types": "ironrdp.d.ts",' \ | ||
| ' "files": ["ironrdp_bg.wasm","ironrdp.js","ironrdp.d.ts"],' \ | ||
| ' "sideEffects": ["./snippets/*"]' \ | ||
| '}' > $(ironrdp)/pkg/package.json |
There was a problem hiding this comment.
Another way to do this which may be a bit easier to modify later:
define ironrdp_package_json
{
"name": "ironrdp",
"version": "0.1.0",
...
}
endef
export ironrdp_package_json
and in the recipe:
printenv ironrdp_package_json > $(ironrdp)/pkg/package.json
The source material is a little bit easier to edit as it does not need all those single quotes and backslashes, which are easy to get wrong. It's just bare json which is also easier to cut and paste.
There was a problem hiding this comment.
Why can't we tell what version we need? Couldn't we run make -C .. print-wasm-bindgen-version and pass it in via an ARG?
* Replace potentially confusing 'CARGO_TARGET_wasm' variable. * Replace oneoff .gitignore with a corresponding entry in the top level .gitignore. * Replace 'printf' used to create package.json file with a cleaner multiline string. * Remove unnecessary 'NEED_VERSION' * Use awk to find wasm-bindgen version without using 'cargo' since it doesn't seem to be available on ARM64 runners
build.assets/versions.mk
Outdated
| # Run lint-rust check locally before merging code after you bump this. | ||
| RUST_VERSION ?= 1.81.0 | ||
| WASM_OPT_VERSION ?= 0.116.1 | ||
| WASM_BINDGEN_VERSION ?= $(shell $(MAKE) -C .. --no-print-directory print-wasm-bindgen-version) |
There was a problem hiding this comment.
I'm not sure I like this here. Prior to this change, this version file could be used directly in other parts of the build when needed such as https://github.com/gravitational/teleport/blob/master/integrations/operator/Dockerfile.gha#L27 - that won't work now as versions.mk now depends on the top-level makefile and its relative location to it.
I would just lift this out into build.assets/Makefile as that already has those dependencies mentioned.
There was a problem hiding this comment.
I realise now that Dockerfile will still work as it does not reference WASM_BINDGEN_VERSION, so it will never run that command or need that version. Still a little more complicated than the basic "set var to version string" so I think it's still best located in build.assets/Makefile but I'm not so worried about breaking other things now.
Our makefiles are a bit of a mess and could do with some unification, but things like this dynamic versions specified in other files is always going to be a bit hairy.
| WASM_BINDGEN_VERSION = $(shell awk ' \ | ||
| $$1 == "name" && $$3 == "\"wasm-bindgen\"" { in_pkg=1; next } \ | ||
| in_pkg && $$1 == "version" { gsub(/"/, "", $$3); print $$3; exit } \ | ||
| ' Cargo.lock) |
There was a problem hiding this comment.
I'm curious what was wrong with the last version - when I ran it locally it seemed to work (although it did require cargo be to be installed, the redirected error should have made it silent if it was not).
The reason I ask is that the awk that was previously there (similar to this awk) for some reason did not work on the 32-bit intel release (i386 arch) for inexplicable reasons and I still don't know what was wrong. I'm a little worried this will not work too since we never resolved it before and why we had to hard code the version. See the comment below on the ensure-wasm-bindgen target. If you've verified this awk works in the 386 release build, then great.
There was a problem hiding this comment.
I had just assumed there was some issue with it since it was commented out and we were hardcoding 0.2.99. Purely by happenstance, this usage of awk seems to work fine on i386. I've been cutting dev builds to ensure that reviewers only see changes that produce a clean build.
Makefile
Outdated
| .PHONY: ensure-wasm-opt | ||
| ensure-wasm-opt: WASM_OPT_VERSION := $(shell $(MAKE) --no-print-directory -C build.assets print-wasm-opt-version) | ||
| ensure-wasm-opt: | ||
| cargo install wasm-opt@$(WASM_OPT_VERSION) |
There was a problem hiding this comment.
Do we need --force or --locked here?
There was a problem hiding this comment.
Ah yes, I missed the --locked flag here. I don't think we should add --force though since it defeats the purpose of seeding the build images by forcing reinstallation (even when the specified version is already installed).
* Get a Teleport build working without wasm-pack * * seed docker images with wasm-opt, and wasm-bindgen-cli * Replace potentially confusing 'CARGO_TARGET_wasm' variable. * Replace oneoff .gitignore with a corresponding entry in the top level .gitignore. * Replace 'printf' used to create package.json file with a cleaner multiline string. * Remove unnecessary 'NEED_VERSION' * Use awk to find wasm-bindgen version without using 'cargo' since it doesn't seem to be available on ARM64 runners * Move 'WASM_BINDGEN_VERSION' definition out of versions.mk * Pass '--locked' flag to wasm-opt install
* Get a Teleport build working without wasm-pack * * seed docker images with wasm-opt, and wasm-bindgen-cli * Replace potentially confusing 'CARGO_TARGET_wasm' variable. * Replace oneoff .gitignore with a corresponding entry in the top level .gitignore. * Replace 'printf' used to create package.json file with a cleaner multiline string. * Remove unnecessary 'NEED_VERSION' * Use awk to find wasm-bindgen version without using 'cargo' since it doesn't seem to be available on ARM64 runners * Move 'WASM_BINDGEN_VERSION' definition out of versions.mk * Pass '--locked' flag to wasm-opt install
* Get a Teleport build working without wasm-pack * * seed docker images with wasm-opt, and wasm-bindgen-cli * Replace potentially confusing 'CARGO_TARGET_wasm' variable. * Replace oneoff .gitignore with a corresponding entry in the top level .gitignore. * Replace 'printf' used to create package.json file with a cleaner multiline string. * Remove unnecessary 'NEED_VERSION' * Use awk to find wasm-bindgen version without using 'cargo' since it doesn't seem to be available on ARM64 runners * Move 'WASM_BINDGEN_VERSION' definition out of versions.mk * Pass '--locked' flag to wasm-opt install
* Get a Teleport build working without wasm-pack * * seed docker images with wasm-opt, and wasm-bindgen-cli * Replace potentially confusing 'CARGO_TARGET_wasm' variable. * Replace oneoff .gitignore with a corresponding entry in the top level .gitignore. * Replace 'printf' used to create package.json file with a cleaner multiline string. * Remove unnecessary 'NEED_VERSION' * Use awk to find wasm-bindgen version without using 'cargo' since it doesn't seem to be available on ARM64 runners * Move 'WASM_BINDGEN_VERSION' definition out of versions.mk * Pass '--locked' flag to wasm-opt install
* Get a Teleport build working without wasm-pack * * seed docker images with wasm-opt, and wasm-bindgen-cli * Replace potentially confusing 'CARGO_TARGET_wasm' variable. * Replace oneoff .gitignore with a corresponding entry in the top level .gitignore. * Replace 'printf' used to create package.json file with a cleaner multiline string. * Remove unnecessary 'NEED_VERSION' * Use awk to find wasm-bindgen version without using 'cargo' since it doesn't seem to be available on ARM64 runners * Move 'WASM_BINDGEN_VERSION' definition out of versions.mk * Pass '--locked' flag to wasm-opt install
* Get a Teleport build working without wasm-pack * * seed docker images with wasm-opt, and wasm-bindgen-cli * Replace potentially confusing 'CARGO_TARGET_wasm' variable. * Replace oneoff .gitignore with a corresponding entry in the top level .gitignore. * Replace 'printf' used to create package.json file with a cleaner multiline string. * Remove unnecessary 'NEED_VERSION' * Use awk to find wasm-bindgen version without using 'cargo' since it doesn't seem to be available on ARM64 runners * Move 'WASM_BINDGEN_VERSION' definition out of versions.mk * Pass '--locked' flag to wasm-opt install
This PR removes our dependency on wasm-pack, which is holding us back from updating to recent releases of rust. This means that we have to roll our own automation to handle the work that
wasm-packwas doing for us. Namely:wasm32-unknown-unknowntoolchainwasm-bindgen-cliis installed (must match the version ofwasm-bindgenthat the wasm library is compiled against)wasm-optis installed (in some environmentswasm-optalready had to be installed out-of-band)wasm-bindgento generate javascript/typescript bindingspackage.jsonmanifest