Skip to content

Commit

Permalink
Build for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Jun 18, 2024
1 parent 1e64b74 commit 96ef5fe
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Build for aarch64-unknown-linux-gnu
run: nix build .#holochain_aarch64-linux

- name: Build for x86_64-pc-windows-gnu
run: nix build .#holochain_x86_64-windows

build-apple:
runs-on: macos-latest
steps:
Expand Down
39 changes: 39 additions & 0 deletions flake.lock

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

10 changes: 10 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
};
};

fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};

holochain = {
url = "github:holochain/holochain/bump-influxive";
flake = false;
Expand All @@ -43,6 +48,11 @@
crossSystem = "x86_64-linux";
rustTargetTriple = "x86_64-unknown-linux-gnu";
};
holochain_x86_64-windows = import ./modules/holochain-windows.nix {
inherit localSystem inputs;
crate = "holochain";
package = "holochain";
};
} // (if localSystem == "aarch64-darwin" then {
holochain_aarch64-apple = import ./modules/holochain-cross.nix {
inherit localSystem inputs;
Expand Down
2 changes: 2 additions & 0 deletions modules/holochain-cross.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
# Flake inputs
inputs

, # The system that we are compiling on
localSystem

# The crate to build, from the Holochain workspace. Must match the path to the Cargo.toml file.
, crate

# The name of the package to build, from the selected crate.
, package

, #
Expand Down
73 changes: 73 additions & 0 deletions modules/holochain-windows.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{ inputs, localSystem, crate, package }:
let
inherit (inputs) nixpkgs crane fenix;

pkgs = nixpkgs.legacyPackages.${localSystem};

toolchain = with fenix.packages.${localSystem};
combine [
minimal.rustc
minimal.cargo
targets.x86_64-pc-windows-gnu.latest.rust-std
];

craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;

# Crane filters out all non-cargo related files. Define include filter with files needed for build.
nonCargoBuildFiles = path: _type: builtins.match ".*(json|sql|wasm.gz)$" path != null;
includeFilesFilter = path: type:
(craneLib.filterCargoSources path type) || (nonCargoBuildFiles path type);

# Crane doesn't know which version to select from a workspace, so we tell it where to look
crateInfo = craneLib.crateNameFromCargoToml { cargoToml = inputs.holochain + "/crates/${crate}/Cargo.toml"; };

libsodium = pkgs.stdenv.mkDerivation {
name = "libsodium";
src = builtins.fetchurl {
url = "https://download.libsodium.org/libsodium/releases/libsodium-1.0.20-mingw.tar.gz";
sha256 = "sha256:09npqqrialraf2v4m6cicvhnj52p8jaya349wnzlklp31b0q3yq1";
};
unpackPhase = "true";
postInstall = ''
tar -xvf $src
mkdir -p $out
cp -r libsodium-win64/* $out
'';
};
in
craneLib.buildPackage {
pname = package;
version = crateInfo.version;
src = pkgs.lib.cleanSourceWith {
src = inputs.holochain;
filter = includeFilesFilter;
};

strictDeps = true;
doCheck = false;

CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu";

# fixes issues related to libring
TARGET_CC = "${pkgs.pkgsCross.mingwW64.stdenv.cc}/bin/${pkgs.pkgsCross.mingwW64.stdenv.cc.targetPrefix}cc";

# Otherwise tx5-go-pion-sys picks up the host linker instead of the cross linker
RUSTC_LINKER = "${pkgs.pkgsCross.mingwW64.stdenv.cc}/bin/${pkgs.pkgsCross.mingwW64.stdenv.cc.targetPrefix}cc";

SODIUM_LIB_DIR = "${libsodium}/lib";

# OPENSSL_NO_VENDOR = "1";

nativeBuildInputs = with pkgs; [
go
perl
];

depsBuildBuild = with pkgs; [
pkgsCross.mingwW64.stdenv.cc
pkgsCross.mingwW64.windows.pthreads
];

cargoExtraArgs = "--package ${package}";
}

0 comments on commit 96ef5fe

Please sign in to comment.