ソースを参照

Finishing Nix build method for Windows.

Ambroz Bizjak 9 年 前
コミット
d72d798d66
4 ファイル変更72 行追加35 行削除
  1. 3 0
      BUILD-WINDOWS-old.txt
  2. 17 0
      BUILD-WINDOWS.txt
  3. 49 28
      badvpn-win32.nix
  4. 3 7
      build-win32.nix

+ 3 - 0
INSTALL → 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

+ 17 - 0
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=<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.

+ 49 - 28
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
+        '';
+    };
 }

+ 3 - 7
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; };
 }