Skip to content

google/include-first

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

include-first

crates.io page docs.rs page

This crate provides a proc macro to evaluate include_str! macros early. This can be used to apply them in the context of a macro_rules! declaration, rather than in the context where the macro is used.

This is not an officially supported Google product. This project is not eligible for the Google Open Source Software Vulnerability Rewards Program.

Usage

Suppose you have a macro_rules! macro in a library crate, which uses include_str! to include a file, such as some assembly code:

#[macro_export]
macro_rules! generate_asm {
    ($foo:expr) => {
        core::arch::global_asm!(
            include_str!("entrypoint.S"),
            foo = const $foo,
        );
    }
}

If you use this from another crate, the include_str! will be evaluated from the context of the crate where it is used, and rustc will look for entrypoint.S relative to that crate's source directory. This is probably not what you want.

Adding the #[include_first] attribute macro fixes this:

use include_first::include_first;

#[macro_export]
#[include_first]
macro_rules! generate_asm {
    ($foo:expr) => {
        core::arch::global_asm!(
            include_str!("entrypoint.S"),
            foo = const $foo,
        );
    }
}

Now the include_first macro will go through and evaluate all include_str! macros in the context of the library crate where it is declared, before the macro_rules! macro is created.

License

Licensed under either of

at your option.

Contributing

If you want to contribute to the project, see details of how we accept contributions.

About

No description, website, or topics provided.

Resources

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages