Automatically cross-compiles the sysroot crates core, compiler_builtins, and alloc.

Overview

cargo-xbuild

Cargo-xbuild is a wrapper for cargo build, which cross compiles the sysroot crates core, compiler_builtins, and alloc for custom targets. It is a simplified fork of xargo, which is in maintainance mode.

Alternative: The build-std feature of cargo

Cargo now has its own feature for cross compiling the sysroot: build-std. You can use it by passing -Z build-std=core,alloc to cargo build. Alternatively, you can specify the following in a .cargo/config.toml file:

[unstable]
build-std = ["core", "compiler_builtins", "alloc"]

The above requires at least Rust nightly 2020–07–15. With the above config in place, the normal cargo build command will now automatically cross-compile the specified sysroot crates.

The compiler may emit references to memset, memcpy, etc which are usually provided by the platform's libc but luckily compiler_builtins has a mem feature that will provide implementations of those functions. To enable that feature we can use the unstable cargo flag -Z build-std-features=compiler-builtins-mem or specify the following in a config.toml:

[unstable]
build-std = ["core", "compiler_builtins", "alloc"]
+build-std-features = ["compiler-builtins-mem"]

Note that using the compiler-builtins-mem requires at least Rust nightly 2020-09-30. For older versions you need to add a dependency on the rlibc crate to provide implementations of memset, memcpy, etc, which the compiler expects. Note that you need to add an extern crate rlibc statement in order for this to work (even in the 2018 edition of Rust). This is required to get cargo to link the otherwise unused crate.

Compared to cargo-xbuild, there are many advantages of using cargo's own feature:

  • the normal cargo {check, build, run, test} commands can be used
  • no external tool must be installed
  • less bugs and breakage because it is always up to date with rustc/cargo
  • faster compilation since the compiler can build the sysroot concurrently to the project crates
  • it might be stablized one day

So it is strongly recommended to try the build-std feature of cargo instead of using this crate.

Dependencies

  • The rust-src component, which you can install with rustup component add rust-src.

  • Rust and Cargo.

Installation of cargo-xbuild

In case you decide to use cargo-xbuild instead of cargo's build-std feature for some reason, you can install this crate through:

$ cargo install cargo-xbuild

Note: The latest version of cargo-xbuild supports all nightlies after 2020-07-30. If you are on an older nightly, you need to install version 0.5.35: cargo install cargo-xbuild --version 0.5.35.

Usage

Just use cargo xbuild instead of cargo build when cross-compiling for a custom target.

cargo xbuild --target your-target-name.json

Instead of the "can't find crate for core" error you would get with a plain cargo build, this crate cross-compiles the core, compiler_builtins, and alloc crates and then invokes cargo build with a modified sysroot. The sysroot is compiled in the target directory of your crate.

All additional arguments (e.g. --release or --verbose) are forwarded to cargo build.

Configuration

To configure cargo-xbuild create a package.metadata.cargo-xbuild table in your Cargo.toml. The following options are available:

[package.metadata.cargo-xbuild]
memcpy = true
sysroot_path = "target/sysroot"
panic_immediate_abort = false
  • The memcpy flag defines whether the mem feature of the compiler_builtins crate should be activated. Turning this flag off allows to specify own versions of the memcpy, memset etc. functions.
  • The sysroot_path flag specifies the directory where the sysroot should be placed.
  • The panic_immediate_abort flag specifies whether the panic_immediate_abort feature the of core crate should be defined.

Environment Variables

In addition to the above configuration keys, cargo-xbuild can be also configured through the following environment variables:

  • The XBUILD_SYSROOT_PATH variable can be used to specify where cargo-xbuild should place the generated sysroot. This variables takes precendence over the package.metadata.cargo-xbuild.sysroot_path configuration key.
  • When the XBUILD_KEEP_TEMP variable is set, the temporary directory used for compiling the sysroot is not deleted. This is useful for debugging. For convenience, cargo-xbuild also prints the directory name when the environment variable is set.

Dev channel

If you want to use a local Rust source instead of rust-src rustup component, you can set the XARGO_RUST_SRC environment variable.

# The source of the `core` crate must be in `$XARGO_RUST_SRC/core`
$ export XARGO_RUST_SRC=/path/to/rust/src

$ cargo xbuild --target msp430-none-elf.json

Using on Android

It's possible to run cargo-xbuild on your Android phone:

Install Termux and Nightly Rustc

  • Install termux
  • Install fish shell and set as default (optional): pkg install fish; chsh -s fish; fish
  • Install some basic tools: pkg install wget tar
  • Add the community repository by its-pointless: wget https://its-pointless.github.io/setup-pointless-repo.sh; bash setup-pointless-repo.sh
  • Install rust nightly: pkg install rustc cargo rustc-nightly
  • Prepend the nightly rustc path to your $PATH in order to use nightly (fish syntax): set -U fish_user_paths $PREFIX/opt/rust-nightly/bin/ $fish_user_paths
  • rustc --version should now return a nightly version

