From 2b115dd284525686bd68a31b37d86e243a5a8c4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Sun, 24 Nov 2024 00:11:52 +0100 Subject: [PATCH] make things working for windows (wip) --- default.nix | 63 +++++++++++++++++++--------------------------- package.nix | 26 ++++++++----------- rust-toolchain.nix | 13 +++++++--- 3 files changed, 46 insertions(+), 56 deletions(-) diff --git a/default.nix b/default.nix index fed585d3..17003c77 100644 --- a/default.nix +++ b/default.nix @@ -1,75 +1,64 @@ { target ? null }: let - pkgs = import { }; - hostPkgs = - if isNull target || pkgs.stdenv.buildPlatform.config == target - then pkgs else import { crossSystem.config = target; }; - - inherit (hostPkgs) lib; - inherit (hostPkgs.stdenv) buildPlatform hostPlatform; - - crossSystems = import ./cross-systems.nix; - crossSystem = - if lib.attrsets.hasAttrByPath [ buildPlatform.system hostPlatform.config ] crossSystems then - crossSystems.${buildPlatform.system}.${hostPlatform.config} - else - throw "Platform not supported: " + hostPlatform.config; - - runner = crossSystem.runner or (_: "./himalaya") pkgs; + pkgs = import ( + if isNull target then { } + else { crossSystem.config = target; } + ); fenix = import (fetchTarball "https://github.com/soywod/fenix/archive/main.tar.gz") { }; mkToolchain = import ./rust-toolchain.nix fenix; rustToolchain = mkToolchain.fromTarget { - pkgs = hostPkgs; - targetSystem = hostPlatform.config; + lib = pkgs.lib; + targetSystem = pkgs.hostPlatform.config; }; - rustPlatform = hostPkgs.makeRustPlatform { + rustPlatform = pkgs.makeRustPlatform { rustc = rustToolchain; cargo = rustToolchain; }; himalaya = import ./package.nix { - inherit lib hostPlatform rustPlatform; - fetchFromGitHub = hostPkgs.fetchFromGitHub; - pkg-config = hostPkgs.pkg-config; - darwin = hostPkgs.darwin; - windows = hostPkgs.pkgsCross.mingwW64.windows; + inherit rustPlatform; + darwin = pkgs.darwin; + windows = pkgs.windows; + lib = pkgs.lib; + hostPlatform = pkgs.hostPlatform; + fetchFromGitHub = pkgs.fetchFromGitHub; + pkg-config = pkgs.pkg-config; installShellFiles = false; installShellCompletions = false; installManPages = false; - notmuch = hostPkgs.notmuch; - gpgme = hostPkgs.gpgme; + notmuch = pkgs.notmuch; + gpgme = pkgs.gpgme; + stdenv = pkgs.stdenv; pkgsCross = pkgs.pkgsCross; - stdenv = - if hostPlatform.isWindows - then pkgs.pkgsCross.mingwW64.stdenv - else pkgs.stdenv; }; in himalaya.overrideAttrs (drv: { version = "1.0.0"; postInstall = '' + export WINEPREFIX="$(mktemp -d)" + mkdir -p $out/bin/share/{applications,completions,man,services} cp assets/himalaya.desktop $out/bin/share/applications/ cp assets/himalaya-watch@.service $out/bin/share/services/ cd $out/bin - ${runner} man ./share/man - ${runner} completion bash > ./share/completions/himalaya.bash - ${runner} completion elvish > ./share/completions/himalaya.elvish - ${runner} completion fish > ./share/completions/himalaya.fish - ${runner} completion powershell > ./share/completions/himalaya.powershell - ${runner} completion zsh > ./share/completions/himalaya.zsh + ${pkgs.hostPlatform.emulator pkgs.buildPackages} himalaya man ./share/man + ${pkgs.hostPlatform.emulator pkgs.buildPackages} himalaya completion bash > ./share/completions/himalaya.bash + ${pkgs.hostPlatform.emulator pkgs.buildPackages} himalaya completion elvish > ./share/completions/himalaya.elvish + ${pkgs.hostPlatform.emulator pkgs.buildPackages} himalaya completion fish > ./share/completions/himalaya.fish + ${pkgs.hostPlatform.emulator pkgs.buildPackages} himalaya completion powershell > ./share/completions/himalaya.powershell + ${pkgs.hostPlatform.emulator pkgs.buildPackages} himalaya completion zsh > ./share/completions/himalaya.zsh tar -czf himalaya.tgz himalaya* share mv himalaya.tgz ../ - ${pkgs.zip}/bin/zip -r himalaya.zip himalaya* share + ${pkgs.buildPackages.zip}/bin/zip -r himalaya.zip himalaya* share mv himalaya.zip ../ ''; src = pkgs.nix-gitignore.gitignoreSource [ ] ./.; diff --git a/package.nix b/package.nix index 7b3534e6..0f537d02 100644 --- a/package.nix +++ b/package.nix @@ -1,11 +1,11 @@ { lib +, darwin +, windows , rustPlatform , fetchFromGitHub , hostPlatform , stdenv , pkg-config -, darwin -, windows , installShellFiles , installShellCompletions ? stdenv.buildPlatform.canExecute stdenv.hostPlatform , installManPages ? stdenv.buildPlatform.canExecute stdenv.hostPlatform @@ -32,29 +32,25 @@ rustPlatform.buildRustPackage rec { cargoHash = "sha256-YS8IamapvmdrOPptQh2Ef9Yold0IK1XIeGs0kDIQ5b8="; - # NIX_BUILD_CORES = 4; - # "CARGO_TARGET_${builtins.replaceStrings ["-"] ["_"] (lib.strings.toUpper stdenv.hostPlatform.config)}_LINKER" = "${stdenv.cc.targetPrefix}cc"; - # CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER = "${pkgsCross.mingwW64.stdenv.cc.targetPrefix}cc"; - # TARGET_CC = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; - # CARGO_BUILD_RUSTFLAGS = [ "-Ctarget-feature=+crt-static" ]; - CARGO_CFG_TARGET_FEATURE = "crt-static"; - CARGO_BUILD_RUSTFLAGS = [ "-Clinker=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" ]; - CARGO_BUILD_TARGET = hostPlatform.config; + NIX_BUILD_CORES = 4; + # CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; + TARGET_CC = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; + CARGO_BUILD_RUSTFLAGS = [ "-Ctarget-feature=+crt-static" "-Clinker=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" ]; + # CARGO_BUILD_RUSTFLAGS = [ "-Clinker=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" ]; + CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu"; doCheck = false; + auditable = false; + strictDeps = true; cargoTestFlags = [ # Only run lib tests (unit tests) # All other tests are integration tests which should not be run with Nix build "--lib" ]; - depsBuildBuild = lib.optionals hostPlatform.isWindows [ - pkgsCross.mingwW64.stdenv.cc - pkgsCross.mingwW64.windows.pthreads - ]; + depsBuildBuild = [ stdenv.cc windows.pthreads ]; nativeBuildInputs = [ ] - ++ lib.optional (builtins.elem "pgp-gpg" buildFeatures) pkg-config ++ lib.optional (installManPages || installShellCompletions) installShellFiles; buildInputs = [ ] diff --git a/rust-toolchain.nix b/rust-toolchain.nix index dd589f40..aa1dfcfd 100644 --- a/rust-toolchain.nix +++ b/rust-toolchain.nix @@ -5,16 +5,21 @@ let sha256 = "+syqAd2kX8KVa8/U2gz3blIQTTsYYt3U63xBWaGOSc8="; in -{ +rec { fromFile = { buildSystem }: fenix.packages.${buildSystem}.fromToolchainFile { inherit file sha256; }; - fromTarget = { pkgs, targetSystem }: + toRustTarget = target: { + x86_64-w64-mingw32 = "x86_64-pc-windows-gnu"; + }.${target} or target; + + fromTarget = { lib, targetSystem }: let - name = (pkgs.lib.importTOML file).toolchain.channel; + target = toRustTarget targetSystem; + name = (lib.importTOML file).toolchain.channel; toolchain = fenix.fromToolchainName { inherit name sha256; }; - targetToolchain = fenix.targets.${targetSystem}.fromToolchainName { inherit name sha256; }; + targetToolchain = fenix.targets.${target}.fromToolchainName { inherit name sha256; }; in fenix.combine [ toolchain.rustc