11

I'm struggling to make macros from my rust lib available to other rust projects.

Here's an example of how I'm trying to get this work at the moment.

lib.rs:

#![crate_name = "dsp"]
#![feature(macro_rules, phase)]
#![phase(syntax)]

pub mod macros;

macros.rs:

#![macro_escape]

#[macro_export]
macro_rules! macro(...)

other_project.rs:

#![feature(phase, macro_rules)]
#![phase(syntax, plugin, link)] extern crate dsp;

macro!(...) // error: macro undefined: 'macro!'

Am I on the right track? I've been trying to use std::macros as a reference, but I don't seem to be having much luck. Is there anything obvious that I'm missing?

Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
mindTree
  • 916
  • 9
  • 18
  • Are you actually looking at doing digital signal processing industry or DSP stood for something else here? – errordeveloper Jul 15 '14 at 23:28
  • @errordeveloper Yep! For audio specifically. It's still very early stages and quite bare bones, but I've got a callback (using portaudio) and the basis of a 'DSP' node framework ready. You can [check it out here](https://github.com/PistonDevelopers/rust-dsp) as a part of the Piston project. I'm currently using it in a generative music engine - I'm hoping to contribute some of the oscillator/synth work i've made very soon. Also, we're always open to contributions/help :-) – mindTree Jul 17 '14 at 03:53
  • Sounds great! I'll check it out :) Feel free to drop a message to me @gmail.com. I was quite interested about how one can take advantage of NEON and VFP with Rust... – errordeveloper Jul 17 '14 at 11:47

1 Answers1

7

Your attributes are tangled.

#![…] refers to the outer scope, while #[…] refers to the next item.

Here are some things of note:

  1. In lib.rs, the #![feature(phase)] is unnecessary, and the #![phase(syntax)] is meaningless.

  2. In other_project.rs, your phase attribute is applied to the crate, not to the extern crate dsp; item—this is why it does not load any macros from it. Remove the !.

Chris Morgan
  • 86,207
  • 24
  • 208
  • 215
  • 1
    Just because I've spent a lot of time to figure it out, and you may come here with the same problem: put both annotations either in `main.rs` or, when you define crate, in `lib.rs`, *not* in the file which you actually want to use macros in. – skalee Dec 11 '14 at 16:12
  • 2
    To have effect, `#![feature]` must be on the crate, which means the crate root file, which defaults to `lib.rs` or `main.rs`, as appropriate. – Chris Morgan Dec 12 '14 at 01:17