(Optional) Install Git and Clone your Repository

  • Install git: pkg install git
  • Clone a repository of your choice: git clone https://github.com/phil-opp/blog_os.git

Install Xbuild

  • Install cargo-xbuild: cargo install cargo-xbuild
  • Add the cargo bin directory to your $PATH (fish syntax): set -U fish_user_paths ~/.cargo/bin/ $fish_user_paths
  • Now cargo xbuild should be available.

It does not work yet because it needs access to the rust source code. By default it tries to use rustup for this, but we have no rustup support so we need a different way.

Providing the Rust Source Code

The Rust source code corresponding to our installed nightly is available in the its-pointless repository:

  • Download it: wget https://github.com/its-pointless/its-pointless.github.io/raw/master/rust-src-nightly.tar.xz
  • Extract it: tar xf rust-src-nightly.tar.xz
  • Set the XARGO_RUST_SRC environment variable to tell cargo-xbuild the source path (fish syntax): set -Ux XARGO_RUST_SRC ~/rust-src-nightly/rust-src/lib/rustlib/src/rust/src

Now cargo-xbuild should no longer complain about a missing rust-src component. However it will throw an I/O error after building the sysroot. The problem is that the downloaded Rust source code has a different structure than the source provided by rustup. We can fix this by adding a symbolic link:

ln -s ~/../usr/opt/rust-nightly/bin ~/../usr/opt/rust-nightly/lib/rustlib/aarch64-linux-android/bin

