Add a basic rust-toolchain.toml (#176)

* 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.
This commit is contained in:
Greg Pfeil 2024-12-16 02:47:41 -07:00 committed by GitHub
parent a429b3f8d3
commit 7bcfb7729b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 50 deletions

View File

@ -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

View File

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

4
rust-toolchain.toml Normal file
View File

@ -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"