标签: rust-compiler-plugin

无法编译简单的 rust 程序

今天我决定学习并开始用 Rust 编码,因为它是一种非常有前途的语言。但是,我尝试在 rust 中编译并运行一个简单的 Hello world 程序,但由于某种原因出现此错误。有人能告诉我出了什么问题吗?

这是我的防锈代码:

fn main(){
        println!("Hi");
}
Run Code Online (Sandbox Code Playgroud)

这是错误消息:

错误:与 cc失败:退出代码:1 | = 注意:“cc”“-m64”“-L”“/Users/moo7md/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib”“test.test. 7rcbfp3g-cgu.0.rcgu.o" "test.test.7rcbfp3g-cgu.1.rcgu.o" "test.test.7rcbfp3g-cgu.2.rcgu.o" "test.test.7rcbfp3g-cgu.3 .rcgu.o" "test.test.7rcbfp3g-cgu.4.rcgu.o" "test.test.7rcbfp3g-cgu.5.rcgu.o" "-o" "test" "test.5fi6c8ty3hqyycqf.rcgu.o " "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/moo7md/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users /moo7md/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-a5984f6fc2a4870f.rlib"

rust rust-cargo rust-compiler-plugin

7
推荐指数
1
解决办法
1414
查看次数

在stable上运行编译器插件

我正在尝试制作的东西需要插件编译器,因为我需要在编译时报告错误,但是我希望它能在Rust稳定运行而不是每晚都运行.

有没有办法在稳定的Rust上运行编译器插件?

rust rust-compiler-plugin

6
推荐指数
1
解决办法
508
查看次数

如何编写生成模块的Rust编译器插件?

我正在编写一个扩展的Rust编译器插件

choose! {
    test_a
    test_b
}
Run Code Online (Sandbox Code Playgroud)

#[cfg(feature = "a")]
mod test_a;
#[cfg(feature = "b")]
mod test_b;
Run Code Online (Sandbox Code Playgroud)

它现在几乎完成,但模块在最终扩展的代码中不包含任何内容.我猜原因是跨度不包括模块文件.

use syntax::ast;
use syntax::ptr::P;
use syntax::codemap;
use syntax::parse::token;
use syntax::tokenstream::TokenTree;
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
use syntax::ext::build::AstBuilder;
use syntax_pos::Span;
use rustc_plugin::Registry;
use syntax::util::small_vector::SmallVector;

// Ideally, it will expand
//
// ```rust
// choose! {
//   test_a
//   test_b
// }
// ```
// to
// ```rust
// #[cfg(feature = "a")]
// mod test_a;
// #[cfg(feature = "b")]
// mod test_b;
// ``` …
Run Code Online (Sandbox Code Playgroud)

rust rust-compiler-plugin

6
推荐指数
1
解决办法
333
查看次数

为什么不是`正则表达式!``Regex :: new`的包装提供相同的正则表达式匹配速度?

锈病正则表达式箱提供了regex!语法扩展,这使得它能够在标准的编译时间编译正则表达式.这有两个好处:

  • 我们不需要在运行时执行该工作(更好的程序性能)
  • 如果我们的正则表达式格式错误,编译器可以在编译期间告诉我们,而不是触发运行时恐慌

不幸的是,文档说:

警告:regex!编译器插件的幅度比正常慢的顺序Regex::new(...)使用.您不应该使用编译器插件,除非您有非常特殊的理由这样做.

这听起来像一个完全不同的正则表达式引擎用于regex!Regex::new().为什么不regex!()只是Regex::new()结合两个世界的优势的包装?据我了解,这些语法扩展编译器插件可以执行任意代码; 为什么不Regex::new()呢?

rust rust-compiler-plugin

6
推荐指数
1
解决办法
416
查看次数

使用Rust编译器插件插入新字段时,创建Span的正确方法是什么?

我想要一个编译器插件来注释带有一些信息的结构.例如,原始结构只有一个字段:

struct X { x: i32 }
Run Code Online (Sandbox Code Playgroud)

我想添加另一个字段:

struct X { x: i32, y: MARKTYPE }
Run Code Online (Sandbox Code Playgroud)

