From dc8df8660a5cf069a1c804669d22433603e7acc7 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 16 Jun 2020 16:23:47 +0800 Subject: [PATCH] conda-windows: build llvmlite-artiq --- artiq-fast/conda-windows/llvmlite-artiq.nix | 53 +++++++++++++++++++++ artiq-fast/conda-windows/llvmlite-msys.diff | 42 ++++++++++++++++ artiq-fast/default.nix | 4 ++ 3 files changed, 99 insertions(+) create mode 100644 artiq-fast/conda-windows/llvmlite-artiq.nix create mode 100644 artiq-fast/conda-windows/llvmlite-msys.diff diff --git a/artiq-fast/conda-windows/llvmlite-artiq.nix b/artiq-fast/conda-windows/llvmlite-artiq.nix new file mode 100644 index 0000000..aa21b79 --- /dev/null +++ b/artiq-fast/conda-windows/llvmlite-artiq.nix @@ -0,0 +1,53 @@ +{ pkgs, conda-windows-llvm-or1k, version, src }: + +# See: https://github.com/valtron/llvm-stuff/wiki/Build-llvmlite-with-MSYS2 + +let + wfvm = import ../wfvm { inherit pkgs; }; + build = wfvm.utils.wfvm-run { + name = "build-llvmlite-artiq"; + image = wfvm.makeWindowsImage { installCommands = with wfvm.layers; [ anaconda3 msys2 msys2-packages ]; }; + script = '' + ${wfvm.utils.win-put}/bin/win-put "${conda-windows-llvm-or1k}/win-64/llvm-or1k-*.tar.bz2" ".\llvm-or1k.tar.bz2" + ${wfvm.utils.win-exec}/bin/win-exec ".\Anaconda3\scripts\activate && conda create -n build llvm-or1k.tar.bz2" + + cat > meta.yaml << EOF + package: + name: llvmlite-artiq + version: ${version} + + source: + url: ../src.tar + EOF + + cat > bld.bat << EOF + set MSYS=C:\MSYS64 + set PATH=%MSYS%\usr\bin;%MSYS%\mingw64\bin;%PATH% + + python setup.py install \ + --prefix=\$PREFIX \ + --single-version-externally-managed \ + --record=record.txt \ + --no-compile + EOF + + ${wfvm.utils.win-exec}/bin/win-exec "mkdir llvmlite-artiq" + ${wfvm.utils.win-put}/bin/win-put meta.yaml ".\llvmlite-artiq" + ${wfvm.utils.win-put}/bin/win-put bld.bat ".\llvmlite-artiq" + cp --no-preserve=mode,ownership -R ${src} src + patch -d src -p1 < ${./llvmlite-msys.diff} + tar chf src.tar src + ${wfvm.utils.win-put}/bin/win-put src.tar ".\src.tar" + + ${wfvm.utils.win-exec}/bin/win-exec ".\Anaconda3\scripts\activate build && conda build --no-anaconda-upload --no-test llvmlite-artiq" + + ${wfvm.utils.win-get}/bin/win-get ".\Anaconda3\conda-bld\win-64\llvmlite-artiq-${version}-0.tar.bz2" + ''; + }; +in + pkgs.runCommand "conda-windows-llvmlite-artiq" { buildInputs = [ build ]; } '' + wfvm-run-build-llvmlite-artiq + mkdir -p $out/win-64 $out/nix-support + cp *.tar.bz2 $out/win-64 + echo file conda $out/win-64/*.tar.bz2 >> $out/nix-support/hydra-build-products + '' diff --git a/artiq-fast/conda-windows/llvmlite-msys.diff b/artiq-fast/conda-windows/llvmlite-msys.diff new file mode 100644 index 0000000..1c4f175 --- /dev/null +++ b/artiq-fast/conda-windows/llvmlite-msys.diff @@ -0,0 +1,42 @@ +diff --git a/ffi/CMakeLists.txt b/ffi/CMakeLists.txt +index 15470d4..11d06a5 100755 +--- a/ffi/CMakeLists.txt ++++ b/ffi/CMakeLists.txt +@@ -29,6 +29,7 @@ list(REMOVE_ITEM LLVM_AVAILABLE_LIBS LTO LLVM) + # that we wish to use + # llvm_map_components_to_libnames(llvm_libs support core irreader) + llvm_map_components_to_libnames(llvm_libs all) ++list(REMOVE_ITEM llvm_libs "LTO") + + # Link against LLVM libraries + target_link_libraries(llvmlite ${llvm_libs}) +diff --git a/ffi/build.py b/ffi/build.py +index 9169d35..41a9a40 100755 +--- a/ffi/build.py ++++ b/ffi/build.py +@@ -24,7 +24,7 @@ def try_cmake(cmake_dir, build_dir, generator): + old_dir = os.getcwd() + try: + os.chdir(build_dir) +- subprocess.check_call(['cmake', '-G', generator, cmake_dir]) ++ subprocess.check_call(['cmake', '-G', generator, '-D', 'LLVM_DIR=$LLVM/lib/cmake/llvm', cmake_dir]) + finally: + os.chdir(old_dir) + +@@ -57,6 +57,7 @@ def find_win32_generator(): + if is_64bit: + generator += ' Win64' + build_dir = tempfile.mkdtemp() ++ generator = 'MinGW Makefiles' + print("Trying generator %r" % (generator,)) + try: + try_cmake(cmake_dir, build_dir, generator) +@@ -78,7 +79,7 @@ def main_win32(): + # Run configuration step + try_cmake(here_dir, build_dir, generator) + subprocess.check_call(['cmake', '--build', build_dir, '--config', config]) +- shutil.copy(os.path.join(build_dir, config, 'llvmlite.dll'), target_dir) ++ shutil.copy(os.path.join(build_dir, 'libllvmlite.dll'), os.path.join(target_dir, 'llvmlite.dll')) + + + def main_posix(kind, library_ext): diff --git a/artiq-fast/default.nix b/artiq-fast/default.nix index b47f86a..5329b71 100644 --- a/artiq-fast/default.nix +++ b/artiq-fast/default.nix @@ -106,6 +106,10 @@ let inherit (llvm-or1k) version; src = llvm-or1k.llvm-src; }; + conda-windows-llvmlite-artiq = import ./conda-windows/llvmlite-artiq.nix { + inherit pkgs conda-windows-llvm-or1k; + inherit (llvmlite-artiq) version src; + }; }; in mainPackages // boardPackages