From 7bcfb7729b13db4afdb6c2c81bbfa8aa731f029c Mon Sep 17 00:00:00 2001 From: Greg Pfeil Date: Mon, 16 Dec 2024 02:47:41 -0700 Subject: [PATCH] Add a basic rust-toolchain.toml (#176) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add a basic rust-toolchain.toml Matches the one in Zebra, although I think pinning to a specific release (e.g., `channel = "1.82"`) would help with consistency, perhaps avoiding issues like https://github.com/ZcashFoundation/zcash_script/pull/174#issuecomment-2445336306 * Remove redundant toolchain info from GH workflow [actions-rs/toolchain doesn’t support TOML-formatted rust-toolchain files](actions-rs/toolchain#126), but it’s unnecessary anyway. - actions-rs/cargo will pick up the rust-toolchain.toml, so we usually don’t need to mention the toolchain at all; - the Windows build just runs `rustup target add x86_64-pc-windows-msvc` directly; and - where we want to build with multiple toolchains (in a matrix), there are some slightly-awkward conditionals. This also makes some other changes: - `fail-fast` is disabled because it hides useful & distinct build results; and - `rustup component add` for clippy and rustfmt are removed because they’re in the rust-toolchain.toml toolchain, and we want to make sure they are, so that they’re available to developers. * Pin rustup channel to "1.81" Newer versions until 1.85 (current nightly) have some breakage wrt C++ linking. * Have bindgen target correct rustc version It should match the version in rust-toolchain.toml. Unfortunately, it’s not possible to reference that directly, so this adds comments to remind contributors to update them together. --- .github/workflows/ci.yml | 74 +++++++++++++--------------------------- build.rs | 7 ++++ rust-toolchain.toml | 4 +++ 3 files changed, 35 insertions(+), 50 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21fa75f6b..340c50ca3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,18 +10,10 @@ jobs: check: name: Check runs-on: ubuntu-latest - strategy: - matrix: - rust: - - stable steps: - uses: actions/checkout@v4 with: submodules: true - - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust }} - override: true - uses: actions-rs/cargo@v1 with: command: check @@ -32,46 +24,57 @@ jobs: name: Package runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - rust: - - stable + toolchain: + - rust-toolchain.toml - nightly steps: - uses: actions/checkout@v4 with: submodules: true - - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust }} - override: true - uses: actions-rs/cargo@v1 + if: matrix.toolchain == 'rust-toolchain.toml' with: command: package + - run: rustup install ${{ matrix.toolchain }} + if: matrix.toolchain != 'rust-toolchain.toml' + - uses: actions-rs/cargo@v1 + if: matrix.toolchain != 'rust-toolchain.toml' + with: + command: package + toolchain: ${{ matrix.toolchain }} test-versions: name: Test Suite runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - rust: - - stable + toolchain: + - rust-toolchain.toml - nightly steps: - uses: actions/checkout@v4 with: submodules: true - - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust }} - override: true - uses: actions-rs/cargo@v1 + if: matrix.toolchain == 'rust-toolchain.toml' with: command: test + - run: rustup install ${{ matrix.toolchain }} + if: matrix.toolchain != 'rust-toolchain.toml' + - uses: actions-rs/cargo@v1 + if: matrix.toolchain != 'rust-toolchain.toml' + with: + command: test + toolchain: ${{ matrix.toolchain }} test-os: name: Test Suite runs-on: ${{ matrix.os }} strategy: + fail-fast: false matrix: # "windows-latest" was removed; see https://github.com/ZcashFoundation/zcash_script/issues/38 os: [ubuntu-latest, macOS-latest, windows-latest] @@ -85,19 +88,8 @@ jobs: # - name: install LLVM on Mac # if: matrix.os == 'macOS-latest' # run: brew install llvm - - uses: actions-rs/toolchain@v1 + - run: rustup target add x86_64-pc-windows-msvc if: matrix.os == 'windows-latest' - with: - target: x86_64-pc-windows-msvc - toolchain: stable - profile: minimal - override: true - - uses: actions-rs/toolchain@v1 - if: matrix.os != 'windows-latest' - with: - toolchain: stable - profile: minimal - override: true - uses: actions-rs/cargo@v1 if: matrix.os == 'windows-latest' with: @@ -111,19 +103,10 @@ jobs: fmt: name: Rustfmt runs-on: ubuntu-latest - strategy: - matrix: - rust: - - stable steps: - uses: actions/checkout@v4 with: submodules: true - - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust }} - override: true - - run: rustup component add rustfmt - uses: actions-rs/cargo@v1 with: command: fmt @@ -132,19 +115,10 @@ jobs: clippy: name: Clippy runs-on: ubuntu-latest - strategy: - matrix: - rust: - - stable steps: - uses: actions/checkout@v4 with: submodules: true - - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust }} - override: true - - run: rustup component add clippy - uses: actions-rs/cargo@v1 with: command: clippy diff --git a/build.rs b/build.rs index a088526ba..91f4dfab3 100644 --- a/build.rs +++ b/build.rs @@ -23,6 +23,10 @@ impl fmt::Display for Error { impl std::error::Error for Error {} +// `bindgen::RustTarget::Stable_*` is deprecated in bindgen >= 0.71.0, but we are constrained +// downstream by the version supported by librocksdb-sys. However, one of our CI jobs still manages +// to pull a newer version, so this silences the deprecation on that job. +#[allow(deprecated)] fn bindgen_headers() -> Result<()> { println!("cargo:rerun-if-changed=depend/zcash/src/script/zcash_script.h"); @@ -31,6 +35,9 @@ fn bindgen_headers() -> Result<()> { // Tell cargo to invalidate the built crate whenever any of the // included header files changed. .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) + // This should not reference a version newer than rust-toolchain.toml. See + // rust-lang/rust-bindgen#3049 for a potential future solution. + .rust_target(bindgen::RustTarget::Stable_1_73) // Finish the builder and generate the bindings. .generate() .map_err(|_| Error::GenerateBindings)?; diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 000000000..ad6842d18 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +# TODO: C++ linking on Linux broke in 1.82, but is fixed again in 1.85. This can be bumped once that +# is released. +channel = "1.81"