From 2e154e7e2af2f5c40f195c3ec5b468ae2259c1c7 Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Sat, 7 Dec 2024 18:54:51 +0100 Subject: [PATCH 1/2] Unbreak shell completion and --version without header This regressed again in #2984. Partially revert d75fe271418e and 42a86e288c43 and restore the previous behavior. Fixes: https://github.com/rust-lang/rust-bindgen/issues/3037 Fixes: https://github.com/rust-lang/rust-bindgen/issues/3039 --- bindgen/options/cli.rs | 52 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/bindgen/options/cli.rs b/bindgen/options/cli.rs index 9d5cea3dc6..8c4c05bc84 100644 --- a/bindgen/options/cli.rs +++ b/bindgen/options/cli.rs @@ -146,7 +146,7 @@ fn parse_custom_attribute( #[allow(clippy::doc_markdown)] struct BindgenCommand { /// C or C++ header file. - header: String, + header: Option, /// Path to write depfile to. #[arg(long)] depfile: Option, @@ -657,6 +657,33 @@ where clang_args, } = command; + if let Some(shell) = generate_shell_completions { + clap_complete::generate( + shell, + &mut BindgenCommand::command(), + "bindgen", + &mut io::stdout(), + ); + + exit(0) + } + + if version { + println!( + "bindgen {}", + option_env!("CARGO_PKG_VERSION").unwrap_or("unknown") + ); + if verbose { + println!("Clang: {}", crate::clang_version().full); + } + + exit(0) + } + + if header.is_none() { + return Err(io::Error::new(io::ErrorKind::Other, "Header not found")); + } + let mut builder = builder(); #[derive(Debug)] @@ -804,31 +831,8 @@ where } } - let header = Some(header); - builder = apply_args!( builder { - generate_shell_completions => |_, shell| { - clap_complete::generate( - shell, - &mut BindgenCommand::command(), - "bindgen", - &mut io::stdout(), - ); - - exit(0) - }, - version => |_, _| { - println!( - "bindgen {}", - option_env!("CARGO_PKG_VERSION").unwrap_or("unknown") - ); - if verbose { - println!("Clang: {}", crate::clang_version().full); - } - - exit(0) - }, header, rust_target, rust_edition, From 9a8502fa97916188b4d256433f8fced971ed06d9 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sun, 8 Dec 2024 10:33:59 -0500 Subject: [PATCH 2/2] ci: add regression tests for #3037 and #3039 --- .github/workflows/bindgen.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml index d459fc2fc2..ba95e42e23 100644 --- a/.github/workflows/bindgen.yml +++ b/.github/workflows/bindgen.yml @@ -201,12 +201,27 @@ jobs: ./mdbook build book ./mdbook test book + # FIXME(pvdrz): this should be done inside `bindgen-test` instead + test-no-headers: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Test `--help` + run: cargo run -- --help + + - name: Test `--version` + run: cargo run -- --version + + - name: Test `--generate-shell-completions` + run: cargo run -- --generate-shell-completions=bash + # One job that "summarizes" the success state of this pipeline. This can then # be added to branch protection, rather than having to add each job # separately. success: runs-on: ubuntu-latest - needs: [rustfmt-clippy, msrv, minimal, docs, quickchecking, test-expectations, test, check-cfg, test-book] + needs: [rustfmt-clippy, msrv, minimal, docs, quickchecking, test-expectations, test, check-cfg, test-book, test-no-headers] # GitHub branch protection is exceedingly silly and treats "jobs skipped # because a dependency failed" as success. So we have to do some # contortions to ensure the job fails if any of its dependencies fails.