From d72d798d6674fed1763b216023030fa5a49c5414 Mon Sep 17 00:00:00 2001 From: Ambroz Bizjak Date: Fri, 18 Nov 2016 19:58:02 +0100 Subject: [PATCH] Finishing Nix build method for Windows. --- INSTALL => BUILD-WINDOWS-old.txt | 3 ++ BUILD-WINDOWS.txt | 17 +++++++ badvpn-win32.nix | 77 ++++++++++++++++++++------------ build-win32.nix | 10 ++--- 4 files changed, 72 insertions(+), 35 deletions(-) rename INSTALL => BUILD-WINDOWS-old.txt (93%) create mode 100644 BUILD-WINDOWS.txt diff --git a/INSTALL b/BUILD-WINDOWS-old.txt similarity index 93% rename from INSTALL rename to BUILD-WINDOWS-old.txt index 3605f4e52..77af4856c 100644 --- a/INSTALL +++ b/BUILD-WINDOWS-old.txt @@ -1,3 +1,6 @@ +NOTE: These instructions are out of date! +The supported method for building Windows binaries is described in BUILD-WINDOWS.txt. + 1 Requirements 1.1 Operating system diff --git a/BUILD-WINDOWS.txt b/BUILD-WINDOWS.txt new file mode 100644 index 000000000..cba1a6f38 --- /dev/null +++ b/BUILD-WINDOWS.txt @@ -0,0 +1,17 @@ +This describes the supported build method for building for Windows. + +Build can only be done on Linux and the Nix package manager must be installed first. +Install Nix from: http://nixos.org/nix/ + +Then you need to checkout a slignely patched version of the Nix packages collections. +This is needed because it has fixes enabling cross-compilation of NSPR and NSS to Windows. + +git clone -b cross-mingw-nss --single-branch https://github.com/ambrop72/nixpkgs + +It may be faster to download a zip from Github: https://github.com/ambrop72/nixpkgs/archive/cross-mingw-nss.zip + +Then you can build with the following command from the badvpn source directory: + +NIX_PATH=nixpkgs= nix-build build-win32.nix -A badvpnPkgs.badvpn -o + +Upon success the chosen will be a symlink to a directory with the build outputs. diff --git a/badvpn-win32.nix b/badvpn-win32.nix index b6719f746..f5e3e4f63 100644 --- a/badvpn-win32.nix +++ b/badvpn-win32.nix @@ -1,30 +1,51 @@ -{ stdenv, cmake, pkgconfig, openssl, nspr, nss, debug ? false }: -let - compileFlags = "-O3 ${stdenv.lib.optionalString (!debug) "-DNDEBUG"}"; -in -stdenv.mkDerivation { - name = "badvpn"; +{ stdenv, cmake, pkgconfig, openssl, nspr, nss, zlib, sqlite, zip, debug ? false }: + +rec { + badvpn = ( + let + compileFlags = "-O3 ${stdenv.lib.optionalString (!debug) "-DNDEBUG"}"; + in + stdenv.mkDerivation { + name = "badvpn"; + + src = stdenv.lib.cleanSource ./.; + + nativeBuildInputs = [ cmake pkgconfig ]; + buildInputs = [ openssl nspr nss ]; + + NIX_CFLAGS_COMPILE = "-I${nspr.crossDrv.dev}/include/nspr -I${nss.crossDrv.dev}/include/nss -ggdb"; + NIX_CFLAGS_LINK = ["-ggdb"]; + + preConfigure = '' + cmakeFlagsArray=( "-DCMAKE_BUILD_TYPE=" "-DCMAKE_C_FLAGS=${compileFlags}" "-DCMAKE_SYSTEM_NAME=Windows" ); + ''; + + postInstall = '' + for lib in eay32; do + cp ${openssl.crossDrv.bin}/bin/lib$lib.dll $out/bin/ + done + for lib in nspr4 plc4 plds4; do + cp ${nspr.crossDrv.out}/lib/lib$lib.dll $out/bin/ + done + for lib in nss3 nssutil3 smime3 ssl3 softokn3 freebl3; do + cp ${nss.crossDrv.out}/lib/$lib.dll $out/bin/ + done + cp ${zlib.crossDrv.out}/bin/zlib1.dll $out/bin/ + cp ${sqlite.crossDrv.out}/bin/libsqlite3-0.dll $out/bin/ + _linkDLLs() { true; } + ''; + + dontCrossStrip = true; + }).crossDrv; - src = stdenv.lib.cleanSource ./.; - - nativeBuildInputs = [ cmake pkgconfig ]; - buildInputs = [ openssl nspr nss ]; - - NIX_CFLAGS_COMPILE = "-I${nspr.crossDrv}/include/nspr -I${nss.crossDrv}/include/nss"; - - preConfigure = '' - cmakeFlagsArray=( "-DCMAKE_BUILD_TYPE=" "-DCMAKE_C_FLAGS=${compileFlags}" "-DCMAKE_SYSTEM_NAME=Windows" ); - ''; - - postInstall = '' - for lib in eay32; do - cp ${openssl.crossDrv}/bin/lib$lib.dll $out/bin/ - done - for lib in nspr4 plc4 plds4; do - cp ${nspr.crossDrv}/lib/lib$lib.dll $out/bin/ - done - for lib in nss3 nssutil3 smime3 ssl3; do - cp ${nss.crossDrv}/lib/$lib.dll $out/bin/ - done - ''; + badvpnZip = stdenv.mkDerivation { + name = "badvpn.zip"; + unpackPhase = "true"; + nativeBuildInputs = [ zip ]; + installPhase = '' + mkdir badvpn-win32 + ln -s ${badvpn}/bin badvpn-win32/bin + zip -q -r $out badvpn-win32 + ''; + }; } diff --git a/build-win32.nix b/build-win32.nix index e701fe1bf..1609d74ac 100644 --- a/build-win32.nix +++ b/build-win32.nix @@ -21,12 +21,8 @@ in rec { inherit pkgs; - drvs = rec { - badvpnFunc = import ./badvpn-win32.nix; - badvpn = pkgs.callPackage badvpnFunc {}; - badvpnDebug = pkgs.callPackage badvpnFunc { debug = true; }; - }; + badvpnPkgsFunc = import ./badvpn-win32.nix; - badvpn = drvs.badvpn.crossDrv; - badvpnDebug = drvs.badvpnDebug.crossDrv; + badvpnPkgs = pkgs.callPackage badvpnPkgsFunc {}; + badvpnDebugPkgs = pkgs.callPackage badvpnPkgsFunc { debug = true; }; }