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

Macro in path attribute on module results in file not found error #48250

Open
CasualX opened this Issue Feb 16, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@CasualX
Copy link

CasualX commented Feb 16, 2018

When using a build script to generate code I tried to include it in a submodule in the following way:

#[path = concat!(env!("OUT_DIR"), "/generated.rs")]
pub mod generated;

However this results in error[E0583]: file not found for module generated. The error does not display the actual path it tried to access.

The closes related issue I could find are #18849 and rust-lang/rfcs#1516 (related rust-lang/cargo#824). However all of these talk about the compile error being a parse error, while I'm getting an error about file not being found.

For reference, here's the build script: (abridged, I apologize if this doesn't compile but you get the idea)

use std::{env, fs};
use std::path::PathBuf;

fn main() {
	let out_dir = PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR not set"));
	let mut file = fs::File::create(&out_dir.join("/generated.cs")).expect("Failed to create generated.rs");
	let _ = writeln!(file, "pub const FOO: i32 = 42;");
}

The include! macro works mostly but has one annoying problem that top-level inner attributes causes a compile error: #18810

The unexpected and reason why I don't think this is a duplicate issue is that the compile error has changed. From the error rust reports it appears I've made a simple typo in the path when in fact this feature is simply not supported.

@pietroalbini

This comment has been minimized.

Copy link
Member

pietroalbini commented Feb 20, 2018

There is a new RFC that aims to provide a way to solve this issue: rust-lang/rfcs#2320.

@durka

This comment has been minimized.

Copy link
Contributor

durka commented Mar 3, 2018

@pietroalbini can you clarify how #2320 addresses this issue? Would built-in attributes such as #[path] be upgraded to use this new macro expansion API?

@pietroalbini

This comment has been minimized.

Copy link
Member

pietroalbini commented Mar 4, 2018

@durka it doesn't directly mention it, but it provides the tools to implement it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.