Plugins 如何正确注册Rust编译器插件?

Plugins 如何正确注册Rust编译器插件?,plugins,compiler-construction,loading,rust,Plugins,Compiler Construction,Loading,Rust,我一直在努力让一个Rust编译器插件正确注册,这让我很恼火 我有一个单独的板条箱,名为rust\u to_glsl,它位于我的主代码的子目录中 在rust\u to_glsl/src/lib.rs文件中,我有以下内容 #![feature(plugin_registrar)] #![feature(rustc_private)] #![crate_type="dylib"] extern crate rustc; extern crate syntax; #[doc(hidden)] #[p

我一直在努力让一个Rust编译器插件正确注册,这让我很恼火

我有一个单独的板条箱,名为
rust\u to_glsl
,它位于我的主代码的子目录中

rust\u to_glsl/src/lib.rs文件中,我有以下内容

#![feature(plugin_registrar)]
#![feature(rustc_private)]
#![crate_type="dylib"]

extern crate rustc;
extern crate syntax;

#[doc(hidden)]
#[plugin_registrar]
pub fn registrar(registry: &mut rustc::plugin::Registry) {
    println!("Test");
    registry.register_macro("to_glsl", expand);
}
另外,我还定义了实际的
展开
函数

src/main.rs
中,我正试图引入那个插件/板条箱

#![feature(plugin)]
#![plugin(rust_to_glsl)]
然后我尝试在这里使用这个宏:

fn main() {
    let glsl = to_glsl!(
        const x: uint = 5;

        static texture: &Texture2d = 1;

        fn hello() {
            min(5, 3 * 1 + 5)
        }
    );

    println!("{}", glsl);
}
如果我编译它,我会得到以下错误:

Compiling opal v0.1.0 (file:///Users/chris/Code/Rust/gl)
src/main.rs:2:11: 2:23 error: can't find crate for `rust_to_glsl`
src/main.rs:2 #![plugin(rust_to_glsl)]
在构建过程中,我注意到没有编译
rust\u to_glsl
(使用
货物构建

如果我将
extern-crater-rust\u添加到\u-glsl
,那么它将
rust\u编译到\u-glsl
。 但随后,他说

49:23 error: macro undefined: 'to_glsl!'
src/main.rs:49     let glsl = to_glsl!(

我不确定是否需要
使用该宏,或者是否所有宏都是全局的。

结果我需要将其添加到
rust\u to_glsl/Cargo.toml

[lib]
name = "rust_to_glsl"
crate-type = ["dylib"]
然后不将其作为
构建依赖项
,而是正常的
依赖项