Skip to content

Commit f09d381

Browse files
Add Rust Toolchain File (#59335)
* Add rust toolchain file * Determine rust version by checking the top level toolchain file. Remove overrides. * Remove explicit overrides and target installation from workflows. * Remove from macOS build docs any language about installing specific rust toolchains or setting overrides. We're relying on the toolchain file and rustup to quietly install and use the toolchain(s) specified by the toolchain file. * Always re-install wasm-bindgen if the currently installed version is out-of-date * e submodule invokes the 'rustup-set-version' target, but it is not needed now that we have the toolchain file. Leave this target in for now so that we don't break the build. We can clean it up later. * Remove target that install wasm toolchain. It is no longer necessary. * Fix awk expression that extracts rust version from the toolchain file. * Fix comment and remove explicit rust toolchain install from lint workflow * We still need to ensure that rustfmt and clippy are installed on machine that runs rust lint.
1 parent 33bd287 commit f09d381

File tree

7 files changed

+24
-62
lines changed

7 files changed

+24
-62
lines changed

.github/workflows/build-macos.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ jobs:
6262
cache: false
6363
go-version: ${{ env.GOLANG_VERSION }}
6464

65-
- name: Configure Rust Toolchain
66-
run: |
67-
rustup override set ${{ env.RUST_VERSION }}
68-
rustup target add wasm32-unknown-unknown
69-
7065
- name: Install wasm-deps
7166
run: make ensure-wasm-deps
7267

.github/workflows/lint.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ jobs:
186186
- name: Set up Rust
187187
run: |
188188
echo "Setting up Rust version ${RUST_VERSION}"
189-
rustup toolchain install ${RUST_VERSION} --component rustfmt,clippy
190-
rustup override set ${RUST_VERSION}
189+
rustup component add rustfmt clippy
191190
rustc --version
192191
cargo --version
193192
rustfmt --version

BUILD_macos.md

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,15 @@ and updates are welcome!
1717
```
1818

1919
1. Install Rust
20-
1. Install rustup
2120

22-
Install rustup with Homebrew:
21+
Install rustup with Homebrew:
2322

24-
```shell
25-
brew install rustup
26-
27-
rustup-init
28-
# Accept defaults
29-
```
30-
31-
1. Install and configure Rust toolchain
32-
1. Find the required Rust version in
33-
[`build.assets/versions.mk`](/build.assets/versions.mk)
34-
(`RUST_VERSION`).
35-
36-
1. Install the Rust toolchain:
37-
38-
```shell
39-
# Replace <version> with the value of RUST_VERSION from build.assets/versions.mk (e.g., 1.81.0)
40-
rustup toolchain install <version>
41-
```
42-
43-
1. Set the default Rust toolchain globally (applies to all projects):
44-
45-
```shell
46-
# Replace <version> with the value of RUST_VERSION from build.assets/versions.mk (e.g., 1.81.0)
47-
rustup default <version>
48-
```
49-
50-
> **Note:** Using `rustup default <version>` sets the toolchain
51-
> globally for your user. If you only want to override the toolchain
52-
> for a specific project directory, use `rustup override set
53-
> <version>` inside that directory instead.
54-
55-
1. Verify the installed version:
23+
```shell
24+
brew install rustup
5625
57-
```shell
58-
rustc --version
59-
```
26+
rustup-init
27+
# Accept defaults
28+
```
6029

6130
1. Install Node.js
6231
1. Find the required Node version in

Makefile

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,7 @@ ensure-js-deps:
18631863
ifeq ($(WEBASSETS_SKIP_BUILD),1)
18641864
ensure-wasm-deps:
18651865
else
1866-
ensure-wasm-deps: ensure-wasm-bindgen ensure-wasm-opt rustup-install-wasm-toolchain
1866+
ensure-wasm-deps: ensure-wasm-bindgen ensure-wasm-opt
18671867

18681868
WASM_BINDGEN_VERSION = $(shell awk ' \
18691869
$$1 == "name" && $$3 == "\"wasm-bindgen\"" { in_pkg=1; next } \
@@ -1874,21 +1874,20 @@ WASM_BINDGEN_VERSION = $(shell awk ' \
18741874
print-wasm-bindgen-version:
18751875
@echo $(WASM_BINDGEN_VERSION)
18761876

1877+
RUST_TOOLCHAIN_VERSION = $(shell awk '$$1 == "channel" && $$2 == "=" { gsub(/"/, "", $$3); print $$3 }' rust-toolchain.toml )
1878+
1879+
.PHONY: print-rust-toolchain-version
1880+
print-rust-toolchain-version:
1881+
@echo $(RUST_TOOLCHAIN_VERSION)
1882+
18771883
ensure-wasm-bindgen: NEED_VERSION = $(WASM_BINDGEN_VERSION)
18781884
ensure-wasm-bindgen: INSTALLED_VERSION = $(word 2,$(shell wasm-bindgen --version 2>/dev/null))
18791885
ensure-wasm-bindgen:
1880-
ifneq ($(CI)$(FORCE),)
18811886
@: $(or $(NEED_VERSION),$(error Unknown wasm-bindgen version. Is it in Cargo.lock?))
18821887
$(if $(filter-out $(INSTALLED_VERSION),$(NEED_VERSION)),\
18831888
cargo install wasm-bindgen-cli --force --locked --version "$(NEED_VERSION)", \
18841889
@echo wasm-bindgen-cli up-to-date: $(INSTALLED_VERSION) \
18851890
)
1886-
else
1887-
$(if $(filter-out $(INSTALLED_VERSION),$(NEED_VERSION)),\
1888-
@echo "Wrong wasm-bindgen version. Want $(NEED_VERSION) have $(INSTALLED_VERSION)"; \
1889-
echo "Run 'make $@ FORCE=true' to force installation." \
1890-
)
1891-
endif
18921891
endif
18931892

18941893
.PHONY: ensure-wasm-opt
@@ -1908,23 +1907,19 @@ build-ui-e: ensure-js-deps ensure-wasm-deps
19081907
docker-ui:
19091908
$(MAKE) -C build.assets ui
19101909

1910+
# TODO(rhammonds): Remove this target once all references to it have
1911+
# been removed from e submodule and e ref is updated.
19111912
.PHONY: rustup-set-version
1912-
rustup-set-version: RUST_VERSION := $(shell $(MAKE) --no-print-directory -C build.assets print-rust-version)
1913-
rustup-set-version:
1914-
rustup override set $(RUST_VERSION)
1913+
rustup-set-version: ; # obsoleted by toolchain file
19151914

19161915
# rustup-install-target-toolchain ensures the required rust compiler is
19171916
# installed to build for $(ARCH)/$(OS) for the version of rust we use, as
19181917
# defined in build.assets/Makefile. It assumes that `rustup` is already
19191918
# installed for managing the rust toolchain.
19201919
.PHONY: rustup-install-target-toolchain
1921-
rustup-install-target-toolchain: rustup-set-version
1920+
rustup-install-target-toolchain:
19221921
rustup target add $(RUST_TARGET_ARCH)
19231922

1924-
.PHONY: rustup-install-wasm-toolchain
1925-
rustup-install-wasm-toolchain: rustup-set-version
1926-
rustup target add $(CARGO_WASM_TARGET)
1927-
19281923
# changelog generates PR changelog between the provided base tag and the tip of
19291924
# the specified branch.
19301925
#

build.assets/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ REQUIRE_HOST_ARCH = $(if $(filter-out $(ARCH),$(RUNTIME_ARCH)),$(error Cannot cr
6060
# responsible for building webassets.
6161
WASM_BINDGEN_VERSION ?= $(shell $(MAKE) -C .. --no-print-directory print-wasm-bindgen-version)
6262

63+
# Determine which version of rust is required to build rust components.
64+
RUST_VERSION ?= $(shell $(MAKE) -C .. --no-print-directory print-rust-toolchain-version)
65+
6366
# This determines which make target we call in this repo's top level Makefile when
6467
# make release in this Makefile is called. Currently this supports its default value
6568
# (release) and release-unix-preserving-webassets. See the release-arm target for

build.assets/versions.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ GOLANGCI_LINT_VERSION ?= v2.4.0
88
# NOTE: Remember to update engines.node in package.json to match the major version.
99
NODE_VERSION ?= 22.14.0
1010

11-
# Run lint-rust check locally before merging code after you bump this.
12-
RUST_VERSION ?= 1.81.0
1311
WASM_OPT_VERSION ?= 0.116.1
1412
LIBBPF_VERSION ?= 1.2.2
1513
LIBPCSCLITE_VERSION ?= 1.9.9-teleport

rust-toolchain.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "1.81.0"
3+
targets = [ "wasm32-unknown-unknown" ]

0 commit comments

Comments
 (0)