Now cargo xbuild --target your-target.json should work!

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Comments
  • Cargo xbuild failed when linking to high address

    Cargo xbuild failed when linking to high address

    I'm trying to build and link my kernel to higher address but cargo xuild emits alots of errors.

    rust-lld: error: core.dn6za2s3-cgu.4:(function core::fmt::num::imp::_$LT$impl$u20$core..fmt..Display$u20$for$u20$usize$GT$::fmt::h5a6ad2655a4131f3: .text._ZN4core3fmt3num3imp54_$LT$impl$u20$core..fmt..Display$u20$for$u20$usize$GT$3fmt17h5a6ad2655a4131f3E+0xFB): relocation R_X86_64_32 out of range: 18446603336221277272 is not in [0, 4294967295]
              rust-lld: error: core.dn6za2s3-cgu.4:(function core::fmt::num::imp::_$LT$impl$u20$core..fmt..Display$u20$for$u20$u32$GT$::fmt::hb74b0354b9128009: .text._ZN4core3fmt3num3imp52_$LT$impl$u20$core..fmt..Display$u20$for$u20$u32$GT$3fmt17hb74b0354b9128009E+0xFB): relocation R_X86_64_32 out of range: 18446603336221277272 is not in [0, 4294967295]
    
    opened by ghost 26
  • error: failed to get bitcode from object file for LTO

    error: failed to get bitcode from object file for LTO

    Hello. I use cargo xbuild to build my OS. Recently build failed with the following error message.

    error: failed to get bitcode from object file for LTO (Bitcode section not found in object file)
    

    My repository is this and cargo_settings.json is specified as the target. You can reproduce this by running make on the master branch. I also tried with phil-opp's .json file, but build failed. The only thing which made it possible to build is to disable lto ( lto = false in Cargo.toml) . cargo clean && cargo xbuild did not solve the problem. This is my CI history. You can see that the same commit succeeds and fails to build.

    opened by toku-sa-n 23
  • cargo xbuild not building core?

    cargo xbuild not building core?

    Hey there! This is kind of a weird bug report; Everything works on CI:

    • https://travis-ci.org/intermezzOS/kernel/jobs/433809087
    • https://ci.appveyor.com/project/steveklabnik/kernel

    but not locally.

    I just got a new computer. I'm trying to build intermezzos. It appears that cargo-xbuild isn't trying to build libcore, and I'm not sure why.

    Log:

    > cargo xbuild --target .\intermezzos.json --verbose
    + "rustc" "--print" "sysroot"
    + "rustc" "--print" "target-list"
    + RUSTFLAGS="--sysroot C:\\Users\\Steve%20Klabnik\\src\\intermezzos\\kernel\\target/sysroot"
    + "cargo" "build" "--target" ".\\intermezzos.json" "--verbose"
           Fresh unicode-width v0.1.5
       Compiling zero v0.1.2
       Compiling ux v0.1.2
       Compiling usize_conversions v0.2.0
       Compiling os_bootinfo v0.2.1
       Compiling bitflags v1.0.4
       Compiling bit_field v0.9.0
         Running `rustc --crate-name zero "C:\Users\Steve Klabnik\.cargo\registry\src\github.com-1ecc6299db9ec823\zero-0.1.2\src\lib.rs" --color always --crate-type lib --emit=dep-info,link -C panic=abort -C debuginfo=2 -C metadata=ba0b6236150e3006 -C extra-filename=-ba0b6236150e3006 --out-dir "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" --target "\\?\C:\Users\Steve Klabnik\src\intermezzos\kernel\intermezzos.json" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\debug\deps" --cap-lints allow --sysroot C:\Users\Steve%20Klabnik\src\intermezzos\kernel\target/sysroot`
         Running `rustc --crate-name ux "C:\Users\Steve Klabnik\.cargo\registry\src\github.com-1ecc6299db9ec823\ux-0.1.2\src\lib.rs" --color always --crate-type lib --emit=dep-info,link -C panic=abort -C debuginfo=2 -C metadata=09d8d1073892a348 -C extra-filename=-09d8d1073892a348 --out-dir "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" --target "\\?\C:\Users\Steve Klabnik\src\intermezzos\kernel\intermezzos.json" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\debug\deps" --cap-lints allow --sysroot C:\Users\Steve%20Klabnik\src\intermezzos\kernel\target/sysroot`
         Running `rustc --crate-name usize_conversions "C:\Users\Steve Klabnik\.cargo\registry\src\github.com-1ecc6299db9ec823\usize_conversions-0.2.0\src\lib.rs" --color always --crate-type lib --emit=dep-info,link -C panic=abort -C debuginfo=2 -C metadata=784cfbd532dc9233 -C extra-filename=-784cfbd532dc9233 --out-dir "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" --target "\\?\C:\Users\Steve Klabnik\src\intermezzos\kernel\intermezzos.json" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\debug\deps" --cap-lints allow --sysroot C:\Users\Steve%20Klabnik\src\intermezzos\kernel\target/sysroot`
         Running `rustc --crate-name os_bootinfo "C:\Users\Steve Klabnik\.cargo\registry\src\github.com-1ecc6299db9ec823\os_bootinfo-0.2.1\src\lib.rs" --color always --crate-type lib --emit=dep-info,link -C panic=abort -C debuginfo=2 -C metadata=bcccaaae8157f32d -C extra-filename=-bcccaaae8157f32d --out-dir "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" --target "\\?\C:\Users\Steve Klabnik\src\intermezzos\kernel\intermezzos.json" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\debug\deps" --cap-lints allow --sysroot C:\Users\Steve%20Klabnik\src\intermezzos\kernel\target/sysroot`
         Running `rustc --crate-name bitflags "C:\Users\Steve Klabnik\.cargo\registry\src\github.com-1ecc6299db9ec823\bitflags-1.0.4\src\lib.rs" --color always --crate-type lib --emit=dep-info,link -C panic=abort -C debuginfo=2 --cfg "feature=\"default\"" -C metadata=416d1ccdb23746f4 -C extra-filename=-416d1ccdb23746f4 --out-dir "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" --target "\\?\C:\Users\Steve Klabnik\src\intermezzos\kernel\intermezzos.json" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\debug\deps" --cap-lints allow --sysroot C:\Users\Steve%20Klabnik\src\intermezzos\kernel\target/sysroot`
    error[E0463]: can't find crate for `core`
      |
      = note: the `intermezzos-11677179942914453679` target may not be installed
    
    error: aborting due to previous error
    
    For more information about this error, try `rustc --explain E0463`.
    error[E0463]: can't find crate for `core`
      |
      = note: the `intermezzos-11677179942914453679` target may not be installed
    
    error: Could not compile `zero`.
    
    Caused by:
      process didn't exit successfully: `rustc --crate-name zero "C:\Users\Steve Klabnik\.cargo\registry\src\github.com-1ecc6299db9ec823\zero-0.1.2\src\lib.rs" --color always --crate-type lib --emit=dep-info,link -C panic=abort -C debuginfo=2 -C metadata=ba0b6236150e3006 -C extra-filename=-ba0b6236150e3006 --out-dir "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" --target "\\?\C:\Users\Steve Klabnik\src\intermezzos\kernel\intermezzos.json" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\debug\deps" --cap-lints allow --sysroot C:\Users\Steve%20Klabnik\src\intermezzos\kernel\target/sysroot` (exit code: 1)
    warning: build failed, waiting for other jobs to finish...
    error: aborting due to previous error
    
    For more information about this error, try `rustc --explain E0463`.
    error[E0463]: can't find crate for `core`
      |
      = note: the `intermezzos-11677179942914453679` target may not be installed
    
    error: aborting due to previous error
    
    For more information about this error, try `rustc --explain E0463`.
    error: Could not compile `usize_conversions`.
    
    Caused by:
      process didn't exit successfully: `rustc --crate-name usize_conversions "C:\Users\Steve Klabnik\.cargo\registry\src\github.com-1ecc6299db9ec823\usize_conversions-0.2.0\src\lib.rs" --color always --crate-type lib --emit=dep-info,link -C panic=abort -C debuginfo=2 -C metadata=784cfbd532dc9233 -C extra-filename=-784cfbd532dc9233 --out-dir "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" --target "\\?\C:\Users\Steve Klabnik\src\intermezzos\kernel\intermezzos.json" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\debug\deps" --cap-lints allow --sysroot C:\Users\Steve%20Klabnik\src\intermezzos\kernel\target/sysroot` (exit code: 1)
    warning: build failed, waiting for other jobs to finish...
    error[E0463]: can't find crate for `core`
      |
      = note: the `intermezzos-11677179942914453679` target may not be installed
    
    error: aborting due to previous error
    
    For more information about this error, try `rustc --explain E0463`.
         Running `rustc --crate-name bit_field "C:\Users\Steve Klabnik\.cargo\registry\src\github.com-1ecc6299db9ec823\bit_field-0.9.0\src\lib.rs" --color always --crate-type lib --emit=dep-info,link -C panic=abort -C debuginfo=2 -C metadata=b0a184e3c9e20697 -C extra-filename=-b0a184e3c9e20697 --out-dir "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" --target "\\?\C:\Users\Steve Klabnik\src\intermezzos\kernel\intermezzos.json" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\debug\deps" --cap-lints allow --sysroot C:\Users\Steve%20Klabnik\src\intermezzos\kernel\target/sysroot`
    error: Could not compile `ux`.
    
    Caused by:
      process didn't exit successfully: `rustc --crate-name ux "C:\Users\Steve Klabnik\.cargo\registry\src\github.com-1ecc6299db9ec823\ux-0.1.2\src\lib.rs" --color always --crate-type lib --emit=dep-info,link -C panic=abort -C debuginfo=2 -C metadata=09d8d1073892a348 -C extra-filename=-09d8d1073892a348 --out-dir "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" --target "\\?\C:\Users\Steve Klabnik\src\intermezzos\kernel\intermezzos.json" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\debug\deps" --cap-lints allow --sysroot C:\Users\Steve%20Klabnik\src\intermezzos\kernel\target/sysroot` (exit code: 1)
    warning: build failed, waiting for other jobs to finish...
    error: Could not compile `os_bootinfo`.
    
    Caused by:
      process didn't exit successfully: `rustc --crate-name os_bootinfo "C:\Users\Steve Klabnik\.cargo\registry\src\github.com-1ecc6299db9ec823\os_bootinfo-0.2.1\src\lib.rs" --color always --crate-type lib --emit=dep-info,link -C panic=abort -C debuginfo=2 -C metadata=bcccaaae8157f32d -C extra-filename=-bcccaaae8157f32d --out-dir "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" --target "\\?\C:\Users\Steve Klabnik\src\intermezzos\kernel\intermezzos.json" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\debug\deps" --cap-lints allow --sysroot C:\Users\Steve%20Klabnik\src\intermezzos\kernel\target/sysroot` (exit code: 1)
    warning: build failed, waiting for other jobs to finish...
    error[E0463]: can't find crate for `core`
      |
      = note: the `intermezzos-11677179942914453679` target may not be installed
    
    error: aborting due to previous error
    
    For more information about this error, try `rustc --explain E0463`.
    error: Could not compile `bitflags`.
    
    Caused by:
      process didn't exit successfully: `rustc --crate-name bitflags "C:\Users\Steve Klabnik\.cargo\registry\src\github.com-1ecc6299db9ec823\bitflags-1.0.4\src\lib.rs" --color always --crate-type lib --emit=dep-info,link -C panic=abort -C debuginfo=2 --cfg "feature=\"default\"" -C metadata=416d1ccdb23746f4 -C extra-filename=-416d1ccdb23746f4 --out-dir "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" --target "\\?\C:\Users\Steve Klabnik\src\intermezzos\kernel\intermezzos.json" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\debug\deps" --cap-lints allow --sysroot C:\Users\Steve%20Klabnik\src\intermezzos\kernel\target/sysroot` (exit code: 1)
    warning: build failed, waiting for other jobs to finish...
    error[E0463]: can't find crate for `core`
      |
      = note: the `intermezzos-11677179942914453679` target may not be installed
    
    error: aborting due to previous error
    
    For more information about this error, try `rustc --explain E0463`.
    error: Could not compile `bit_field`.
    
    Caused by:
      process didn't exit successfully: `rustc --crate-name bit_field "C:\Users\Steve Klabnik\.cargo\registry\src\github.com-1ecc6299db9ec823\bit_field-0.9.0\src\lib.rs" --color always --crate-type lib --emit=dep-info,link -C panic=abort -C debuginfo=2 -C metadata=b0a184e3c9e20697 -C extra-filename=-b0a184e3c9e20697 --out-dir "C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" --target "\\?\C:\Users\Steve Klabnik\src\intermezzos\kernel\intermezzos.json" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\intermezzos\debug\deps" -L "dependency=C:\Users\Steve Klabnik\src\intermezzos\kernel\target\debug\deps" --cap-lints allow --sysroot C:\Users\Steve%20Klabnik\src\intermezzos\kernel\target/sysroot` (exit code: 1)
    

    It fails to find libcore, but it doesn't even try to build it...

    Any ideas?

    opened by steveklabnik 23
  • Recompile only on demand

    Recompile only on demand

    Hi Phil,

    thanks for taking on the annoying RUST_TARGET_PATH issue. I just tested it locally and it seems that, unless I'm doing something wrong, core, compiler_builtins, etc, are rebuilt every time from scratch.

    Would it make sense to not recompile if a previous, up-to-date built of the components is already in target? Is it technically feasible?

    Thanks, Andre

    opened by andre-richter 17
  • LTO causes sysroot to be unlinkable by non-LLVM toolchains

    LTO causes sysroot to be unlinkable by non-LLVM toolchains

    I'm using cargo xbuild to compile Rust binaries for the ESP32 via https://github.com/MabezDev/rust-xtensa, and then linking them via the Espressif xtensa-esp32-elf-ld, which is a GNU crosstool-NG linker that doesn't understand LLVM bitcode / LTO output

    Is it possible to disable LTO by default for the sysroot, or make it a flag that can be passed in?

    Reverting to 0.5.29 resolves the issue, so I imagine this is caused by the fix for #69 ?

    opened by rbtying 11
  • Escape spaces in rustflags

    Escape spaces in rustflags

    This is a PR originally filed by @AxelMontini for xargo: https://github.com/japaric/xargo/pull/221

    Below the originial PR description:


    Fixes an error on windows where paths with whitespaces don't get escaped at all, causing the error error: multiple input filenames provided. In my case it happens because my Windows username is "Axel Montini" and xargo doesn't like the space in the middle. This commit adds a function in utils to escape a string and replace spaces with %20 on windows or \ on other operative systems. I haven't tested this on a Unix machine, but it seems to work on windows.

    opened by phil-opp 11
  • Adds command xrustc

    Adds command xrustc

    Some options can only be passed to rustc with arguments e.g. --emit=link=path/exe. I'm not sure if it will break anything for others who would use cargo build instead of cargo rustc

    opened by qqwa 10
  • Unset RUSTFLAGS when building sysroot

    Unset RUSTFLAGS when building sysroot

    Fixes #4

    @qqwa Could you try whether this fixes your problem? You can install this version through:

    cargo install --git https://github.com/rust-osdev/cargo-xbuild.git --branch unset-rustflags --force
    
    opened by phil-opp 10
  • Cargo xbuild fails to build with older rustc nightly

    Cargo xbuild fails to build with older rustc nightly

    I'm using nightly-2020-02-24, but cargo xbuild tries to build core crate with lastest rust-src, which failed. cargo xbuild need a way to specify which rust-src to use when building core crate.

    opened by ghost 8
  • error: parsing package.metadata.cargo-xbuild section failed

    error: parsing package.metadata.cargo-xbuild section failed

    I get this new error message (introduced in #57) with no additional way to diagnose the cause.

    error: parsing package.metadata.cargo-xbuild section failed
    note: run with `RUST_BACKTRACE=1` for a backtrace
    

    Setting RUST_BACKTRACE=1 hides the second line from the error message and produces no backtrace.

    This causes my CI to fail. E.g. https://travis-ci.org/rust-console/cargo-n64/builds/650914215

    FWIW, the cargo-n64 repo is setup with a workspace manifest, and I do not have a package.metadata.cargo-xbuild section in any of the crate manifests. cargo xbuild is invoked something like this:

    cargo xbuild --target=/tmp/mips-nintendo64-none.json --package=hello-ipl3font --release
    
    Where the contents of the target JSON file is:
    {
      "arch": "mips",
      "cpu": "mips3",
      "data-layout": "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32:64-S64",
      "disable-redzone": true,
      "env": "unknown",
      "executables": true,
      "features": "+mips3,+gp64,+fpxx,+nooddspreg",
      "linker": "rust-lld",
      "linker-flavor": "ld.lld",
      "llvm-target": "mips-unknown-unknown",
      "os": "none",
      "panic-strategy": "abort",
      "pre-link-args": {
        "ld.lld": [
          "--script=/tmp/linker.ld"
        ]
      },
      "relocation-model": "static",
      "target-c-int-width": "32",
      "target-endian": "big",
      "target-pointer-width": "32",
      "vendor": "nintendo64"
    }
    
    And the contents of the linker script:
    ENTRY(_start)
    
    SECTIONS {
        . = 0x80000400;
        __boot_start = .;
    
        .boot : {
            *(.boot)
        }
    
        .text : {
            *(.text .text.*)
        }
    
        .rodata : {
            *(.rodata .rodata.*)
        }
    
        .data : {
            *(.data .data.*)
        }
    
        .bss : {
            . = ALIGN(4);
            __bss_start = .;
            *(.bss .bss.*)
            __bss_end = .;
        }
    
        . = ALIGN(2);
        __rom_end = . - __boot_start + 0xB0001000;
    
        /DISCARD/ : {
            *(.MIPS.*)
            *(.comment)
            *(.mdebug.*)
            *(.pdr)
            *(.reginfo)
    
            /*
             * We may need the global offset table some day.
             * Our target is currently set with a static relocation-model, so this
             * might not be needed after all.
             */
            *(.got)
        }
    }
    
    opened by parasyte 7
  • Still need `extern crate` when using Rust 2018

    Still need `extern crate` when using Rust 2018

    I recently ported some of our OS code to Rust 2018 and then a binary crate depending on a library crate does not compile if I remove the extern crate statement from it's main. The same example works when not cross-compiling (with a normal cargo build) so I guess it is something with the way cargo-xbuild works.

    The error I get is this

      |                                                                                                                                                                                                                                                                                                                                    
    7 | use salmiak::gpu;                                                                                                                                                                                                                                                                                                                  
      |     ^^^^^^^ Maybe a missing `extern crate salmiak;`?
    
    opened by abbec 7
  • relocation R_X86_64_32S out of range

    relocation R_X86_64_32S out of range

    When I build a Kernel Os with some crates ,it happend. Then I tried to give RUSTFLAGS and rebuilded those crates, also failed. But when I used .cargo/config.toml ,set build-std and env RUSTFLAGS then it did well Is cargo-xbuild question or have another resolution I don`t find?

    opened by polyproline 1
  • xbuild on Windows with git bash using gnu linker when msvc linker unavailable

    xbuild on Windows with git bash using gnu linker when msvc linker unavailable

    Recently, I accidentally uninstalled MSVC tooling on my windows machine unknowingly. This removed the MSVC linker, which (I believe) xbuild normally tries to use. Because I am using git bash, there is an included linker in the shell, which was used instead, and made builds fail. Untitled-1.txt This massive error message is what resulted. It was extremely hard to find out what was wrong, and I ended up having to reinstall xbuild, rust, all my toolchains, etc. Would it be possible to add some sort of check to ensure that the user knows the issue? This massive linker error dump is not useful at all.

    opened by Neben5 1
  • How to use a custom std

    How to use a custom std

    xbuild currently compiles core and alloc and puts in the custom sysroot. Is it possible to put a custom std in that location and compile it?

    The idea is that we can provide a minimal custom std so that crates that need std can be compiled without changing their code.

    opened by vinaychandra 1
  • ".got" linker section emitted in debug mode despite disabling dynamic linking/PIE

    I'm getting this error " = note: rust-lld: error: no memory region specified for section '.got'" which is unexpected because my target does not support the .got section at all. It is allowed in the linker script just to trigger a compiler error. This was working as of the .29 release, but is now broken with .33. With .29 I had the error with LTO code when using release mode, but with .33 that error went away. This .got error only occurs with debug builds.

    The target file I'm using:

    {
      "arch": "x86",
      "cpu": "i486",
      "data-layout": "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128",
      "dynamic-linking": false,
      "executables": true,
      "has-elf-tls": false,
      "has-rpath": false,
      "is-builtin": false,
      "linker": "rust-lld",
      "linker-flavor": "ld.lld",
      "linker-is-gnu": false,
      "llvm-target": "i486-unknown-none",
      "max-atomic-width": 64,
      "os": "neutron",
      "position-independent-executables": false,
      "target-c-int-width": "32",
      "target-endian": "little",
      "target-family": "unix",
      "target-pointer-width": "32",
      "vendor": "qtum",
      "features": "-mmx,-sse,+soft-float",
      "panic-strategy": "abort"
    }
    

    The linker script:

    ENTRY(__start)
    
    EXTERN(__sheap)
    EXTERN(__start)
    
    MEMORY
    {
        CODEMEM : ORIGIN = 0x10000, LENGTH = 63K
        CODEMEMAUX1 : ORIGIN = 0x20000, LENGTH = 63K
        CODEMEMAUX2 : ORIGIN = 0x30000, LENGTH = 63K
        CODEMEMAUX3 : ORIGIN = 0x40000, LENGTH = 63K
        CODEMEMAUX4 : ORIGIN = 0x50000, LENGTH = 63K
        CODEMEMAUX5 : ORIGIN = 0x60000, LENGTH = 63K
        CODEMEMAUX6 : ORIGIN = 0x70000, LENGTH = 63K
        CODEMEMAUX7 : ORIGIN = 0x80000, LENGTH = 63K
        DATAMEM : ORIGIN = 0x80020000, LENGTH = 63K
    }
    /* # Sections */
    SECTIONS
    {
      /* ### .text */
      .text :
      {
        *(__start_text);
        *(.text .text.*);
        *(.rodata .rodata.*);
      } > CODEMEM
      /* # aux code sections */
      .textaux1 :
      {
        *(.textaux1 .textaux1.*);
      } > CODEMEMAUX1
      .textaux2 :
      {
        *(.textaux2 .textaux2.*);
      } > CODEMEMAUX2
      .textaux3 :
      {
        *(.textaux3 .textaux3.*);
      } > CODEMEMAUX3
      .textaux4 :
      {
        *(.textaux4 .textaux4.*);
      } > CODEMEMAUX4
      .textaux5 :
      {
        *(.textaux5 .textaux5.*);
      } > CODEMEMAUX5
      .textaux6 :
      {
        *(.textaux6 .textaux6.*);
      } > CODEMEMAUX6
      .textaux7 :
      {
        *(.textaux7 .textaux7.*);
      } > CODEMEMAUX7
    
    
      /* ## Sections in RAM */
      /* ### .data */
      .data : ALIGN(4)
      {
        . = ALIGN(4);
        __sdata = .;
        *(.data .data.*);
        . = ALIGN(4); /* 4-byte align the end (VMA) of this section */
        __edata = .;
      } > DATAMEM AT > CODEMEM
    
      /* LMA of .data */
      __sidata = LOADADDR(.data);
    
      /* ### .bss */
      .bss : ALIGN(4)
      {
        . = ALIGN(4);
        __sbss = .;
        *(.bss .bss.*);
        . = ALIGN(4); /* 4-byte align the end (VMA) of this section */
        __ebss = .;
      } > DATAMEM
    
      /* ### .uninit */
      .uninit (NOLOAD) : ALIGN(4)
      {
        . = ALIGN(4);
        *(.uninit .uninit.*);
        . = ALIGN(4);
      } > DATAMEM
    
      /* Place the heap right after `.uninit` */
      . = ALIGN(4);
      __sheap = .;
    
      /* ## .got */
      /* Dynamic relocations are unsupported. This section is only used to detect relocatable code in
         the input files and raise an error if relocatable code is found */
      .got  :
      {
        KEEP(*(.got .got.*));
      }
    
      /* ## Discarded sections */
      /DISCARD/ :
      {
        /* Unused exception related info that only wastes space */
        *(.ARM.exidx);
        *(.ARM.exidx.*);
        *(.ARM.extab.*);
        *(.debug*);
        *(.comment*);
        *(.eh_frame*);
        
      }
    }
    /*
    ASSERT(SIZEOF(.got) == 0, "
    ERROR(cortex-m-rt): .got section detected in the input object files
    Dynamic relocations are not supported. If you are linking to C code compiled using
    the 'cc' crate then modify your build script to compile the C code _without_
    the -fPIC flag. See the documentation of the `cc::Build.pic` method for details.");
    */
    
    

    And the .cargo/config file:

    [target.i686-neutron]
    rustflags = [
      "-C", "link-arg=-Tlink.x",
      "-C", "relocation-model=static"
    ]
    [target.i486-neutron]
    rustflags = [
      "-C", "link-arg=-Tlink.x",
      "-C", "relocation-model=static"
    ]
    runner = "neutron-testbench"
    
    [build]
    target = "i486-neutron"
    
    

    I'm building it using cargo xbuild --target i486-neutron.json --verbose

    I have a few other targeted crates that I'm using, as well as some common ones like serde, alloc, etc

    opened by Earlz 3
  • codegen-backends deleted on Windows.

    codegen-backends deleted on Windows.

    On Windows, xbuild seems to be deleting codegen-backends and other presumably important files before erroring out.

    C:\Users\me\source\repos\CustomSdkRustInterop\lib_hello>cargo xbuild --target aarch64-custom-elf.json
        Updating crates.io index
       Compiling core v0.0.0 (C:\Users\me\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libcore)
       Compiling compiler_builtins v0.1.19
       Compiling rustc-std-workspace-core v1.99.0 (C:\Users\me\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\tools\rustc-std-workspace-core)
       Compiling alloc v0.0.0 (C:\Users\me\AppData\Local\Temp\xargo.P3VleUWvqWpF)
        Finished release [optimized] target(s) in 27.84s
    error: process didn't exit successfully: `rustc -vV` (exit code: 1)
    --- stdout
    rustc 1.40.0-nightly (fa0f7d008 2019-10-17)
    binary: rustc
    commit-hash: fa0f7d0080d8e7e9eb20aa9cbf8013f96c81287f
    commit-date: 2019-10-17
    host: x86_64-pc-windows-msvc
    release: 1.40.0-nightly
    
    --- stderr
    error: failed to find a `codegen-backends` folder in the sysroot candidates:
    * C:\Users\me\.rustup\toolchains\nightly-x86_64-pc-windows-msvc
    * \\?\C:\Users\me\.rustup\toolchains\nightly-x86_64-pc-windows-msvc```
    
    opened by sgeos 1
Owner
Rust OSDev
Operating System Development in Rust
Rust OSDev
Ector is an open source async, no-alloc actor framework for embedded devices

Ector is an open source async, no-alloc actor framework for embedded devices. Ector is an open source async, no-alloc actor framework for embedded dev

Drogue IoT 11 Dec 15, 2022
no-std no-alloc Rust protobufs.

noproto No-std, no-alloc protocol buffers (protobuf) implementation in Rust, for embedded systems. Optimized for binary size and memory usage, not for

null 13 Jun 21, 2023
A Diablo II library for core and simple client functionality, written in Rust for performance, safety and re-usability

A Diablo II library for core and simple client functionality, written in Rust for performance, safety and re-usability

null 4 Nov 30, 2022
mach-dump can parse Mach-O core dumps taken with lldb from macOS and iOS devices.

mach-dump mach-dump can parse Mach-O core dumps taken with lldb from macOS and iOS devices. It has no external dependencies. Example use std::path::Pa

Tobi 8 Sep 16, 2022
A lean, minimal, and stable set of types for color interoperation between crates in Rust.

This library provides a lean, minimal, and stable set of types for color interoperation between crates in Rust. Its goal is to serve the same function that mint provides for (linear algebra) math types.

Gray Olson 16 Sep 21, 2022
k-mer counter in Rust using the rust-bio and rayon crates

krust is a k-mer counter written in Rust and run from the command line that will output canonical k-mers and their frequency across the records in a f

null 14 Jan 7, 2023
Rust library to scan files and expand multi-file crates source code as a single tree

syn-file-expand This library allows you to load full source code of multi-file crates into a single syn::File. Features: Based on syn crate. Handling

Vitaly Shukela 11 Jul 27, 2022
A snapshot of name squatting on crates.io

Machine-readable database of public packages on crates.io which meet an arbitrary, unwritten, sensible definition of name squatting: squatted.csv Form

David Tolnay 69 Feb 1, 2023
Generate an SPDX Software Bill of Materials for Rust crates.

cargo-spdx cargo-spdx is currently in development and not yet ready for use. cargo-spdx provides a cargo subcommand to generate an SPDX Software Bill

Andrew Lilley Brinker 13 May 18, 2023
Crate of GitHub’s collection of gitignores, embedded, automatically updated

Gitignores GitHub’s collection of gitignores, embedded, automatically updated. API documentation. Public Domain via CC0-1.0 (same as source data). MSR

null 3 May 3, 2022
A git hook to manage derivative files automatically.

git-derivative A git hook to manage derivative files automatically. For example if you checked out to a branch with different yarn.lock, git-derivativ

Sung Jeon 3 Oct 30, 2022
Automatically build a Rust module tree from the project directory structure

Hypermod An even lazier version of automod and supermod. Searches the src/ directory recursively for .rs files, then builds a module tree using the di

null 4 Aug 3, 2022
Automatically transform your Next.js Pages to use SuperJSON with SWC

?? NEXT SUPERJSON PLUGIN export default function Page({ date }) { return ( <div> Today is {date.toDateString()} </div> ) } // You c

⚡️Blitz 92 Jan 4, 2023
A CLI tool that automatically writes commit messages for you.

Automagically-generated commit messages A CLI tool that generates commit messages from your staged changes, built in Rust and using OpenAI's Codex. In

Miguel Piedrafita 839 Jan 6, 2023
A swc plugin that automatically converts React component libraries into "React Client Component"

A swc plugin that automatically converts React component libraries into "React Client Component". For example, you can automatically convert components from @mui into "React Client Component" without having to wrap a component that uses "use client".

xiaotian 3 Jul 12, 2023
Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.

Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.

Fusion 1 Oct 19, 2021
A cross-platform serial port library in Rust. Provides a blocking I/O interface and port enumeration including USB device information.

Note: This is a fork of the original serialport-rs project on GitLab. Please note there have been some changes to both the supported targets and which

Serialport 128 Jan 4, 2023
Build and deploy cross platform bioinformatic utilities with Rust.

The Bioinformatics Toolkit RUST-backed utilities for bioinformatic data processing. Get started The fastest way to get started it to download the appl

null 5 Sep 8, 2023
A cross-platform serial port library in Rust.

Introduction serialport-rs is a general-purpose cross-platform serial port library for Rust. It provides a blocking I/O interface and port enumeration

Bryant Mairs 143 Nov 5, 2021