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

Cannot build workspace with proc-macro lib as member #610

Open
dsxmachina opened this issue May 6, 2024 · 2 comments
Open

Cannot build workspace with proc-macro lib as member #610

dsxmachina opened this issue May 6, 2024 · 2 comments
Labels
bug Something isn't working needs reproduction Missing a flake which easily reproduces the problem

Comments

@dsxmachina
Copy link

Describe the bug

I have a workspace containing a few binary, library and one proc-macro crate. However, when I want to build any package or use nix flake check, I get a weird build error:

       > error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]`
       >   --> core/macros/src/lib.rs:14:1
       >    |
       > 14 | pub fn main() {}
       >    | ^^^^^^^^^^^^^
       >
       > error: could not compile `macros` (lib) due to 1 previous error
       > warning: build failed, waiting for other jobs to finish...
       For full logs, run 'nix-store -l /nix/store/ymbh5xqg7z4cbiprgvs2i93fw93k27r7-cargo-package-deps-0.0.1.drv'.

Which is bogus, because the library does not include a pub fn main() {} at line 14.

Reproduction
I used the example init flake from your documentation (https://crane.dev/examples/quick-start-workspace.html) and replaced my-cli and my-server with my own binary crates from the workspace. Everything else is as it is in the example.

I traced down the error and found what was causing it. By looking at the derivation, I searched for the code inside the nix-store, that is used for the compilation:

nix show-derivation /nix/store/ymbh5xqg7z4cbiprgvs2i93fw93k27r7-cargo-package-deps-0.0.1.drv

This gave me quite a lot of output. Under the key "env/src" I found the link to the src repository:

"env": 
     ...
     "src": "/nix/store/knwb69fg1gqwhlrz4zbn23pv187za27m-source",

And inside /nix/store/knwb69fg1gqwhlrz4zbn23pv187za27m-source I found the basic directory structure of my workspace, but the Code has been replaced with a dummy implementation (which seems to be something that crane does, although I don't know why or how I could influence this behaviour).
Here is the code of the proc-macro library that is causing the compilation error:

#![allow(clippy::all)]
#![allow(dead_code)]
#![cfg_attr(any(target_os = "none", target_os = "uefi"), no_std)]
#![cfg_attr(any(target_os = "none", target_os = "uefi"), no_main)]

#[allow(unused_extern_crates)]
extern crate core;

#[cfg_attr(any(target_os = "none", target_os = "uefi"), panic_handler)]
fn panic(_info: &::core::panic::PanicInfo<'_>) -> ! {
    loop {}
}

pub fn main() {}

And there we have the culprit - pub fn main() {} in line 14.

It seems to me, that this is the default dummy implementation that you guys use for everything. All other library crates had their lib.rs content replaced with the same code above. For normal libraries it does not seem to be a problem that there is a main function defined though.

@dsxmachina dsxmachina added the bug Something isn't working label May 6, 2024
@ipetkov
Copy link
Owner

ipetkov commented May 8, 2024

Hi @dsxmachina thanks for the report! Yes it does seem like there is something going wrong with the dummification, perhaps we have to treat proc-macro crates differently...

Do you have a(n ideally) minimal reproduction I can take a look at?

I tried to come up with a trivial proc-macro crate myself, but it built just fine (though now that I notice it, cleaning Cargo.tomls is stripping out lib.proc-macro = true which might be a separate bug) 🤔

@ipetkov ipetkov added the needs reproduction Missing a flake which easily reproduces the problem label May 8, 2024
@dsxmachina
Copy link
Author

The proc-macro crate itself as a flake works fine, this seems only to be an issue with workspaces.

I created a small repo to reproduce the bug: https://github.com/dsxmachina/crane-bug-test

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs reproduction Missing a flake which easily reproduces the problem
Projects
None yet
Development

No branches or pull requests

2 participants