Skip to content

Commit

Permalink
Add support for our temporary target
Browse files Browse the repository at this point in the history
For the current phase of work we are requiring that input LLVM IR be
built to target the `aarch64-unknown-none-softfloat` target. This means
that it can make no assumptions about either the host operating system
(as there is none), nor the target ABI (meaning that we fall back to
platform codegen ABI convention, and hence that `rustc` will not do
anything funky here).

We add support in the nix derivation (`flake.nix`) so that this target
is automatically made available in the sandbox. It may be necessary to
add it at the system level as well, depending on how your development
environment is set up.
  • Loading branch information
iamrecursion committed Sep 30, 2024
1 parent 43179c3 commit e7970c2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
3 changes: 3 additions & 0 deletions crates/compiler/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@
//! translation—the benefits of not having to manually perform this additional
//! work far outweighs that downside. If we _do_ need any additional control, we
//! can always modify this process at a later date.
#[cfg(test)]
mod test {}
14 changes: 3 additions & 11 deletions crates/rust-test-input/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
#![no_std]

/// Adds two numbers together.
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
5 changes: 3 additions & 2 deletions docs/Getting LLVM IR Output.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ this project.
## Rust

`rustc` will emit LLVM IR when passed the `--emit=llvm-ir` flag, and LLVM bytecode when passed the
`--emit=llvm-bc`. This will output `.ll` files into the `target` directory corresponding to your
compiled file. For more information, see the
`--emit=llvm-bc`. This will output `.ll` (or `.bc`) files into the `target` directory corresponding
to your compiled file (usually in `build-type/deps/crate-name-hash.ll`). For more information, see
the
[`rustc` developer guide](https://rustc-dev-guide.rust-lang.org/backend/debugging.html).

- This can be passed to the correct compiler when using cargo by calling
Expand Down
34 changes: 18 additions & 16 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@
flake-utils.lib.eachDefaultSystem (system:
let
# We grab our expected rust version from the Cargo.toml.
rustVersion = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.rust-version;
rustVersion = (lib.importTOML ./Cargo.toml).workspace.package.rust-version;

# Then we set up our libraries for building this thing.
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
fenixLib = fenix.packages.${system};
toolchainHash = "sha256-VZZnlyP69+Y3crrLHQyJirqlHrTtGTsyiSnZB8jEvVo=";
fenixStable = fenixLib.fromToolchainName {
name = rustVersion;
sha256 = "sha256-VZZnlyP69+Y3crrLHQyJirqlHrTtGTsyiSnZB8jEvVo=";
sha256 = toolchainHash;
};

# A target of the same version for our temporary "source" ABI
fenixAarch64 = fenixLib.targets.aarch64-unknown-none-softfloat.toolchainOf {
channel = rustVersion;
sha256 = toolchainHash;
};

# As we want nightly Rustfmt, we have to build a custom toolchain.
Expand All @@ -40,6 +47,7 @@
"rust-std"
"rustc"
])
fenixAarch64.rust-std
];

# The crane library configures the Rust toolchain, along with the components we expect it
Expand Down

0 comments on commit e7970c2

Please sign in to comment.