Skip to content

the #[proc_macro] attribute is only usable with crates of the proc-macro crate type #363

@sudo-nice

Description

@sudo-nice

I can't build a binary statically, using peg as a dependency. Here is a tiny main.rs to reproduce:

extern crate peg;
use peg::parser;

parser!{
    pub grammar g() for [u8] {
        #[no_eof]
        pub rule foo() = "foo"
    }
}

fn main() {
    assert_eq!(g::foo(b"foobar"), Ok(()));
}

Cargo.toml:

[profile.release]
strip = "symbols"
lto = "fat"
panic = "abort"
codegen-units = 1

# Commenting out this line allows to compile
rustflags = ["-C", "target-feature=+crt-static"]

[package]
name = "bar"
version = "0.1.0"
edition = "2021"

[dependencies]
peg = "*"

Trying to build it with cargo build --release results in the error:

error: the `#[proc_macro]` attribute is only usable with crates of the `proc-macro` crate type
  --> /mnt/ssd1/rust/cargo/registry/src/index.crates.io-6f17d22bba15001f/peg-macros-0.8.2/lib.rs:20:1
   |
20 | #[proc_macro]
   | ^^^^^^^^^^^^^

error: could not compile `peg-macros` (lib) due to previous error

Debian GNU/Linux 11 (bullseye)
rustc 1.76.0-nightly (49b3924bd 2023-11-27)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions