【问题标题】:How can I compile the Rust core crate for a custom target using only cargo or rustc?如何仅使用 cargo 或 rustc 为自定义目标编译 Rust 核心板条箱?
【发布时间】:2020-07-06 12:26:25
【问题描述】:

我正在为裸机 x86 目标编写代码,我需要交叉编译核心板条箱。我想要一个只使用 cargo 或 rustc 的解决方案。

我目前使用xcargo 编译一个虚拟的 no_std crate 并将 sysroot 文件夹复制到我的项目中。

【问题讨论】:

  • 也许这会有所帮助?有一节关于使用 rustc 构建 libcore。 randomhacks.net/2015/11/11/…
  • 我按照那个链接成功构建了一个名为 liblib.a 的文件。我怎样才能使用那个库?

标签: rust


【解决方案1】:

您可以使用 Cargo 的unstable build-std 功能:

cargo build -Z build-std=core --target my-custom-target.json

参数可以是:

  • core
  • std
  • alloc
  • proc_macro

不为所有参数传递任何参数。

【讨论】:

  • cargo build -Z build-std failed with error: unresolved imports `libc::c_char`, `libc::c_int`, `libc::c_void`, `libc::uintptr_t`
  • 我设法使用以下命令进行构建:'cargo build -Zbuild-std=core,alloc --target mytarget.json'
猜你喜欢
  • 1970-01-01
  • 2019-08-27
  • 2019-09-10
  • 1970-01-01
  • 1970-01-01
  • 2020-12-28
  • 1970-01-01
  • 1970-01-01
  • 2021-10-17
相关资源
最近更新 更多