From 12eb08180662fbdbc73bcc9069df36480b459282 Mon Sep 17 00:00:00 2001 From: Ara Adkins Date: Mon, 30 Sep 2024 15:28:37 -0600 Subject: [PATCH] Add support for our temporary target (#68) 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. --- crates/compiler/src/compile.rs | 3 +++ crates/rust-test-input/src/lib.rs | 14 +++----------- docs/Getting LLVM IR Output.md | 6 +++--- flake.nix | 12 ++++++++++-- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/crates/compiler/src/compile.rs b/crates/compiler/src/compile.rs index 92632488..475594d2 100644 --- a/crates/compiler/src/compile.rs +++ b/crates/compiler/src/compile.rs @@ -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 {} diff --git a/crates/rust-test-input/src/lib.rs b/crates/rust-test-input/src/lib.rs index b93cf3ff..95b24a4c 100644 --- a/crates/rust-test-input/src/lib.rs +++ b/crates/rust-test-input/src/lib.rs @@ -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); - } -} diff --git a/docs/Getting LLVM IR Output.md b/docs/Getting LLVM IR Output.md index efc8feab..793be15b 100644 --- a/docs/Getting LLVM IR Output.md +++ b/docs/Getting LLVM IR Output.md @@ -8,9 +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 -[`rustc` developer guide](https://rustc-dev-guide.rust-lang.org/backend/debugging.html). +`--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 `cargo rustc -- --emit=llvm-ir`. diff --git a/flake.nix b/flake.nix index a3833212..554a6c84 100644 --- a/flake.nix +++ b/flake.nix @@ -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. @@ -40,6 +47,7 @@ "rust-std" "rustc" ]) + fenixAarch64.rust-std ]; # The crane library configures the Rust toolchain, along with the components we expect it