Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .envrc

This file was deleted.

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,18 @@ nix build .#uefi
# Run the CLI tool directly
nix run .#tool -- --help

# Cross-compile for Windows (from Linux, no Windows needed)
nix build .#windows

# Run the UEFI app in QEMU
nix run .#qemu

# Enter a development shell with all dependencies
nix develop

# Enter a cross-compilation shell for Windows
nix develop .#cross-windows
cargo build --target x86_64-pc-windows-gnu -p framework_tool
```

### Building with Cargo
Expand Down
85 changes: 85 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,23 @@
# Read toolchain from rust-toolchain.toml
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;

# Toolchain extended with Windows cross-compilation target
rustToolchainWindows = rustToolchain.override {
targets = [ "x86_64-pc-windows-gnu" ];
};

# Create a custom rustPlatform with our toolchain
rustPlatform = pkgs.makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};

# rustPlatform with Windows cross-compilation target
rustPlatformWindows = pkgs.makeRustPlatform {
cargo = rustToolchainWindows;
rustc = rustToolchainWindows;
};

# Common build inputs for OS builds
commonBuildInputs = with pkgs; [
openssl
Expand Down Expand Up @@ -57,6 +68,7 @@
"framework_lib"
"framework_tool"
"framework_uefi"
"res"
".cargo"
];
includedFiles = [
Expand Down Expand Up @@ -129,6 +141,60 @@
LIBGIT2_NO_VENDOR = "1";
};

# MinGW cross-compiler for Windows builds
mingw = pkgs.pkgsCross.mingwW64.stdenv.cc;
mingwPthreads = pkgs.pkgsCross.mingwW64.windows.pthreads;

# Build function for Windows cross-compilation (Linux -> Windows)
buildFrameworkToolWindows = { release ? false }:
let
profile = if release then "release" else "debug";
in
rustPlatformWindows.buildRustPackage {
pname = "framework_tool";
version = "0.5.0";

src = buildSrc;

cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = gitDependencyHashes;
};

buildType = profile;
buildNoDefaultFeatures = true;

# Disable cargo-auditable as it's incompatible with cross-compilation
auditable = false;

buildPhase = ''
runHook preBuild
cargo build \
${if release then "--release" else ""} \
--target x86_64-pc-windows-gnu \
-p framework_tool
runHook postBuild
'';

# Skip check phase - can't run .exe on Linux
doCheck = false;

installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp target/x86_64-pc-windows-gnu/${profile}/framework_tool.exe $out/bin/
runHook postInstall
'';

nativeBuildInputs = [ mingw ];

CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER = "${mingw}/bin/x86_64-w64-mingw32-gcc";
CC_x86_64_pc_windows_gnu = "${mingw}/bin/x86_64-w64-mingw32-gcc";
CXX_x86_64_pc_windows_gnu = "${mingw}/bin/x86_64-w64-mingw32-g++";
AR_x86_64_pc_windows_gnu = "${mingw}/bin/x86_64-w64-mingw32-ar";
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUSTFLAGS = "-L native=${mingwPthreads}/lib";
};

# Build function for UEFI application
buildFrameworkUefi = { release ? false, features ? [] }:
let
Expand Down Expand Up @@ -186,6 +252,8 @@
framework-tool-release = buildFrameworkTool { release = true; };
framework-uefi-debug = buildFrameworkUefi { release = false; };
framework-uefi-release = buildFrameworkUefi { release = true; };
framework-tool-windows = buildFrameworkToolWindows { release = true; };
framework-tool-windows-debug = buildFrameworkToolWindows { release = false; };

# Wrapper script to run the UEFI build in an emulator
run-qemu = pkgs.writeShellScriptBin "run-framework-uefi-qemu" ''
Expand Down Expand Up @@ -261,6 +329,8 @@
tool-debug = framework-tool-debug;
uefi = framework-uefi-release;
uefi-debug = framework-uefi-debug;
windows = framework-tool-windows;
windows-debug = framework-tool-windows-debug;
run-qemu = run-qemu;
run-qemu-release = run-qemu-release;
};
Expand All @@ -273,6 +343,21 @@
qemu-release = flake-utils.lib.mkApp { drv = run-qemu-release; };
};

devShells.cross-windows = pkgs.mkShell {
packages = [
rustToolchainWindows
];

# Ensure build scripts (e.g. libgit2-sys) use the native host compiler
HOST_CC = "cc";

CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER = "${mingw}/bin/x86_64-w64-mingw32-gcc";
CC_x86_64_pc_windows_gnu = "${mingw}/bin/x86_64-w64-mingw32-gcc";
CXX_x86_64_pc_windows_gnu = "${mingw}/bin/x86_64-w64-mingw32-g++";
AR_x86_64_pc_windows_gnu = "${mingw}/bin/x86_64-w64-mingw32-ar";
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUSTFLAGS = "-L native=${mingwPthreads}/lib";
};

devShells.default = pkgs.mkShell {
packages = with pkgs; [
rustToolchain
Expand Down
8 changes: 6 additions & 2 deletions framework_tool/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ fn main() {
// Add app icon
if std::env::var_os("CARGO_CFG_WINDOWS").is_some() {
winresource::WindowsResource::new()
.set_icon("..\\res\\framework_startmenuicon.ico")
.set_icon("../res/framework_startmenuicon.ico")
.compile()
.unwrap();
}

if !cfg!(debug_assertions) {
let is_msvc = std::env::var("CARGO_CFG_TARGET_ENV")
.map(|v| v == "msvc")
.unwrap_or(false);

if !cfg!(debug_assertions) && is_msvc {
// Statically link vcruntime to allow running on clean install
static_vcruntime::metabuild();

Expand Down