Skip to content

Remove 'wasm-pack' Build Dependency#58618

Merged
rhammonds-teleport merged 5 commits intomasterfrom
rhammonds/remove-webpack
Sep 16, 2025
Merged

Remove 'wasm-pack' Build Dependency#58618
rhammonds-teleport merged 5 commits intomasterfrom
rhammonds/remove-webpack

Conversation

@rhammonds-teleport
Copy link
Copy Markdown
Contributor

@rhammonds-teleport rhammonds-teleport commented Sep 2, 2025

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-pack was doing for us. Namely:

  1. Installing the wasm32-unknown-unknown toolchain
  2. Ensuring the correct version of wasm-bindgen-cli is installed (must match the version of wasm-bindgen that the wasm library is compiled against)
  3. Ensuring that wasm-opt is installed (in some environments wasm-opt already had to be installed out-of-band)
  4. Building our wasm library
  5. Optimizing the wasm build artifact for size
  6. Executing wasm-bindgen to generate javascript/typescript bindings
  7. Creating a package.json manifest

@rhammonds-teleport rhammonds-teleport force-pushed the rhammonds/remove-webpack branch 4 times, most recently from fa3e667 to f7f427b Compare September 4, 2025 17:21
Copy link
Copy Markdown
Contributor

@fheinecke fheinecke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM provided this builds

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Comment on lines +1906 to +1908
print-wasm-bindgen-version: NEED_VERSION = $(WASM_BINDGEN_VERSION)
print-wasm-bindgen-version:
@echo $(NEED_VERSION)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Comment on lines +499 to +506
@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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@rhammonds-teleport rhammonds-teleport added the no-changelog Indicates that a PR does not require a changelog entry label Sep 10, 2025
# 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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1906 to +1909
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need --force or --locked here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@public-teleport-github-review-bot public-teleport-github-review-bot bot removed the request for review from ravicious September 12, 2025 22:22
@rhammonds-teleport rhammonds-teleport added this pull request to the merge queue Sep 16, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 16, 2025
@rhammonds-teleport rhammonds-teleport added this pull request to the merge queue Sep 16, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 16, 2025
@rhammonds-teleport rhammonds-teleport added this pull request to the merge queue Sep 16, 2025
Merged via the queue into master with commit 09f6f6c Sep 16, 2025
44 checks passed
@rhammonds-teleport rhammonds-teleport deleted the rhammonds/remove-webpack branch September 16, 2025 17:21
@rosstimothy rosstimothy mentioned this pull request Sep 17, 2025
rhammonds-teleport added a commit that referenced this pull request Dec 11, 2025
* 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
rhammonds-teleport added a commit that referenced this pull request Dec 11, 2025
* 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
rhammonds-teleport added a commit that referenced this pull request Dec 11, 2025
* 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
github-merge-queue bot pushed a commit that referenced this pull request Dec 11, 2025
* 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
rhammonds-teleport added a commit that referenced this pull request Dec 12, 2025
* 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
github-merge-queue bot pushed a commit that referenced this pull request Dec 15, 2025
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog Indicates that a PR does not require a changelog entry size/sm ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants