Skip to content

Commit

Permalink
[LW-6744] lace-blockchain-services installers – Windows (#213)
Browse files Browse the repository at this point in the history
* [LW-6744] lace-blockchain-services installers – Windows

* fix: some deadlocks

* ci: add Windows

* ci: make the ZIP downloadable from Hydra

* fix: preview/preprod on Windows (non-P2P topology)

* feat: force-kill children after some grace period

* fix: open currently being written to log file on Windows

* build: get native Windows DLLs mostly building with MSVC

* build: get all Node.js extension DLLs (native modules) built

* fix: a typo

* feat: package the final cardano-js-sdk for–, and enable on Windows

* build: determine `chromedriverBin` version programmatically

* feat: make Windows signalling more reliable

* build: have a JS and no-JS version of the archive

* feat: allow specifying "SIGINT" apart from "SIGBREAK" (big quotes)

* feat: pass the Handle as POSIX-ish FD using a hidden Windows API… :/

* build: share `main_fd_inheritance_windows.go`

* fix: make cardano-node exit gracefully on Windows in 100% cases

* fix: Linux build

* build: prepare an NSIS installer for Windows

* build: embed the ICO in the EXE

* build: silence most of Wine’s tracing

* build: include ‘laceVersion’ in file names, and NSIS

* build: add comments after code review

* build: move ‘nixpkgs-nsis’ to flake inputs
  • Loading branch information
michalrus authored Jul 20, 2023
1 parent 0c14a68 commit 8ca6907
Show file tree
Hide file tree
Showing 22 changed files with 1,716 additions and 36 deletions.
18 changes: 18 additions & 0 deletions flake.lock

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

7 changes: 5 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

nix-bundle-exe.url = "github:3noch/nix-bundle-exe";
nix-bundle-exe.flake = false;

# FIXME: ‘nsis’ can’t cross-compile with the regular Nixpkgs (above)
nixpkgs-nsis.url = "github:input-output-hk/nixpkgs/be445a9074f139d63e704fa82610d25456562c3d";
nixpkgs-nsis.flake = false; # too old
};

outputs = inputs: let
Expand All @@ -45,8 +49,7 @@
x86_64-linux = inputs.self.packages.x86_64-linux.lace-blockchain-services-installer;
x86_64-darwin = inputs.self.packages.x86_64-darwin.lace-blockchain-services-installer;
aarch64-darwin = inputs.self.packages.aarch64-darwin.lace-blockchain-services-installer;
# Uncomment once implemented:
# x86_64-windows = inputs.self.packages.x86_64-linux.lace-blockchain-services-installer-x86_64-windows;
x86_64-windows = inputs.self.packages.x86_64-linux.lace-blockchain-services-installer-x86_64-windows;
};

required = inputs.nixpkgs.legacyPackages.x86_64-linux.releaseTools.aggregate {
Expand Down
9 changes: 5 additions & 4 deletions nix/lace-blockchain-services/internal/any-darwin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ in rec {
lace-blockchain-services-exe = pkgs.buildGoModule rec {
name = "lace-blockchain-services";
src = ./lace-blockchain-services;
vendorHash = "sha256-DjDyHOENtaFSNGQtX50wL3hIo+lmMY1BJBn/TaAcXU0=";
vendorHash = "sha256-1slTIiIGxraIFdtKNeH4llXjrtSEaEQ7IIbOM3LL3N0=";
nativeBuildInputs = with pkgs; [ imagemagick go-bindata ];
buildInputs =
(with pkgs; [ ])
Expand All @@ -108,7 +108,8 @@ in rec {
};
preBuild = ''
convert -background none -size 66x66 cardano-template.svg cardano.png
go-bindata -pkg main -o assets.go cardano.png
cp cardano.png tray-icon
go-bindata -pkg main -o assets.go tray-icon
'';
};

Expand Down Expand Up @@ -264,7 +265,7 @@ in rec {
else "dirty";
in pkgs.runCommand "lace-blockchain-services-dmg" {} ''
mkdir -p $out
target=$out/lace-blockchain-services-${revShort}-${targetSystem}.dmg
target=$out/lace-blockchain-services-${common.laceVersion}-${revShort}-${targetSystem}.dmg
/usr/bin/hdiutil makehybrid -iso -joliet -o tmp.iso \
${lace-blockchain-services-bundle}/Applications
Expand Down Expand Up @@ -508,7 +509,7 @@ in rec {
'';
in pkgs.runCommand "lace-blockchain-services-dmg" {} ''
mkdir -p $out
target=$out/lace-blockchain-services-${revShort}-${targetSystem}.dmg
target=$out/lace-blockchain-services-${common.laceVersion}-${revShort}-${targetSystem}.dmg
${dmgbuild}/bin/dmgbuild \
-D app_path=${lace-blockchain-services-bundle}/Applications/${lib.escapeShellArg common.prettyName}.app \
Expand Down
46 changes: 42 additions & 4 deletions nix/lace-blockchain-services/internal/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,43 @@ in rec {

prettyName = "Lace Blockchain Services";

laceVersion = (builtins.fromJSON (builtins.readFile ../../../package.json)).version;

cardanoWorldFlake = (flake-compat { src = inputs.cardano-world; }).defaultNix;

# These are configs of ‘cardano-node’ for all networks we make available from the UI.
# The patching of the official networks needs to happen to:
# • turn off ‘EnableP2P’ (and modify topology accordingly), because it doesn’t work on Windows,
# • and turn off ‘hadPrometheus’, because it makes cardano-node hang on Windows during graceful exit.
networkConfigs = let
selectedNetworks = [ "mainnet" "preprod" "preview" ];
website = cardanoWorldFlake.${buildSystem}.cardano.packages.cardano-config-html-internal;
in pkgs.runCommand "network-configs" {} (lib.concatMapStringsSep "\n" (network: ''
in pkgs.runCommand "network-configs" {
nativeBuildInputs = [ pkgs.jq ];
} ((lib.concatMapStringsSep "\n" (network: ''
mkdir -p $out/${network}
cp -r ${website}/config/${network}/. $out/${network}
'') selectedNetworks);
'') selectedNetworks) + (lib.optionalString (targetSystem == "x86_64-windows") ''
# Transform P2P topologies to non-P2P (or else, on Windows, we’d require C:\etc\resolv.conf)
chmod -R +w $out
find $out -type f -name 'topology.*' | while IFS= read -r file ; do
addr=$(jq -er '.PublicRoots[0].publicRoots.accessPoints[0].address' "$file") || continue
port=$(jq -er '.PublicRoots[0].publicRoots.accessPoints[0].port' "$file") || continue
jq --arg addr "$addr" --argjson port "$port" --null-input \
'.Producers = [.addr = $addr | .port = $port | .valency = 1]' > tmp.json
mv tmp.json "$file"
done
find $out -type f -name 'config.*' | while IFS= read -r file ; do
if [ "$(jq .EnableP2P "$file")" == "true" ] ; then
jq '.EnableP2P = false' "$file" >tmp.json
mv tmp.json "$file"
fi
# With '.hasPrometheus', cardano-node hangs during graceful exit on Windows:
jq 'del(.hasPrometheus)' "$file" >tmp.json
mv tmp.json "$file"
done
''));

# XXX: they don’t enable aarch64-darwin builds yet:
cardanoNodeFlake = if targetSystem != "aarch64-darwin" then inputs.cardano-node else let
Expand All @@ -38,6 +66,16 @@ in rec {

ogmiosCompiler = "ghc8107";

ogmiosPatched = {
outPath = toString (pkgs.runCommand "ogmios-patched" {} ''
cp -r ${inputs.ogmios} $out
chmod -R +w $out
cd $out
patch -p1 -i ${./ogmios--on-windows.patch}
'');
inherit (inputs.ogmios.sourceInfo) rev shortRev lastModified lastModifiedDate;
};

ogmiosProject = let
theirDefaultNix = __readFile "${inputs.ogmios}/default.nix";
in
Expand All @@ -50,7 +88,7 @@ in rec {
inputMap = { "https://input-output-hk.github.io/cardano-haskell-packages" = inputs.ogmios-CHaP; };
src = haskell-nix.haskellLib.cleanSourceWith {
name = "ogmios-src";
src = inputs.ogmios;
src = ogmiosPatched;
subDir = "server";
filter = path: type: builtins.all (x: x) [
(baseNameOf path != "package.yaml")
Expand All @@ -60,7 +98,7 @@ in rec {

ogmios = {
x86_64-linux = ogmiosProject.projectCross.musl64.hsPkgs.ogmios.components.exes.ogmios;
x86_64-windows = throw "unimplemented";
x86_64-windows = ogmiosProject.projectCross.mingwW64.hsPkgs.ogmios.components.exes.ogmios;
x86_64-darwin = ogmiosProject.hsPkgs.ogmios.components.exes.ogmios;
aarch64-darwin = ogmiosProject.hsPkgs.ogmios.components.exes.ogmios;
}.${targetSystem};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
diff --git a/src/syscall/exec_windows.go b/src/syscall/exec_windows.go
index 45295dedff..cae07b0433 100644
--- a/src/syscall/exec_windows.go
+++ b/src/syscall/exec_windows.go
@@ -250,6 +250,8 @@ type SysProcAttr struct {
NoInheritHandles bool // if set, each inheritable handle in the calling process is not inherited by the new process
AdditionalInheritedHandles []Handle // a list of additional handles, already marked as inheritable, that will be inherited by the new process
ParentProcess Handle // if non-zero, the new process regards the process given by this handle as its parent process, and AdditionalInheritedHandles, if set, should exist in this parent process
+ StartupInfoCbReserved2 uint16
+ StartupInfoLpReserved2 *byte
}

var zeroProcAttr ProcAttr
@@ -410,6 +412,9 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
return 0, 0, err
}

+ si.CbReserved2 = sys.StartupInfoCbReserved2
+ si.LpReserved2 = sys.StartupInfoLpReserved2
+
pi := new(ProcessInformation)
flags := sys.CreationFlags | CREATE_UNICODE_ENVIRONMENT | _EXTENDED_STARTUPINFO_PRESENT
if sys.Token != 0 {
diff --git a/src/syscall/types_windows.go b/src/syscall/types_windows.go
index 384b5b4f2c..497ccf7357 100644
--- a/src/syscall/types_windows.go
+++ b/src/syscall/types_windows.go
@@ -483,8 +483,8 @@ type StartupInfo struct {
FillAttribute uint32
Flags uint32
ShowWindow uint16
- _ uint16
- _ *byte
+ CbReserved2 uint16
+ LpReserved2 *byte
StdInput Handle
StdOutput Handle
StdErr Handle
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ require (
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
golang.org/x/sys v0.8.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
)
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/Knetic/govaluate.v3 v3.0.0/go.mod h1:csKLBORsPbafmSCGTEh3U7Ozmsuq8ZSIlKk1bcqph0E=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU=
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading

0 comments on commit 8ca6907

Please sign in to comment.