From bc447638a92cdb9857f2ef6fb37a39d81c6963d4 Mon Sep 17 00:00:00 2001 From: Astro Date: Fri, 24 Jul 2020 09:35:29 +0800 Subject: [PATCH] Revert "conda-windows-binutils-or1k: build with msys2, not conda" This reverts commit 3409eb3c115023406173149e631ce2d5025f0c68. --- .../binutils-hack-libiconv.patch | 0 .../conda-windows/binutils-recipe/bld.bat | 22 +++++++-- artiq-fast/conda-windows/binutils.nix | 10 ++--- artiq-fast/conda-windows/patch_prefix.py | 35 --------------- artiq-fast/default.nix | 8 +--- artiq-fast/windows/binutils.nix | 45 ------------------- 6 files changed, 23 insertions(+), 97 deletions(-) rename artiq-fast/{windows => conda-windows}/binutils-hack-libiconv.patch (100%) delete mode 100644 artiq-fast/conda-windows/patch_prefix.py delete mode 100644 artiq-fast/windows/binutils.nix diff --git a/artiq-fast/windows/binutils-hack-libiconv.patch b/artiq-fast/conda-windows/binutils-hack-libiconv.patch similarity index 100% rename from artiq-fast/windows/binutils-hack-libiconv.patch rename to artiq-fast/conda-windows/binutils-hack-libiconv.patch diff --git a/artiq-fast/conda-windows/binutils-recipe/bld.bat b/artiq-fast/conda-windows/binutils-recipe/bld.bat index 90e4ff0..fa5fe84 100644 --- a/artiq-fast/conda-windows/binutils-recipe/bld.bat +++ b/artiq-fast/conda-windows/binutils-recipe/bld.bat @@ -1,7 +1,21 @@ set MSYS=C:\MSYS64 +set TRIPLE=x86_64-pc-mingw64 set PATH=%MSYS%\usr\bin;%MSYS%\mingw64\bin;%PATH% -cd %PREFIX% -tar xjf /c/Users/wfvm/src.tar.bz2 -dir C:\Users\wfvm -python C:\Users\wfvm\patch_prefix.py "##PREFIX##" %PREFIX% +mkdir build +cd build +set CFLAGS=-I%PREFIX:\=/%/Library/include/ +set LDFLAGS=-L%PREFIX:\=/%/Library/lib/ +sh ../configure --build=%TRIPLE% ^ + --prefix="%PREFIX:\=/%/Library" ^ + --target=##TARGET## +if errorlevel 1 exit 1 + +make -j4 +if errorlevel 1 exit 1 + +make install +if errorlevel 1 exit 1 + +rem this is a copy of prefixed executables +rmdir /S /Q %PREFIX%\Library\##TARGET## diff --git a/artiq-fast/conda-windows/binutils.nix b/artiq-fast/conda-windows/binutils.nix index b58f9a4..6358ebe 100644 --- a/artiq-fast/conda-windows/binutils.nix +++ b/artiq-fast/conda-windows/binutils.nix @@ -1,4 +1,4 @@ -{ pkgs, version, target, windows-binutils }: +{ pkgs, version, src, target }: let wfvm = import ../wfvm.nix { inherit pkgs; }; @@ -34,13 +34,11 @@ let cp --no-preserve=mode,ownership -R ${./binutils-recipe} binutils sed -i s/##TARGET##/${target}/g binutils/* sed -i s/##VERSION##/${version}/g binutils/* - sed -i 's!##PREFIX##!${windows-binutils.prefix}!g' binutils/* ${wfvm.utils.win-put}/bin/win-put binutils . - cp ${windows-binutils} src.tar.bz2 + tar xjf ${src} + patch -d binutils-${version} -p1 < ${./binutils-hack-libiconv.patch} + tar cjf src.tar.bz2 binutils-${version} ${wfvm.utils.win-put}/bin/win-put src.tar.bz2 . - cp ${./patch_prefix.py} patch_prefix.py - ls -l patch_prefix.py - ${wfvm.utils.win-put}/bin/win-put patch_prefix.py . ${wfvm.utils.win-exec}/bin/win-exec ".\Anaconda3\scripts\activate && conda build --no-anaconda-upload --no-test -c file:///C:/users/wfvm/fake-channel --override-channels binutils" diff --git a/artiq-fast/conda-windows/patch_prefix.py b/artiq-fast/conda-windows/patch_prefix.py deleted file mode 100644 index 083d15c..0000000 --- a/artiq-fast/conda-windows/patch_prefix.py +++ /dev/null @@ -1,35 +0,0 @@ -import os, sys, re - -OLD = sys.argv[1].encode('utf-8') -NEW = sys.argv[2].encode('utf-8') - -if len(NEW) > len(OLD): - raise ValueError("Cannot new shorter than the replacement") -new = NEW + b"\0" * (len(OLD) - len(NEW)) - -def patch_file(path): - with open(path, "r+b") as f: - s = f.read() - occurrences = s.count(OLD) - s = s.replace(OLD, new) - if occurrences > 0: - print("{}: replaced {}, left {}".format(path, occurrences, s.count(OLD))) - with open(path, "w+b") as f: - f.write(s) - -for root, dirs, files in os.walk("."): - for filename in files: - path = "{}/{}".format(root, filename) - patch_file(path) - -def mangle_path(path): - path = re.sub(r"^/c/", "C:/", path) - return str(path) - -OLD = mangle_path(sys.argv[1]).encode('utf-8') -NEW = mangle_path(sys.argv[2]).encode('utf-8') - -for root, dirs, files in os.walk("."): - for filename in files: - path = "{}/{}".format(root, filename) - patch_file(path) diff --git a/artiq-fast/default.nix b/artiq-fast/default.nix index d0705ae..0569314 100644 --- a/artiq-fast/default.nix +++ b/artiq-fast/default.nix @@ -124,17 +124,11 @@ let }; condaWindowsExperimental = rec { - windows-binutils-or1k = import ./windows/binutils.nix { + conda-windows-binutils-or1k = import ./conda-windows/binutils.nix { inherit pkgs; inherit (mainPackages.binutils-or1k) version src; target = "or1k-linux"; }; - conda-windows-binutils-or1k = import ./conda-windows/binutils.nix { - inherit pkgs; - inherit (mainPackages.binutils-or1k) version; - target = "or1k-linux"; - windows-binutils = windows-binutils-or1k; - }; conda-windows-binutils-arm = import ./conda-windows/binutils.nix { inherit pkgs; inherit (mainPackages.binutils-or1k) version src; diff --git a/artiq-fast/windows/binutils.nix b/artiq-fast/windows/binutils.nix deleted file mode 100644 index 9d54653..0000000 --- a/artiq-fast/windows/binutils.nix +++ /dev/null @@ -1,45 +0,0 @@ -{ pkgs, version, src, target }: - -let - wfvm = import ../wfvm.nix { inherit pkgs; }; - repeat = s: - let go = n: - if n > 0 - then s + go (n - 1) - else ""; - in go; - outName = "windows-binutils-${target}-${version}.tar.bz2"; - # add padding for later PREFIX replacement in `conda build` - prefix = "/c/Users/wfvm/binutils_" + repeat "0" 80; - build = wfvm.utils.wfvm-run { - name = "build-binutils"; - image = wfvm.makeWindowsImage { installCommands = with wfvm.layers; [ msys2 (msys2-packages (import ../conda-windows/msys_packages.nix { inherit pkgs; } )) ]; }; - script = '' - tar xjf ${src} - patch -d binutils-${version} -p1 < ${./binutils-hack-libiconv.patch} - tar cjf src.tar.bz2 binutils-${version} - ${wfvm.utils.win-put}/bin/win-put src.tar.bz2 . - - cat > build-binutils.bat << EOF - set MSYS=c:\msys64 - set PATH=%MSYS%\usr\bin;%MSYS%\mingw64\bin;%PATH% - tar xjf src.tar.bz2 - bash -c "cd binutils-${version} && ./configure --build=x86_64-w64-mingw32 --prefix=${prefix}/Library --target=${target} && make -j$NIX_BUILD_CORES && make install" - rm -r ${prefix}/Library/or1k-linux - cp %MSYS%/mingw64/bin/libiconv-2.dll ${prefix}/Library/bin/ - tar cjf ${outName} -C ${prefix} . - EOF - ${wfvm.utils.win-put}/bin/win-put build-binutils.bat . - ${wfvm.utils.win-exec}/bin/win-exec build-binutils - - ${wfvm.utils.win-get}/bin/win-get ${outName} - ''; - }; -in -pkgs.runCommand outName { - buildInputs = [ build ]; - passthru = { inherit prefix; }; -} '' - wfvm-run-build-binutils - cp ${outName} $out - ''