Skip to content

Commit

Permalink
Use a Rust toolchain file
Browse files Browse the repository at this point in the history
This ensures that rustup will automatically use the toolchain version
specified in the repo, which will eliminate cases where devs encounter
errors after we bump the Rust version.
  • Loading branch information
zmb3 committed Dec 24, 2024
1 parent d71268f commit b181ade
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 85 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/build-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ jobs:
run: |
echo NODE_VERSION=$(make -s -C build.assets print-node-version) >> $GITHUB_ENV
echo GOLANG_VERSION=$(make -s -C build.assets print-go-version | sed 's/^go//') >> $GITHUB_ENV
echo RUST_VERSION=$(make -s -C build.assets print-rust-version) >> $GITHUB_ENV
echo WASM_PACK_VERSION=$(make -s -C build.assets print-wasm-pack-version) >> $GITHUB_ENV
echo PKG_CONFIG_PATH="$(build.assets/build-fido2-macos.sh pkg_config_path)" >> $GITHUB_ENV
Expand All @@ -46,7 +45,6 @@ jobs:
echo "make: $(make --version)"
echo "node: ${NODE_VERSION}"
echo "go: ${GOLANG_VERSION}"
echo "rust: ${RUST_VERSION}"
echo "wasm-pack: ${WASM_PACK_VERSION}"
- name: Install Node Toolchain
Expand All @@ -64,10 +62,6 @@ jobs:
cache: false
go-version: ${{ env.GOLANG_VERSION }}

- name: Configure Rust Toolchain
run: |
rustup override set ${{ env.RUST_VERSION }}
- name: Install wasm-pack
run: |
cargo install wasm-pack --locked --version ${WASM_PACK_VERSION}
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Set Rust version
run: echo "RUST_VERSION=$(make -s -C build.assets print-rust-version)" >> $GITHUB_ENV

- name: Set up Rust
run: |
echo "Setting up Rust version ${RUST_VERSION}"
rustup toolchain install ${RUST_VERSION} --component rustfmt,clippy
rustup override set ${RUST_VERSION}
rustc --version
cargo --version
rustfmt --version
Expand Down
17 changes: 2 additions & 15 deletions BUILD_macos.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ PRs with corrections and updates are welcome!
brew install go
````

