Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
rustup override set ${{ env.RUST_VERSION }}
rustup target add wasm32-unknown-unknown

- name: Install wasm-pack
- name: Install wasm-deps
run: make ensure-wasm-deps

- name: Build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ default.etcd
out
build
!/web/packages/build
/web/packages/shared/libs/ironrdp/pkg/**
*.o
*.a
*.so
Expand Down
18 changes: 0 additions & 18 deletions BUILD_macos.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,6 @@ and updates are welcome!
node --version
```

1. Install `wasm-pack`:
1. Find the required wasm-pack version in
[`build.assets/versions.mk`](/build.assets/versions.mk)
(`WASM_PACK_VERSION`).

1. Install wasm-pack globally:

```shell
# Replace <version> with the value of WASM_PACK_VERSION from build.assets/versions.mk (e.g., 0.12.1)
npm install --global wasm-pack@<version>
```

1. Verify wasm-pack version:

```shell
wasm-pack --version
```

1. Install `libfido2`:

```shell
Expand Down
61 changes: 40 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ CARGO_TARGET_linux_386 := i686-unknown-linux-gnu
CARGO_TARGET_linux_amd64 := x86_64-unknown-linux-gnu

CARGO_TARGET := --target=$(RUST_TARGET_ARCH)
CARGO_WASM_TARGET := wasm32-unknown-unknown

# If set to 1, Windows RDP client is not built.
RDPCLIENT_SKIP_BUILD ?= 0
Expand Down Expand Up @@ -488,6 +489,26 @@ ifeq ("$(with_rdpclient)", "yes")
cargo build -p rdp-client $(if $(FIPS),--features=fips) --release --locked $(CARGO_TARGET)
endif

define ironrdp_package_json
{
"name": "ironrdp",
"version": "0.1.0",
"module": "ironrdp.js",
"types": "ironrdp.d.ts",
"files": ["ironrdp_bg.wasm","ironrdp.js","ironrdp.d.ts"],
"sideEffects": ["./snippets/*"]
}
endef
export ironrdp_package_json

.PHONY: build-ironrdp-wasm
build-ironrdp-wasm: ironrdp = web/packages/shared/libs/ironrdp
build-ironrdp-wasm: ensure-wasm-deps
cargo build --package ironrdp --lib --target $(CARGO_WASM_TARGET) --release
wasm-opt target/$(CARGO_WASM_TARGET)/release/ironrdp.wasm -o target/$(CARGO_WASM_TARGET)/release/ironrdp.wasm -O
wasm-bindgen target/$(CARGO_WASM_TARGET)/release/ironrdp.wasm --out-dir $(ironrdp)/pkg --typescript --target web
printenv ironrdp_package_json > $(ironrdp)/pkg/package.json

# Build libfido2 and dependencies for MacOS. Uses exported C_ARCH variable defined earlier.
.PHONY: build-fido2
build-fido2:
Expand Down Expand Up @@ -539,7 +560,7 @@ endif
rm -f *.zip
rm -f gitref.go
rm -rf build.assets/tooling/bin
# Clean up wasm-pack build artifacts
# Clean up wasm build artifacts
rm -rf web/packages/shared/libs/ironrdp/pkg/

.PHONY: clean-ui
Expand Down Expand Up @@ -1880,29 +1901,18 @@ ensure-js-deps:
ifeq ($(WEBASSETS_SKIP_BUILD),1)
ensure-wasm-deps:
else
ensure-wasm-deps: ensure-wasm-pack ensure-wasm-bindgen

# Get the version of wasm-bindgen from cargo, as that is what wasm-pack is
# going to do when it checks for the right version. The buildboxes do not
# have jq installed (yet), so have a hacky awk version on standby.
CARGO_GET_VERSION_JQ = cargo metadata --locked --format-version=1 | jq -r 'first(.packages[] | select(.name? == "$(1)") | .version)'
CARGO_GET_VERSION_AWK = awk -F '[ ="]+' '/^name = "$(1)"$$/ {inpkg = 1} inpkg && $$1 == "version" {print $$2; exit}' Cargo.lock
ensure-wasm-deps: ensure-wasm-bindgen ensure-wasm-opt rustup-install-wasm-toolchain

BIN_JQ = $(shell which jq 2>/dev/null)
CARGO_GET_VERSION = $(if $(BIN_JQ),$(CARGO_GET_VERSION_JQ),$(CARGO_GET_VERSION_AWK))
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)
Comment on lines +1906 to +1909
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.


ensure-wasm-pack: NEED_VERSION = $(shell $(MAKE) --no-print-directory -s -C build.assets print-wasm-pack-version)
ensure-wasm-pack: INSTALLED_VERSION = $(word 2,$(shell wasm-pack --version 2>/dev/null))
ensure-wasm-pack:
$(if $(filter-out $(INSTALLED_VERSION),$(NEED_VERSION)),\
cargo install wasm-pack --force --locked --version "$(NEED_VERSION)", \
@echo wasm-pack up-to-date: $(INSTALLED_VERSION) \
)
.PHONY: print-wasm-bindgen-version
print-wasm-bindgen-version:
@echo $(WASM_BINDGEN_VERSION)

# TODO: Use CARGO_GET_VERSION_AWK instead of hardcoded version
# On 386 Arch, calling the variable produces a malformed command that fails the build.
#ensure-wasm-bindgen: NEED_VERSION = $(shell $(call CARGO_GET_VERSION,wasm-bindgen))
ensure-wasm-bindgen: NEED_VERSION = 0.2.99
ensure-wasm-bindgen: NEED_VERSION = $(WASM_BINDGEN_VERSION)
ensure-wasm-bindgen: INSTALLED_VERSION = $(word 2,$(shell wasm-bindgen --version 2>/dev/null))
ensure-wasm-bindgen:
ifneq ($(CI)$(FORCE),)
Expand All @@ -1919,6 +1929,11 @@ else
endif
endif

.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 --locked wasm-opt@$(WASM_OPT_VERSION)

.PHONY: build-ui
build-ui: ensure-js-deps ensure-wasm-deps
@[ "${WEBASSETS_SKIP_BUILD}" -eq 1 ] || pnpm build-ui-oss
Expand All @@ -1944,6 +1959,10 @@ rustup-set-version:
rustup-install-target-toolchain: rustup-set-version
rustup target add $(RUST_TARGET_ARCH)

.PHONY: rustup-install-wasm-toolchain
rustup-install-wasm-toolchain: rustup-set-version
rustup target add $(CARGO_WASM_TARGET)

# changelog generates PR changelog between the provided base tag and the tip of
# the specified branch.
#
Expand Down
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,12 @@ versions listed in [`build.assets/versions.mk`](/build.assets/versions.mk):
1. [`Go`](https://golang.org/dl/)
1. [`Rust`](https://www.rust-lang.org/tools/install)
1. [`Node.js`](https://nodejs.org/en/download/)
1. [`wasm-pack`](https://github.com/rustwasm/wasm-pack)
1. [`libfido2`](https://github.com/Yubico/libfido2)
1. [`pkg-config`](https://www.freedesktop.org/wiki/Software/pkg-config/)

For an example of Dev Environment setup on a Mac, see [these
instructions](/BUILD_macos.md).

##### Linux 64-bit ARM Dependencies

1. On Linux aarch64 (64-bit ARM), you may need to manually install
[`binaryen`](https://github.com/WebAssembly/binaryen). Check with `which
wasm-opt`. If not found, install with `apt-get install binaryen`
(Debian-based systems). On other platforms, `wasm-pack` installs it
automatically.

#### Perform a build

>**Important**
Expand Down
9 changes: 4 additions & 5 deletions build.assets/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ RUN apt-get -y update && \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
tee /etc/apt/sources.list.d/hashicorp.list > /dev/null && \
apt-get update && apt-get install terraform -y --no-install-recommends && \
# Manually install the wasm-opt binary from the binaryen package on ARM64.
if [ "$BUILDARCH" = "arm64" ]; then apt-get install -y binaryen; fi && \
pip3 --no-cache-dir install yamllint && \
dpkg-reconfigure locales && \
apt-get -y clean && \
Expand Down Expand Up @@ -228,9 +226,10 @@ RUN curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs | sh -s -- -y --p
rustup target add wasm32-unknown-unknown && \
if [ "$BUILDARCH" = "amd64" ]; then rustup target add aarch64-unknown-linux-gnu i686-unknown-linux-gnu; fi

ARG WASM_PACK_VERSION
# Install wasm-pack for targeting WebAssembly from Rust.
RUN cargo install wasm-pack --locked --version ${WASM_PACK_VERSION}
ARG WASM_OPT_VERSION
ARG WASM_BINDGEN_VERSION
# Install wasm-bindgen-ci and wasm-opt for bulding rust webassembly module.
RUN cargo install --locked wasm-opt@${WASM_OPT_VERSION} wasm-bindgen-cli@${WASM_BINDGEN_VERSION}

# Switch back to root for the remaining instructions and keep it as the default
# user.
Expand Down
5 changes: 0 additions & 5 deletions build.assets/Dockerfile-centos7
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,6 @@ RUN curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs | sh -s -- -y --p
rustc --version && \
rustup target add wasm32-unknown-unknown

# Install wasm-pack for targeting WebAssembly from Rust.
ARG WASM_PACK_VERSION
# scl enable is required to use the newer C compiler installed above. Without it, the build fails.
RUN scl enable ${DEVTOOLSET} "cargo install wasm-pack --locked --version ${WASM_PACK_VERSION}"

# Do a quick switch back to root and copy/setup libfido2 and libpcsclite binaries.
# Do this last to take better advantage of the multi-stage build.
USER root
Expand Down
9 changes: 4 additions & 5 deletions build.assets/Dockerfile-node
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ RUN apt-get -y update && \
# Used during tag builds to build the RPM package of Connect.
rpm \
&& \
# Manually install the wasm-opt binary from the binaryen package on ARM64.
if [ "$BUILDARCH" = "arm64" ]; then apt-get install -y binaryen; fi && \
dpkg-reconfigure locales && \
apt-get -y clean && \
rm -rf /var/lib/apt/lists/*
Expand Down Expand Up @@ -83,6 +81,7 @@ RUN curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs | sh -s -- -y --p
rustup target add wasm32-unknown-unknown && \
if [ "$BUILDARCH" = "amd64" ]; then rustup target add aarch64-unknown-linux-gnu; fi

# Install wasm-pack for targeting WebAssembly from Rust.
ARG WASM_PACK_VERSION
RUN cargo install wasm-pack --locked --version ${WASM_PACK_VERSION}
ARG WASM_OPT_VERSION
ARG WASM_BINDGEN_VERSION
# Install wasm-bindgen-ci and wasm-opt for bulding rust webassembly module.
RUN cargo install --locked wasm-opt@${WASM_OPT_VERSION} wasm-bindgen-cli@${WASM_BINDGEN_VERSION}
27 changes: 19 additions & 8 deletions build.assets/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ endif
# $(ARCH) is the target architecture we want to build for.
REQUIRE_HOST_ARCH = $(if $(filter-out $(ARCH),$(RUNTIME_ARCH)),$(error Cannot cross-compile $@ $(ARCH) on $(RUNTIME_ARCH)))

# Determine which version of wasm-bindgen should be installed on build containers
# responsible for building webassets.
WASM_BINDGEN_VERSION ?= $(shell $(MAKE) -C .. --no-print-directory print-wasm-bindgen-version)

# This determines which make target we call in this repo's top level Makefile when
# make release in this Makefile is called. Currently this supports its default value
# (release) and release-unix-preserving-webassets. See the release-arm target for
Expand Down Expand Up @@ -176,7 +180,8 @@ buildbox:
--build-arg GOLANG_VERSION=$(GOLANG_VERSION) \
--build-arg GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION) \
--build-arg RUST_VERSION=$(RUST_VERSION) \
--build-arg WASM_PACK_VERSION=$(WASM_PACK_VERSION) \
--build-arg WASM_OPT_VERSION=$(WASM_OPT_VERSION) \
--build-arg WASM_BINDGEN_VERSION=$(WASM_BINDGEN_VERSION) \
--build-arg NODE_VERSION=$(NODE_VERSION) \
--build-arg LIBBPF_VERSION=$(LIBBPF_VERSION) \
--build-arg BUF_VERSION=$(BUF_VERSION) \
Expand Down Expand Up @@ -219,7 +224,6 @@ buildbox-centos7:
--build-arg TARGETARCH=$(RUNTIME_ARCH) \
--build-arg GOLANG_VERSION=$(GOLANG_VERSION) \
--build-arg RUST_VERSION=$(RUST_VERSION) \
--build-arg WASM_PACK_VERSION=$(WASM_PACK_VERSION) \
--build-arg DEVTOOLSET=$(DEVTOOLSET) \
--build-arg LIBBPF_VERSION=$(LIBBPF_VERSION) \
--build-arg LIBPCSCLITE_VERSION=$(LIBPCSCLITE_VERSION) \
Expand Down Expand Up @@ -248,7 +252,6 @@ buildbox-centos7-fips:
--build-arg TARGETARCH=$(RUNTIME_ARCH) \
--build-arg GOLANG_VERSION=$(GOLANG_VERSION) \
--build-arg RUST_VERSION=$(RUST_VERSION) \
--build-arg WASM_PACK_VERSION=$(WASM_PACK_VERSION) \
--build-arg DEVTOOLSET=$(DEVTOOLSET) \
--build-arg LIBBPF_VERSION=$(LIBBPF_VERSION) \
--build-arg LIBPCSCLITE_VERSION=$(LIBPCSCLITE_VERSION) \
Expand Down Expand Up @@ -297,7 +300,8 @@ buildbox-node:
--build-arg GID=$(GID) \
--build-arg NODE_VERSION=$(NODE_VERSION) \
--build-arg RUST_VERSION=$(RUST_VERSION) \
--build-arg WASM_PACK_VERSION=$(WASM_PACK_VERSION) \
--build-arg WASM_OPT_VERSION=$(WASM_OPT_VERSION) \
--build-arg WASM_BINDGEN_VERSION=$(WASM_BINDGEN_VERSION) \
--cache-to type=inline \
--cache-from $(BUILDBOX_NODE) \
$(if $(PUSH),--push,--load) \
Expand Down Expand Up @@ -738,11 +742,18 @@ print-rust-version:
@echo $(RUST_VERSION)

#
# Print the wasm-pack version used to build Teleport.
# Print the wasm-opt version used to build Teleport.
#
.PHONY:print-wasm-opt-version
print-wasm-opt-version:
@echo $(WASM_OPT_VERSION)

#
# Print the wasm-bindgen version used to build Teleport.
#
.PHONY:print-wasm-pack-version
print-wasm-pack-version:
@echo $(WASM_PACK_VERSION)
.PHONY:print-wasm-bindgen-version
print-wasm-bindgen-version:
@echo $(WASM_BINDGEN_VERSION)

#
# Print the Node version used to build Teleport Connect.
Expand Down
2 changes: 1 addition & 1 deletion build.assets/versions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ NODE_VERSION ?= 22.14.0

# Run lint-rust check locally before merging code after you bump this.
RUST_VERSION ?= 1.81.0
WASM_PACK_VERSION ?= 0.12.1
WASM_OPT_VERSION ?= 0.116.1
LIBBPF_VERSION ?= 1.2.2
LIBPCSCLITE_VERSION ?= 1.9.9-teleport

Expand Down
23 changes: 7 additions & 16 deletions build.assets/windows/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,15 @@ function Enable-Node {
}
}

function Install-WasmPack {
function Install-WasmDeps {
<#
.SYNOPSIS
Builds and installs wasm-pack and dependent tooling.
Builds and installs wasm-bindgen-cli, wasm-opt, and wasm32-unknown-unknown toolchain.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string] $WasmPackVersion
)
begin {
Write-Host "::group::Installing wasm-pack $WasmPackVersion"
# TODO(camscale): Don't hard-code wasm-binden-cli version
cargo install wasm-bindgen-cli --locked --version 0.2.99
cargo install wasm-pack --locked --version "$WasmPackVersion"
Write-Host "::endgroup::"
}

Write-Host "::group::Installing wasm-bindgen-cli, wasm-opt, and wasm32-unknown-unknown toolchain"
make -C "$TeleportSourceDirectory" ensure-wasm-deps
Write-Host "::endgroup::"
}

function Install-Wintun {
Expand Down Expand Up @@ -349,8 +341,7 @@ function Install-BuildRequirements {
$GoVersion = $(make --no-print-directory -C "$TeleportSourceDirectory/build.assets" print-go-version).TrimStart("go")
Install-Go -GoVersion "$GoVersion" -ToolchainDir "$InstallDirectory"

$WasmPackVersion = $(make --no-print-directory -C "$TeleportSourceDirectory/build.assets" print-wasm-pack-version).Trim()
Install-WasmPack -WasmPackVersion "$WasmPackVersion"
Install-WasmDeps
}
Write-Host $("All build requirements installed in {0:g}" -f $CommandDuration)
}
Expand Down
1 change: 0 additions & 1 deletion devbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"yamllint@latest",
"zlib@latest",
"rustup@latest",
"wasm-pack@latest",
"wasm-bindgen-cli@latest",
"pkg-config@latest",

Expand Down
Loading
Loading