1
0
Fork 0

conda-windows-binutils-or1k: build with msys2, not conda

This commit is contained in:
Astro 2020-07-22 06:43:56 +08:00
parent 6c328f32f1
commit 3409eb3c11
6 changed files with 97 additions and 23 deletions

View File

@ -1,21 +1,7 @@
set MSYS=C:\MSYS64
set TRIPLE=x86_64-pc-mingw64
set PATH=%MSYS%\usr\bin;%MSYS%\mingw64\bin;%PATH%
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##
cd %PREFIX%
tar xjf /c/Users/wfvm/src.tar.bz2
dir C:\Users\wfvm
python C:\Users\wfvm\patch_prefix.py "##PREFIX##" %PREFIX%

View File

@ -1,4 +1,4 @@
{ pkgs, version, src, target }:
{ pkgs, version, target, windows-binutils }:
let
wfvm = import ../wfvm.nix { inherit pkgs; };
@ -34,11 +34,13 @@ 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 .
tar xjf ${src}
patch -d binutils-${version} -p1 < ${./binutils-hack-libiconv.patch}
tar cjf src.tar.bz2 binutils-${version}
cp ${windows-binutils} src.tar.bz2
${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"

View File

@ -0,0 +1,35 @@
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)

View File

@ -124,11 +124,17 @@ let
};
condaWindowsExperimental = rec {
conda-windows-binutils-or1k = import ./conda-windows/binutils.nix {
windows-binutils-or1k = import ./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;

View File

@ -0,0 +1,45 @@
{ 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-pc-mingw64 --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
''