Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global proc-macro! sideeffects are a terrible idea #65

Open
MaulingMonkey opened this issue Jan 10, 2020 · 0 comments
Open

global proc-macro! sideeffects are a terrible idea #65

MaulingMonkey opened this issue Jan 10, 2020 · 0 comments
Labels
api-change Breaking API change bug Something isn't working java bindgen How Java types are automatically exposed to Rust macros

Comments

@MaulingMonkey
Copy link
Owner

For not-yet public java interop macros I'm introducing a new attribute to share state between invokations:

#![share_state_by_voiding_rustc_semver_and_breaking_randomly_in_the_future]

Per rust-lang/reference#578, the order of proc-macro expansion is not defined, and is likely to eventually change in the future even though right now it seems to be consistently in-order. My use case is something like:

java! {
    // Declare where to source Java metadata from:
    extern jdk "adopt-openjdk-13";
    extern jar "my-class.jar";
    // Generate Rust bindings for calling into Java:
    define import java.lang.*;
    define import my.Class;
    ...
}

// ...in a galaxy far far away...
java! {
    impl class my.Class { // This should be validated against the extern ed SDKs
        fn some_native_method(&env, this, a: u32, b: u32) -> u32 {
            ...
        }
    }
}

Alternatives

  • Duplicate defs every time (seems lame / a bad idea, doesn't play well with codegen?)
  • Have a single java! per crate that consumes the entire crate src (maybe a #![java] proc macro?)
  • When the first macro is evaluated, or via a build script:
    • Could pre-scan crate src once for externs/defines to pre-populate
    • Could read sidecar configuration files
    • Could read Cargo.toml package metadata
@MaulingMonkey MaulingMonkey added bug Something isn't working api-change Breaking API change java bindgen How Java types are automatically exposed to Rust macros labels Jan 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-change Breaking API change bug Something isn't working java bindgen How Java types are automatically exposed to Rust macros
Projects
None yet
Development

No branches or pull requests

1 participant