当我查看Rust编译器插件时,我决定使用MultiModifier(SyntaxExtension)来完成我的工作.enum ItemKind定义Struct(VariantData, Generics)VariantData存储数据字段:

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum VariantData {
    /// Struct variant.
    ///
    /// E.g. `Bar { .. }` as in `enum Foo { Bar { .. } }`
    Struct(Vec<StructField>, NodeId),
    /// Tuple variant.
    ///
    /// E.g. `Bar(..)` as in `enum Foo { Bar(..) }`
    Tuple(Vec<StructField>, NodeId),
    /// Unit …
Run Code Online (Sandbox Code Playgroud)

rust rust-compiler-plugin

6
推荐指数
0
解决办法
112
查看次数

如何将自定义 llvm pass 添加到 rustc 中

我正在尝试将我的 llvm pass 添加到 Rustc 中。Rustc 有一个编译选项-C passes=val,我们可以在其中添加额外的 LLVM 传递来运行。然而,正如我的尝试,此选项只能在密码放置在 LLVM 代码树内时接受密码,但我想将我的密码从树外添加到 Rustc 中。

当我通过此选项添加我的通行证时:
RUSTFLAGS="-C passes=my-pass" cargo build
编译器报告错误:
error: failed to run LLVM passes: unknown pass name 'my-pass'

然后我尝试通过-C llvm-args=-fpass-plugin=/opt/new-pass/mypass.so -C passes=my-pass这种clang方式加载我的通行证。据报道:rustc -Cllvm-args="..." with: Unknown command line argument '-fpass-plugin=/opt/new-pass/mypass.so'. 也尝试替换-fpass-plugin为其他选项,如-load-load-pass-plugin,但它们仍然无法被 rustc 识别。

如何将自定义通行证添加到 Rustc 中?

rust llvm-ir rust-cargo rust-compiler-plugin

6
推荐指数
1
解决办法
726
查看次数

如何在编译器插件中修改包的所有项?

我正在尝试构建一个语法扩展,将属性扩展为调用.之前:

#[flame]
fn flamed() {
    ..
}
Run Code Online (Sandbox Code Playgroud)

后:

fn flamed() {
    flame::start_guard("flamed");
    ..
}
Run Code Online (Sandbox Code Playgroud)

这已经有效了.但是,如果我#[flame]在箱子级别(如#![flame])具有属性,我也希望它能够工作.这是可能的,如果是的话,怎么样?

compiler-construction rust rust-compiler-plugin

5
推荐指数
1
解决办法
90
查看次数

仅导出特定字段的属性,例如serde

使用derive语法,我可以实现特定字段HashPartialEq使用特定字段的特征,而不是全部字段吗?

它可能看起来像:

#[derive(Debug, Hash, Eq, PartialEq)]
struct MyStruct {
    id: i32,
    name: String,

    #[derive(hash_skip, eq_skip)] 
    aux_data1: f64,
    #[derive(hash_skip, eq_skip)]
    aux_data2: f64,
    #[derive(hash_skip, eq_skip)]
    aux_data3: String,
}
Run Code Online (Sandbox Code Playgroud)

我希望该hash方法仅使用id,name而不是其他人.

SERDE库允许这样的事情进行序列化.

rust rust-compiler-plugin

3
推荐指数
1
解决办法
779
查看次数

如何在编译器插件中获取struct字段和字段类型?

我想生成一个HashMap使用struct字段作为键,并使用usize整数作为值.

pub struct Article {
    title: String,
    content: String,
    category: String,
    comments: Vec<Comment>
}

pub struct Comment {
    content: String
}
Run Code Online (Sandbox Code Playgroud)

我的预期输出是:

{
    title: 0,
    content: 1,
    category: 2
    comments[].content: 3
}
Run Code Online (Sandbox Code Playgroud)

我的解决办法是impl我的特质FieldsMapping两个ArticleComment:

pub trait FieldsMapping {
    fn get_fields_map(&self) -> HashMap<String, usize>;
}
Run Code Online (Sandbox Code Playgroud)

我想为自定义派生编写一个编译器插件FieldsMapping.

我的问题是:如何在编译器插件中获取所有字段?我怎么知道字段类型是Vec什么?

rust rust-compiler-plugin rustc-serialize

1
推荐指数
1
解决办法
138
查看次数