Environment variable OUT_DIR is undefined

I'm trying to hide boilerplate from a project template for my framework.

src/main.rs

rialight::initialize!(|app| {
    // application
});

build.rs

rialight::initialize_build!(|| {
    // procedure
});

Basically I'm having trouble with build.rs. The compiler says OUT_DIR isn't defined. IIRC I did it some other time and it worked. I'm using a workspace, so the binary crate is in that workspace too, for debugging purposes.

#[macro_export]
macro_rules! initialize_build {
    ($lambda_exp:expr) => {
        fn main() {
            ::rialight::entry_point::_build_preprocess(env!("OUT_DIR"));
            let user_ie: fn() -> () = $lambda_exp;
            user_ie();
        }
    };
}

I tried passing OUT_DIR from build.rs to that macro as well...

My debug command:

cargo run -p rialight_blank_experiment

The env! macro is expanded at compile time, which is appropriate for main.rs, but the build script should use the runtime std::env::var_os. You can see that difference in this example:

https://doc.rust-lang.org/cargo/reference/build-script-examples.html#code-generation

3 Likes
5 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.