* `Rust` and `Cargo` version from
[build.assets/Makefile](https://github.com/gravitational/teleport/blob/master/build.assets/versions.mk#L11)
(search for RUST_VERSION):

* `Rust` and `Cargo`
* Follow [official instructions](https://www.rust-lang.org/tools/install) to install `rustup`
* Or install with homebrew:

Expand All @@ -55,16 +52,6 @@ PRs with corrections and updates are welcome!
# or open a new shell
```

* Install the required version

```shell
rustup toolchain install <version from build.assets/versions.mk>
cd <teleport.git>
rustup override set <version from build.assets/versions.mk>
rustc --version
# rustc <version from build.assets/versions.mk>
```

* To install `libfido2` (pulls `openssl 3` as dependency)

```shell
Expand All @@ -80,7 +67,7 @@ PRs with corrections and updates are welcome!
* To install tools for building the UI:
* `brew install node corepack`
* `corepack enable pnpm`
* The `Rust` and `Cargo` version in [build.assets/Makefile](https://github.com/gravitational/teleport/blob/master/build.assets/versions.mk#L11) (search for `RUST_VERSION`) are required.
* `Rust` and `Cargo` are required
* The [`wasm-pack`](https://github.com/rustwasm/wasm-pack) version in [build.assets/Makefile](https://github.com/gravitational/teleport/blob/master/build.assets/versions.mk#L12) (search for `WASM_PACK_VERSION`) is required:
`curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh`

Expand Down
9 changes: 2 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1789,17 +1789,12 @@ build-ui-e: ensure-js-deps
docker-ui:
$(MAKE) -C build.assets ui

.PHONY: rustup-set-version
rustup-set-version: RUST_VERSION := $(shell $(MAKE) --no-print-directory -C build.assets print-rust-version)
rustup-set-version:
rustup override set $(RUST_VERSION)

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

# changelog generates PR changelog between the provided base tag and the tip of
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,17 @@ make -C build.assets build-binaries
Ensure you have installed correct versions of necessary dependencies:
* `Go` version from
[go.mod](https://github.com/gravitational/teleport/blob/master/go.mod#L3)
* If you wish to build the Rust-powered features like Desktop Access, see the
`Rust` and `Cargo` versions in
[build.assets/Makefile](https://github.com/gravitational/teleport/blob/master/build.assets/Makefile#L21)
(search for `RUST_VERSION`)
* Rust and Cargo should be installed via [rustup](https://rustup.rs/)
* For `tsh` version > `10.x` with FIDO2 support, you will need `libfido2` and
`pkg-config` installed locally
* To build the web UI:
* [`pnpm`](https://pnpm.io/installation#using-corepack). If you have Node.js installed, run `corepack enable pnpm` to make `pnpm` available.
* If you prefer not to install/use pnpm, but have docker available, you can run `make docker-ui` instead.
* The `Rust` and `Cargo` version in [build.assets/Makefile](https://github.com/gravitational/teleport/blob/master/build.assets/versions.mk#L11) (search for `RUST_VERSION`) are required.
* The [`wasm-pack`](https://github.com/rustwasm/wasm-pack) version in [build.assets/Makefile](https://github.com/gravitational/teleport/blob/master/build.assets/versions.mk#L12) (search for `WASM_PACK_VERSION`) is required.
* [`binaryen`](https://github.com/WebAssembly/binaryen) (which contains `wasm-opt`) is required to be installed manually
on linux aarch64 (64-bit ARM). You can check if it's already installed on your system by running `which wasm-opt`. If not you can install it like `apt-get install binaryen` (for Debian-based Linux). `wasm-pack` will install this automatically on other platforms.

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

#### Perform a build

Expand Down
9 changes: 3 additions & 6 deletions build.assets/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,20 @@ RUN groupadd ci --gid=$GID -o && \
mkdir -p -m0700 /var/lib/teleport && chown -R ci /var/lib/teleport

# Install Rust.
ARG RUST_VERSION
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=$RUST_VERSION
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH
RUN mkdir -p $RUSTUP_HOME && chmod a+w $RUSTUP_HOME && \
mkdir -p $CARGO_HOME/registry && chmod -R a+w $CARGO_HOME
# Install Rust using the ci user, as that is the user that
# will run builds using the Rust toolchains we install here.
# Cross-compilation targets are only installed on amd64, as
# this image doesn't contain gcc-multilib.
USER ci
RUN curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain $RUST_VERSION && \
RUN curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal && \
rustup --version && \
cargo --version && \
rustc --version && \
rustup component add rustfmt clippy && \
rustup target add wasm32-unknown-unknown && \
if [ "$BUILDARCH" = "amd64" ]; then rustup target add aarch64-unknown-linux-gnu i686-unknown-linux-gnu; fi

Expand Down
6 changes: 2 additions & 4 deletions build.assets/Dockerfile-arm
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,15 @@ RUN groupadd ci --gid="$GID" -o && \
chown -R ci /var/lib/teleport

# Install Rust.
ARG RUST_VERSION
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=$RUST_VERSION
PATH=/usr/local/cargo/bin:$PATH
RUN mkdir -p $RUSTUP_HOME && chmod a+w $RUSTUP_HOME && \
mkdir -p $CARGO_HOME/registry && chmod -R a+w $CARGO_HOME
# Install Rust using the ci user, as that is the user that
# will run builds using the Rust toolchains we install here.
USER ci
RUN curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain $RUST_VERSION && \
RUN curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal && \
rustup target add arm-unknown-linux-gnueabihf && \
rustup --version && \
cargo --version && \
Expand Down
6 changes: 2 additions & 4 deletions build.assets/Dockerfile-centos7
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,9 @@ COPY pam/ /opt/pam_teleport/
RUN make -C /opt/pam_teleport install

# Install Rust.
ARG RUST_VERSION
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=$RUST_VERSION
PATH=/usr/local/cargo/bin:$PATH

RUN mkdir -p $RUSTUP_HOME && chmod a+w $RUSTUP_HOME && \
mkdir -p $CARGO_HOME/registry && chmod -R a+w $CARGO_HOME
Expand All @@ -273,7 +271,7 @@ RUN chmod a-w /
# Install Rust using the ci user, as that is the user that
# will run builds using the Rust toolchains we install here.
USER ci
RUN curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain $RUST_VERSION && \
RUN curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal && \
rustup --version && \
cargo --version && \
rustc --version && \
Expand Down
6 changes: 2 additions & 4 deletions build.assets/Dockerfile-node
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,14 @@ RUN groupadd ci --gid=$GID -o && \
useradd ci --uid=$UID --gid=$GID --create-home --shell=/bin/sh

# Install Rust.
ARG RUST_VERSION
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=$RUST_VERSION
PATH=/usr/local/cargo/bin:$PATH
RUN mkdir -p $RUSTUP_HOME && chmod a+w $RUSTUP_HOME && \
mkdir -p $CARGO_HOME/registry && chmod -R a+w $CARGO_HOME

USER ci
RUN curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain $RUST_VERSION && \
RUN curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal && \
rustup --version && \
cargo --version && \
rustc --version && \
Expand Down
13 changes: 0 additions & 13 deletions build.assets/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ buildbox-ng:
docker buildx build \
--build-arg THIRDPARTY_IMAGE=$(BUILDBOX_THIRDPARTY) \
--build-arg GOLANG_VERSION=$(GOLANG_VERSION) \
--build-arg RUST_VERSION=$(RUST_VERSION) \
--cache-from $(BUILDBOX_NG) \
--cache-to type=inline \
$(if $(PUSH),--push,--load) \
Expand All @@ -167,7 +166,6 @@ buildbox:
--build-arg BUILDARCH=$(RUNTIME_ARCH) \
--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 NODE_VERSION=$(NODE_VERSION) \
--build-arg LIBBPF_VERSION=$(LIBBPF_VERSION) \
Expand Down Expand Up @@ -208,7 +206,6 @@ buildbox-centos7:
--build-arg BUILDARCH=$(HOST_ARCH) \
--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) \
Expand All @@ -235,7 +232,6 @@ buildbox-centos7-fips:
--build-arg BUILDARCH=$(HOST_ARCH) \
--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) \
Expand All @@ -258,7 +254,6 @@ buildbox-arm:
--build-arg BUILDARCH=$(RUNTIME_ARCH) \
--build-arg GOLANG_VERSION=$(GOLANG_VERSION) \
--build-arg NODE_VERSION=$(NODE_VERSION) \
--build-arg RUST_VERSION=$(RUST_VERSION) \
--cache-to type=inline \
--cache-from $(BUILDBOX_ARM) \
$(if $(PUSH),--push,--load) \
Expand All @@ -280,7 +275,6 @@ buildbox-node:
--build-arg UID=$(UID) \
--build-arg GID=$(GID) \
--build-arg NODE_VERSION=$(NODE_VERSION) \
--build-arg RUST_VERSION=$(RUST_VERSION) \
--build-arg WASM_PACK_VERSION=$(WASM_PACK_VERSION) \
--cache-to type=inline \
--cache-from $(BUILDBOX_NODE) \
Expand Down Expand Up @@ -701,13 +695,6 @@ print-golangci-lint-version:
print-buf-version:
@echo $(BUF_VERSION)

#
# Print the Rust version used to build Teleport.
#
.PHONY:print-rust-version
print-rust-version:
@echo $(RUST_VERSION)

#
# Print the wasm-pack version used to build Teleport.
#
Expand Down
3 changes: 1 addition & 2 deletions build.assets/buildbox/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ FROM base AS rust
RUN install -d -m 0775 -o buildbox -g buildbox /opt/rust
USER buildbox

ARG RUST_VERSION
ENV RUSTUP_HOME=/opt/rust
ENV CARGO_HOME=/opt/rust
RUN curl --proto =https --tlsv1.2 -fsSL https://sh.rustup.rs | \
sh -s -- -y --profile minimal --default-toolchain ${RUST_VERSION} && \
sh -s -- -y --profile minimal && \
${CARGO_HOME}/bin/rustup --version && \
${CARGO_HOME}/bin/cargo --version && \
${CARGO_HOME}/bin/rustc --version && \
Expand Down
2 changes: 0 additions & 2 deletions build.assets/versions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ GOLANGCI_LINT_VERSION ?= v1.62.2

NODE_VERSION ?= 20.18.0

# Run lint-rust check locally before merging code after you bump this.
RUST_VERSION ?= 1.81.0
WASM_PACK_VERSION ?= 0.12.1
LIBBPF_VERSION ?= 1.2.2
LIBPCSCLITE_VERSION ?= 1.9.9-teleport
Expand Down
9 changes: 3 additions & 6 deletions build.assets/windows/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ function Install-Rust {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string] $ToolchainDir,
[Parameter(Mandatory)]
[string] $RustVersion
[string] $ToolchainDir
)
begin {
Write-Host "::group::Installing Rust $RustVersion to $ToolchainDir..."
Expand All @@ -101,7 +99,7 @@ function Install-Rust {
Invoke-WebRequest -Uri https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-gnu/rustup-init.exe -OutFile $RustupFile
$Env:RUSTUP_HOME = "$ToolchainDir/rustup"
$Env:CARGO_HOME = "$ToolchainDir/cargo"
& "$ToolchainDir\rustup-init.exe" --profile minimal -y --default-toolchain "$RustVersion-x86_64-pc-windows-gnu"
& "$ToolchainDir\rustup-init.exe" --profile minimal -y --target x86_64-pc-windows-gnu
Enable-Rust -ToolchainDir $ToolchainDir
Write-Host "::endgroup::"
}
Expand Down Expand Up @@ -259,8 +257,7 @@ function Install-BuildRequirements {
$CommandDuration = Measure-Block {
New-Item -Path "$InstallDirectory" -ItemType Directory -Force | Out-Null

$RustVersion = $(make --no-print-directory -C "$TeleportSourceDirectory/build.assets" print-rust-version).Trim()
Install-Rust -RustVersion "$RustVersion" -ToolchainDir "$InstallDirectory"
Install-Rust -ToolchainDir "$InstallDirectory"

$NodeVersion = $(make --no-print-directory -C "$TeleportSourceDirectory/build.assets" print-node-version).Trim()
Install-Node -NodeVersion "$NodeVersion" -ToolchainDir "$InstallDirectory"
Expand Down
2 changes: 1 addition & 1 deletion e
Submodule e updated from 1ac55f to 33509b
5 changes: 5 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[toolchain]
channel = "1.81.0"
profile = "minimal"
components = [ "rustfmt", "clippy" ]

6 changes: 3 additions & 3 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can make production builds locally, or you can use Docker to do that.

### Local Build

Install Node.js (you can take the version by executing
Install Node.js (you can take the version by executing
`make -C build.assets print-node-version` from the root directory).
After that, run `corepack enable pnpm` to enable installing a package manager.

Expand All @@ -27,7 +27,7 @@ pnpm install
```

You will also need the following tools installed:
* The `Rust` and `Cargo` version in [build.assets/Makefile](https://github.com/gravitational/teleport/blob/master/build.assets/versions.mk#L11) (search for `RUST_VERSION`) are required.
* `Rust` and `Cargo` should be installed via [rustup](https://rustup.rs/)
* The [`wasm-pack`](https://github.com/rustwasm/wasm-pack) version in [build.assets/Makefile](https://github.com/gravitational/teleport/blob/master/build.assets/versions.mk#L12) (search for `WASM_PACK_VERSION`) is required:
`curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh`
* [`binaryen`](https://github.com/WebAssembly/binaryen) (which contains `wasm-opt`) is required to be installed manually
Expand Down Expand Up @@ -296,7 +296,7 @@ not own.
We use [pnpm workspaces](https://pnpm.io/workspaces) to manage dependencies.

To add a package to the workspace, run `pnpm --filter=<workspace-name> add <package-name>`.
Alternatively, you can add a line to the workspace's `package.json` file and then
Alternatively, you can add a line to the workspace's `package.json` file and then
run `pnpm install` (or `pnpm i`) from the root of this repository.

Dependencies should generally be added to the specific workspaces that use them.
Expand Down

0 comments on commit b181ade

Please sign in to comment.