Skip to content

Commit 44245be

Browse files
committed
Expose crate as ::rustapi_rs; update tests
Allow proc-macro expansions to reference this crate via an absolute path by adding `extern crate self as rustapi_rs` and using `::rustapi_rs` when `FoundCrate::Itself` is detected in the macro. This ensures generated code also works in examples/benches inside the rustapi-rs package. Also update the CLI test helper to use `assert_cmd::cargo::cargo_bin_cmd!` instead of `Command::cargo_bin`.
1 parent 7d551c2 commit 44245be

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

crates/cargo-rustapi/tests/cli_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use tempfile::tempdir;
77

88
/// Helper to get the cargo-rustapi binary
99
fn cargo_rustapi() -> Command {
10-
Command::cargo_bin("cargo-rustapi").expect("Failed to find cargo-rustapi binary")
10+
assert_cmd::cargo::cargo_bin_cmd!("cargo-rustapi")
1111
}
1212

1313
mod new_command {

crates/rustapi-macros/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ fn get_rustapi_path() -> proc_macro2::TokenStream {
3535

3636
if let Ok(found) = rustapi_rs_found {
3737
match found {
38-
FoundCrate::Itself => quote! { crate },
38+
// `FoundCrate::Itself` can occur for examples/benches inside the rustapi-rs package.
39+
// Use an absolute crate path so generated code also works in those targets.
40+
FoundCrate::Itself => quote! { ::rustapi_rs },
3941
FoundCrate::Name(name) => {
4042
let normalized = name.replace('-', "_");
4143
let ident = syn::Ident::new(&normalized, proc_macro2::Span::call_site());

crates/rustapi-rs/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
//! rustapi-rs = { version = "0.1.300", features = ["jwt", "cors"] }
6060
//! ```
6161
62+
// Allow proc-macro expansions to refer to this crate via `::rustapi_rs`.
63+
extern crate self as rustapi_rs;
64+
6265
// Re-export core functionality
6366
pub use rustapi_core::*;
6467

0 commit comments

Comments
 (0)