Skip to content

Commit

Permalink
Finishing Nix build method for Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
ambrop72 committed Nov 18, 2016
1 parent 3940ed0 commit d72d798
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 35 deletions.
3 changes: 3 additions & 0 deletions INSTALL → BUILD-WINDOWS-old.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 17 additions & 0 deletions BUILD-WINDOWS.txt
Original file line number Diff line number Diff line change
@@ -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=<path-to-nixpkgs> nix-build build-win32.nix -A badvpnPkgs.badvpn -o <output-link-path>

Upon success the chosen <output-link-path> will be a symlink to a directory with the build outputs.
77 changes: 49 additions & 28 deletions badvpn-win32.nix
Original file line number Diff line number Diff line change
@@ -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
'';
};
}
10 changes: 3 additions & 7 deletions build-win32.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
}

0 comments on commit d72d798

Please sign in to comment.