From 987cd7d6d551bd5e29a6b5efce45704c39722acd Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sat, 19 Aug 2023 16:01:13 +0200 Subject: [PATCH] Replace bors with Github native merge queue --- .github/workflows/ci.yml | 117 +++++++++++++++++++++ .github/workflows/docs.yml | 25 ----- .github/workflows/gh-pages.yml | 7 +- .github/workflows/rust.yml | 96 ----------------- .github/workflows/rust_bors.yml | 97 ----------------- bors.toml | 12 --- docs/book/src/usage/setting-lint-levels.md | 4 +- marker_adapter/src/context.rs | 68 ++++++------ marker_adapter/src/lib.rs | 1 - marker_api/src/context.rs | 3 + rust-toolchain | 4 - rust-toolchain.toml | 12 +++ scripts/download/cargo-machete.sh | 2 + scripts/download/lib.sh | 21 ++++ scripts/download/mdbook.sh | 8 +- scripts/download/taplo.sh | 7 +- scripts/download/typos.sh | 6 ++ 17 files changed, 207 insertions(+), 283 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/docs.yml delete mode 100644 .github/workflows/rust.yml delete mode 100644 .github/workflows/rust_bors.yml delete mode 100644 bors.toml delete mode 100644 rust-toolchain create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..33f351b1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,117 @@ +name: ci + +on: + # Makes it possible to trigger via the GitHub UI (Actions tab) + workflow_dispatch: + merge_group: + pull_request: + push: + branches: + - master + +defaults: + run: + shell: bash + +env: + RUST_BACKTRACE: 1 + CARGO_INCREMENTAL: 0 + CARGO_TERM_COLOR: always + RUSTDOCFLAGS: --deny warnings + RUSTFLAGS: --deny warnings + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + rust-test: + runs-on: ${{ matrix.os }}-latest + + strategy: + matrix: + os: [ubuntu, windows, macos] + + steps: + - uses: actions/checkout@v3 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + + - run: cargo test --locked + + rust-lint: + runs-on: ${{ matrix.os }}-latest + + strategy: + matrix: + os: [ubuntu, windows, macos] + + steps: + - uses: actions/checkout@v3 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + + - run: cargo clippy + - run: cargo doc --no-deps + + rust-formatting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + # We don't need any cache here, so use dtolnay action directly + - uses: dtolnay/rust-toolchain@stable + - run: cargo fmt --check + + # This job ensures required packages can be built with a stable toolchain + # except for some special ones that require nightly + rust-check-on-stable: + runs-on: ${{ matrix.os }}-latest + + strategy: + matrix: + os: [ubuntu, windows, macos] + + steps: + - uses: actions/checkout@v3 + - run: rm rust-toolchain.toml + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: stable + + - run: >- + cargo check + --locked + --workspace + --exclude marker_rustc_driver + --exclude marker_lints + + # Check for unused dependencies that uses simple regex search, + # meaning it's ⚡️ blazingly ⚡️ fast + rust-unused-dependencies: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: scripts/download/cargo-machete.sh + - run: cargo-machete + + # Check the formatting of TOML files in the repository + toml: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: scripts/download/taplo.sh + - run: taplo fmt --check + + # Check for typos in the repository based on a static dictionary + typos: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: scripts/download/typos.sh + - run: typos + + # Check that the documentation can be built + mdbook: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: scripts/download/mdbook.sh + - run: mdbook build docs/book diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml deleted file mode 100644 index d24fe295..00000000 --- a/.github/workflows/docs.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Docs - -on: - push: - paths: - - '**.md' - - './docs/**' - pull_request: - paths: - - '**.md' - - './docs/**' - -jobs: - # Build job - mdbook: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - run: ./scripts/download/mdbook.sh - - name: Build the book - run: | - PATH="$PATH:`pwd`" - cd ./docs/book/ - mdbook build - cd ../../ diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 0ba1bfc3..2c4fe8e4 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -36,11 +36,8 @@ jobs: mkdir deploy cp ./docs/index.html ./deploy/index.html - name: Build the book - run: | - PATH="$PATH:`pwd`" - cd ./docs/book/ - mdbook build --dest-dir ../../deploy/book - cd ../../ + run: mdbook build docs/book --dest-dir deploy/book + - name: Upload artifact uses: actions/upload-pages-artifact@v2 with: diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index 4150c3cb..00000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,96 +0,0 @@ -# This file has to be kept in sync with `rust_bors.yml` -name: Rust - -on: - push: - # Don't run tests, when only text files were modified - paths-ignore: - - 'COPYRIGHT' - - 'LICENSE-*' - - '**.md' - - '**.txt' - # Bors magic branches, these are covered by `rust_bors` - branches-ignore: - - '**.tmp' - - 'staging' - - 'trying' - - 'master' - pull_request: - # Don't run tests, when only text files were modified - paths-ignore: - - 'COPYRIGHT' - - 'LICENSE-*' - - '**.md' - - '**.txt' - -env: - RUST_BACKTRACE: 1 - CARGO_TERM_COLOR: always - RUSTDOCFLAGS: "-Dwarnings" - RUSTFLAGS: "-Dwarnings" - -jobs: - rust: - runs-on: ubuntu-latest - - # Setup - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@master - with: - toolchain: nightly-2023-07-13 - components: rustfmt, clippy - - - run: rustc -vV - - # Tests - - run: cargo test - - run: cargo clippy - - run: cargo fmt --check - - run: cargo doc --no-deps - - # This task ensures, required packages can be built with a stable toolchain - # the only package requiring nightly should be `marker_rustc_driver` and - # optionally `marker_adapter` - rust-crates-build-stable: - runs-on: ubuntu-latest - - # Setup - steps: - - uses: actions/checkout@v3 - - run: rm rust-toolchain - - uses: dtolnay/rust-toolchain@stable - - - run: rustc -vV - - # Test - - run: cargo build --package cargo_marker - - run: cargo build --package marker_api - - run: cargo build --package marker_utils - - run: cargo build --package marker_uitest - - run: cargo build --package marker_uilints - - # Check the formatting of TOML files in the repository - toml: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - run: ./scripts/download/taplo.sh - - run: ./taplo fmt --check - - # Check for typos in the repository based on a static dictionary - typos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - run: ./scripts/download/typos.sh - - run: ./typos - - # Check for unused dependencies that uses simple regex search, - # meaning it's ⚡️ blazingly ⚡️ fast - rust-unused-dependencies: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - run: ./scripts/download/cargo-machete.sh - - run: ./cargo-machete diff --git a/.github/workflows/rust_bors.yml b/.github/workflows/rust_bors.yml deleted file mode 100644 index c5a4a93a..00000000 --- a/.github/workflows/rust_bors.yml +++ /dev/null @@ -1,97 +0,0 @@ -# This file has to be kept in sync with `rust.yml` -name: Rust (bors) - -on: - push: - # Bors magic branches - branches: - - 'staging' - - 'trying' - -env: - RUST_BACKTRACE: 1 - CARGO_TERM_COLOR: always - RUSTDOCFLAGS: "-Dwarnings" - RUSTFLAGS: "-Dwarnings" - -jobs: - rust: - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - - runs-on: ${{ matrix.os }} - - # Setup - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@master - with: - toolchain: nightly-2023-07-13 - components: rustfmt, clippy - - - run: rustc -vV - - # Tests - - run: cargo test - - run: cargo clippy - - run: cargo fmt --check - - run: cargo doc --no-deps - - # This task ensures, required packages can be built with a stable toolchain - # the only package requiring nightly should be `marker_rustc_driver` and - # optionally `marker_adapter` - rust-crates-build-stable: - runs-on: ubuntu-latest - - # Setup - steps: - - uses: actions/checkout@v3 - - run: rm rust-toolchain - - uses: dtolnay/rust-toolchain@stable - - - run: rustc -vV - - # Test - - run: cargo build --package cargo_marker - - run: cargo build --package marker_api - - run: cargo build --package marker_utils - - run: cargo build --package marker_uitest - - run: cargo build --package marker_uilints - - # Check the formatting of TOML files in the repository - toml: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - run: ./scripts/download/taplo.sh - - run: ./taplo fmt --check - - # Check for typos in the repository based on a static dictionary - typos: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - run: ./scripts/download/typos.sh - - run: ./typos - - # Check for unused dependencies that uses simple regex search, - # meaning it's ⚡️ blazingly ⚡️ fast - rust-unused-dependencies: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - run: ./scripts/download/cargo-machete.sh - - run: ./cargo-machete - - mdbook: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - run: ./scripts/download/mdbook.sh - - name: Build the book - run: | - PATH="$PATH:`pwd`" - cd ./docs/book/ - mdbook build - cd ../../ diff --git a/bors.toml b/bors.toml deleted file mode 100644 index db38cce7..00000000 --- a/bors.toml +++ /dev/null @@ -1,12 +0,0 @@ -delete_merged_branches = true -status = [ - "rust (ubuntu-latest)", - "rust (windows-latest)", - "rust (macos-latest)", - "rust-crates-build-stable", - "toml", - "typos", - "rust-unused-dependencies", - "mdbook", -] -timeout_sec = 1200 # 20 min diff --git a/docs/book/src/usage/setting-lint-levels.md b/docs/book/src/usage/setting-lint-levels.md index c031e14d..4373f21b 100644 --- a/docs/book/src/usage/setting-lint-levels.md +++ b/docs/book/src/usage/setting-lint-levels.md @@ -19,7 +19,7 @@ lint attributes you might usually use, on marker provided lints, like `#[allow(m ``` #### Nightly Lint Attribute -``` +```rust // Marker lints can be controlled like this #[allow(marker::my_lint)] fn foo() {} @@ -49,7 +49,7 @@ check, like this: `#[cfg_attr(marker = "my_crate", allow(marker::foo))]`. ``` #### Stable Conditional Lint Attribute -``` +```rust // Marker lints can be controlled like this #[cfg_attr(marker, allow(marker::my_lint))] fn foo() {} diff --git a/marker_adapter/src/context.rs b/marker_adapter/src/context.rs index d87ef97d..c9e3be70 100644 --- a/marker_adapter/src/context.rs +++ b/marker_adapter/src/context.rs @@ -1,7 +1,5 @@ -#![allow( - clippy::needless_lifetimes, - reason = "the lifetimes are destroyed by unsafe, but help with readability" -)] +// The lifetimes are destroyed by unsafe, but help with readability +#![allow(clippy::needless_lifetimes)] use marker_api::{ ast::{ @@ -55,57 +53,57 @@ impl<'ast> DriverContextWrapper<'ast> { } } -#[allow(improper_ctypes_definitions, reason = "fp because `EmissionNode` are non-exhaustive")] +// False positive because `EmissionNode` are non-exhaustive +#[allow(improper_ctypes_definitions)] extern "C" fn lint_level_at(data: &(), lint: &'static Lint, node: EmissionNode) -> Level { - let wrapper = unsafe { &*(data as *const ()).cast::() }; - wrapper.driver_cx.lint_level_at(lint, node) + unsafe { as_driver_cx(data) }.lint_level_at(lint, node) } -extern "C" fn emit_diag<'a, 'ast>(data: &(), diag: &Diagnostic<'a, 'ast>) { - let wrapper = unsafe { &*(data as *const ()).cast::() }; - wrapper.driver_cx.emit_diag(diag); +extern "C" fn emit_diag<'a, 'ast>(data: &'ast (), diag: &Diagnostic<'a, 'ast>) { + unsafe { as_driver_cx(data) }.emit_diag(diag); } -#[allow(improper_ctypes_definitions, reason = "fp because `ItemKind` is non-exhaustive")] -extern "C" fn item<'ast>(data: &(), id: ItemId) -> FfiOption> { - let wrapper = unsafe { &*(data as *const ()).cast::() }; - wrapper.driver_cx.item(id).into() +// False positive because `ItemKind` is non-exhaustive +#[allow(improper_ctypes_definitions)] +extern "C" fn item<'ast>(data: &'ast (), id: ItemId) -> FfiOption> { + unsafe { as_driver_cx(data) }.item(id).into() } -extern "C" fn body<'ast>(data: &(), id: BodyId) -> &'ast Body<'ast> { - let wrapper = unsafe { &*(data as *const ()).cast::() }; - wrapper.driver_cx.body(id) +extern "C" fn body<'ast>(data: &'ast (), id: BodyId) -> &'ast Body<'ast> { + unsafe { as_driver_cx(data) }.body(id) } -extern "C" fn resolve_ty_ids<'ast>(data: &(), path: ffi::FfiStr<'_>) -> ffi::FfiSlice<'ast, TyDefId> { - let wrapper = unsafe { &*(data as *const ()).cast::() }; - wrapper.driver_cx.resolve_ty_ids((&path).into()).into() +extern "C" fn resolve_ty_ids<'ast>(data: &'ast (), path: ffi::FfiStr<'_>) -> ffi::FfiSlice<'ast, TyDefId> { + unsafe { as_driver_cx(data) }.resolve_ty_ids((&path).into()).into() } -#[allow(improper_ctypes_definitions, reason = "fp because `TyKind` is non-exhaustive")] -extern "C" fn expr_ty<'ast>(data: &(), expr: ExprId) -> SemTyKind<'ast> { - let wrapper = unsafe { &*(data as *const ()).cast::() }; - wrapper.driver_cx.expr_ty(expr) +// False positive because `SemTyKind` is non-exhaustive +#[allow(improper_ctypes_definitions)] +extern "C" fn expr_ty<'ast>(data: &'ast (), expr: ExprId) -> SemTyKind<'ast> { + unsafe { as_driver_cx(data) }.expr_ty(expr) } -extern "C" fn span<'ast>(data: &(), span_id: SpanId) -> &'ast Span<'ast> { - let wrapper = unsafe { &*(data as *const ()).cast::() }; - wrapper.driver_cx.span(span_id) +extern "C" fn span<'ast>(data: &'ast (), span_id: SpanId) -> &'ast Span<'ast> { + unsafe { as_driver_cx(data) }.span(span_id) } -extern "C" fn span_snippet<'ast>(data: &(), span: &Span<'ast>) -> ffi::FfiOption> { - let wrapper = unsafe { &*(data as *const ()).cast::() }; - wrapper.driver_cx.span_snippet(span).map(Into::into).into() +extern "C" fn span_snippet<'ast>(data: &'ast (), span: &Span<'ast>) -> ffi::FfiOption> { + unsafe { as_driver_cx(data) }.span_snippet(span).map(Into::into).into() } -extern "C" fn symbol_str<'ast>(data: &(), sym: SymbolId) -> ffi::FfiStr<'ast> { - let wrapper = unsafe { &*(data as *const ()).cast::() }; - wrapper.driver_cx.symbol_str(sym).into() +extern "C" fn symbol_str<'ast>(data: &'ast (), sym: SymbolId) -> ffi::FfiStr<'ast> { + unsafe { as_driver_cx(data) }.symbol_str(sym).into() } extern "C" fn resolve_method_target(data: &(), id: ExprId) -> ItemId { - let wrapper = unsafe { &*(data as *const ()).cast::() }; - wrapper.driver_cx.resolve_method_target(id) + unsafe { as_driver_cx(data) }.resolve_method_target(id) +} + +/// # Safety +/// The `data` must be a valid pointer to a [`DriverContextWrapper`] +unsafe fn as_driver_cx<'ast>(data: &'ast ()) -> &'ast dyn DriverContext<'ast> { + let wrapper = &*(data as *const ()).cast::(); + wrapper.driver_cx } pub trait DriverContext<'ast> { diff --git a/marker_adapter/src/lib.rs b/marker_adapter/src/lib.rs index 4ab3793a..dc57d0e9 100644 --- a/marker_adapter/src/lib.rs +++ b/marker_adapter/src/lib.rs @@ -1,5 +1,4 @@ #![doc = include_str!("../README.md")] -#![feature(lint_reasons)] #![warn(clippy::pedantic)] #![warn(clippy::index_refutable_slice)] #![allow(clippy::module_name_repetitions)] diff --git a/marker_api/src/context.rs b/marker_api/src/context.rs index d8eb51a8..1d874419 100644 --- a/marker_api/src/context.rs +++ b/marker_api/src/context.rs @@ -230,6 +230,9 @@ struct DriverCallbacks<'ast> { /// get its own context. pub driver_context: &'ast (), + // FIXME: all of the callbacks here must be marked as `unsafe`, because you + // can't call them in safe Rust passing a &() pointer. This will trigger UB. + // Lint emission and information pub lint_level_at: extern "C" fn(&'ast (), &'static Lint, EmissionNode) -> Level, pub emit_diag: for<'a> extern "C" fn(&'ast (), &'a Diagnostic<'a, 'ast>), diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index e7c27a29..00000000 --- a/rust-toolchain +++ /dev/null @@ -1,4 +0,0 @@ -[toolchain] -channel = "nightly-2023-07-13" -components = ["cargo", "clippy", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"] -# This has to be synced with the toolchain in `github/workflows` diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000..f3452757 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,12 @@ +[toolchain] +channel = "nightly-2023-07-13" +components = [ + "cargo", + "clippy", + "llvm-tools", + "rust-src", + "rust-std", + "rustc", + "rustc-dev", + "rustfmt", +] diff --git a/scripts/download/cargo-machete.sh b/scripts/download/cargo-machete.sh index c5ec731d..ff8a5a6c 100755 --- a/scripts/download/cargo-machete.sh +++ b/scripts/download/cargo-machete.sh @@ -15,3 +15,5 @@ download_and_decompress \ --check-hash sha256 \ $base_url/$file_stem.tar.gz \ --strip-components 1 $file_stem/cargo-machete + +with_log mv cargo-machete$exe ~/.cargo/bin diff --git a/scripts/download/lib.sh b/scripts/download/lib.sh index 22a564a1..9c8c4cab 100755 --- a/scripts/download/lib.sh +++ b/scripts/download/lib.sh @@ -5,6 +5,27 @@ script_dir=$(readlink -f $(dirname ${BASH_SOURCE[0]})) # Produces Rust-style arch names, e.g. x86_64, aarch64, etc. export arch_rust=$(uname -m) +case "$OSTYPE" in + linux*) export os=linux ;; + darwin*) export os=darwin ;; + msys) export os=windows ;; + *) echo "Unknown OS: $OSTYPE" && exit 1 ;; +esac + +case $os in + linux) export triple_rust=unknown-linux-gnu ;; + darwin) export triple_rust=apple-darwin ;; + windows) export triple_rust=pc-windows-msvc ;; +esac + +triple_rust=$arch_rust-$triple_rust + +if [[ os == "windows" ]]; then + export exe=.exe +else + export exe= +fi + function download_and_decompress { with_backoff try_download_and_decompress "$@" } diff --git a/scripts/download/mdbook.sh b/scripts/download/mdbook.sh index dadc1161..c781352c 100755 --- a/scripts/download/mdbook.sh +++ b/scripts/download/mdbook.sh @@ -9,11 +9,15 @@ script_dir=$(readlink -f $(dirname ${BASH_SOURCE[0]})) # mdbook version=v0.4.33 base_url=https://github.com/rust-lang/mdBook/releases/download/$version -file_stem=mdbook-$version-x86_64-unknown-linux-gnu +file_stem=mdbook-$version-$triple_rust download_and_decompress $base_url/$file_stem.tar.gz +with_log mv mdbook$exe ~/.cargo/bin + # mdbook-toc version=0.14.1 base_url=https://github.com/badboy/mdbook-toc/releases/download/$version -file_stem=mdbook-toc-$version-x86_64-unknown-linux-gnu +file_stem=mdbook-toc-$version-$triple_rust download_and_decompress $base_url/$file_stem.tar.gz + +with_log mv mdbook-toc$exe ~/.cargo/bin diff --git a/scripts/download/taplo.sh b/scripts/download/taplo.sh index 68312429..ef9ea305 100755 --- a/scripts/download/taplo.sh +++ b/scripts/download/taplo.sh @@ -10,10 +10,9 @@ version=0.8.1 base_url=https://github.com/tamasfe/taplo/releases/download/$version -file_stem=taplo-linux-$arch_rust +file_stem=taplo-$os-$arch_rust download_and_decompress $base_url/$file_stem.gz -mv $file_stem taplo - -chmod +x ./taplo +with_log chmod +x $file_stem$exe +with_log mv $file_stem$exe ~/.cargo/bin/taplo$exe diff --git a/scripts/download/typos.sh b/scripts/download/typos.sh index 7be033c8..1804cc10 100755 --- a/scripts/download/typos.sh +++ b/scripts/download/typos.sh @@ -12,6 +12,12 @@ version=v1.16.1 base_url=https://github.com/crate-ci/typos/releases/download/$version +if [[ $os == linux ]]; then + triple_rust=$arch_rust-unknown-linux-musl +fi + file_stem=typos-$version-x86_64-unknown-linux-musl download_and_decompress $base_url/$file_stem.tar.gz ./typos + +with_log mv typos$exe ~/.cargo/bin