Unverified Commit efb24d6f authored by Zexin Yuan's avatar Zexin Yuan
Browse files

python3Packages.warp-lang: replace patch with substituteInPlace

parent 50a96edd
Loading
Loading
Loading
Loading
+0 −15
Original line number Diff line number Diff line
diff --git a/warp/build_dll.py b/warp/build_dll.py
index 2218ff13..3fcf5796 100644
--- a/warp/build_dll.py
+++ b/warp/build_dll.py
@@ -404,8 +404,8 @@ def build_dll_for_arch(args, dll_path, cpp_paths, cu_path, arch, libs: Optional[
         cuda_compiler = "clang++" if getattr(args, "clang_build_toolchain", False) else "nvcc"
         cpp_compiler = "clang++" if getattr(args, "clang_build_toolchain", False) else "g++"
 
-        cpp_includes = f' -I"{warp_home_path.parent}/external/llvm-project/out/install/{mode}-{arch}/include"'
-        cpp_includes += f' -I"{warp_home_path.parent}/_build/host-deps/llvm-project/release-{arch}/include"'
+        cpp_includes = ' -I"@LLVM_DEV@/include"'
+        cpp_includes += ' -I"@LIBCLANG_DEV@/include"'
         cuda_includes = f' -I"{cuda_home}/include"' if cu_path else ""
         includes = cpp_includes + cuda_includes
+0 −28
Original line number Diff line number Diff line
diff --git a/warp/build_dll.py b/warp/build_dll.py
index 11d2a898..33fb2a76 100644
--- a/warp/build_dll.py
+++ b/warp/build_dll.py
@@ -636,8 +636,8 @@ def build_dll_for_arch(args, dll_path, cpp_paths, cu_path, arch, libs: list[str]
 
     else:
         # Unix compilation
-        cuda_compiler = "clang++" if getattr(args, "clang_build_toolchain", False) else "nvcc"
-        cpp_compiler = "clang++" if getattr(args, "clang_build_toolchain", False) else "g++"
+        cuda_compiler = "@CLANG@" if getattr(args, "clang_build_toolchain", False) else "nvcc"
+        cpp_compiler = "@CLANG@" if getattr(args, "clang_build_toolchain", False) else "g++"
 
         cpp_includes = f' -I"{warp_home_path.parent}/external/llvm-project/out/install/{mode}-{arch}/include"'
         cpp_includes += f' -I"{warp_home_path.parent}/_build/host-deps/llvm-project/release-{arch}/include"'
@@ -687,9 +687,9 @@ def build_dll_for_arch(args, dll_path, cpp_paths, cu_path, arch, libs: list[str]
             else:
                 # Use Clang compiler
                 if mode == "debug":
-                    cuda_cmd = f'clang++ -Werror -Wuninitialized -Wno-unknown-cuda-version {" ".join(clang_opts)} -g -O0 -fPIC -fvisibility=hidden -D_DEBUG -D_ITERATOR_DEBUG_LEVEL=0 -DWP_ENABLE_CUDA=1 -I"{native_dir}" -D{mathdx_enabled} {libmathdx_includes} -o "{cu_out}" -c "{cu_path}"'
+                    cuda_cmd = f'@CLANG@ -Werror -Wuninitialized -Wno-unknown-cuda-version {" ".join(clang_opts)} -g -O0 -fPIC -fvisibility=hidden -D_DEBUG -D_ITERATOR_DEBUG_LEVEL=0 -DWP_ENABLE_CUDA=1 -I"{native_dir}" -D{mathdx_enabled} {libmathdx_includes} -o "{cu_out}" -c "{cu_path}"'
                 elif mode == "release":
-                    cuda_cmd = f'clang++ -Werror -Wuninitialized -Wno-unknown-cuda-version {" ".join(clang_opts)} -O3 -fPIC -fvisibility=hidden -DNDEBUG -DWP_ENABLE_CUDA=1 -I"{native_dir}" -D{mathdx_enabled} {libmathdx_includes} -o "{cu_out}" -c "{cu_path}"'
+                    cuda_cmd = f'@CLANG@ -Werror -Wuninitialized -Wno-unknown-cuda-version {" ".join(clang_opts)} -O3 -fPIC -fvisibility=hidden -DNDEBUG -DWP_ENABLE_CUDA=1 -I"{native_dir}" -D{mathdx_enabled} {libmathdx_includes} -o "{cu_out}" -c "{cu_path}"'
 
             with ScopedTimer("build_cuda", active=args.verbose):
                 run_cmd(cuda_cmd)
+0 −25
Original line number Diff line number Diff line
diff --git a/build_llvm.py b/build_llvm.py
index aee0a9f1..5e1c3557 100644
--- a/build_llvm.py
+++ b/build_llvm.py
@@ -171,7 +171,6 @@ def build_llvm_clang_from_source_for_arch(args, arch: str, llvm_source: str) ->
         "-D", "LLVM_INCLUDE_TESTS=FALSE",
         "-D", "LLVM_INCLUDE_TOOLS=TRUE",  # Needed by Clang
         "-D", "LLVM_INCLUDE_UTILS=FALSE",
-        "-D", f"CMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=0 {abi_version}",  # The pre-C++11 ABI is still the default on the CentOS 7 toolchain
         "-D", f"CMAKE_INSTALL_PREFIX={install_path}",
         "-D", f"LLVM_HOST_TRIPLE={host_triple}",
         "-D", f"CMAKE_OSX_ARCHITECTURES={osx_architectures}",
diff --git a/warp/build_dll.py b/warp/build_dll.py
index 2218ff13..2354f69f 100644
--- a/warp/build_dll.py
+++ b/warp/build_dll.py
@@ -417,7 +417,7 @@ def build_dll_for_arch(args, dll_path, cpp_paths, cu_path, arch, libs: Optional[
             else:
                 version = ""
 
-        cpp_flags = f'-Werror -Wuninitialized {version} --std=c++17 -fno-rtti -D{cuda_enabled} -D{mathdx_enabled} -D{cuda_compat_enabled} -fPIC -fvisibility=hidden -D_GLIBCXX_USE_CXX11_ABI=0 -I"{native_dir}" {includes} '
+        cpp_flags = f'-Werror -Wuninitialized {version} --std=c++17 -fno-rtti -D{cuda_enabled} -D{mathdx_enabled} -D{cuda_compat_enabled} -fPIC -fvisibility=hidden -I"{native_dir}" {includes} '
 
         if mode == "debug":
             cpp_flags += "-O0 -g -D_DEBUG -DWP_ENABLE_DEBUG=1 -fkeep-inline-functions"
+0 −12
Original line number Diff line number Diff line
diff --git a/warp/build_dll.py b/warp/build_dll.py
index 2218ff13..53786017 100644
--- a/warp/build_dll.py
+++ b/warp/build_dll.py
@@ -441,6 +442,7 @@ def build_dll_for_arch(args, dll_path, cpp_paths, cu_path, arch, libs: Optional[
                 build_cmd = f'{cpp_compiler} {cpp_flags} -c "{cpp_path}" -o "{cpp_out}"'
                 run_cmd(build_cmd)
 
+        ld_inputs.append('-L"@LIBCXX_LIB@/lib" -lc++')
         if cu_path:
             cu_out = cu_path + ".o"
 
+77 −74
Original line number Diff line number Diff line
@@ -62,80 +62,83 @@ buildPythonPackage {
    hash = "sha256-Atp3WyxQ7GYwWLmQIUgoPULyVlNjduh4/9CBixNWFwc=";
  };

  patches = [
    ./cxx11-abi.patch
  ]
  ++ lib.optionals effectiveStdenv.hostPlatform.isDarwin [
    (replaceVars ./darwin-libcxx.patch {
      LIBCXX_LIB = llvmPackages.libcxx;
    })

  patches =
    lib.optionals effectiveStdenv.hostPlatform.isDarwin [
      ./darwin-single-target.patch
    ]
  ++ lib.optionals (effectiveStdenv.cc.isClang || standaloneSupport) [
    (replaceVars ./clang-path.patch {
      CLANG = "${effectiveStdenv.cc}/bin/cc";
    })

    (replaceVars ./clang-libs.patch {
      LLVM_DEV = llvmPackages.llvm.dev;
      LIBCLANG_DEV = llvmPackages.libclang.dev;
    })
  ]
    ++ lib.optionals standaloneSupport [
    (replaceVars ./llvm-libs.patch {
      (replaceVars ./dynamic-link.patch {
        LLVM_LIB = llvmPackages.llvm.lib;
        LIBCLANG_LIB = llvmPackages.libclang.lib;
      })
    ];

  postPatch =
    # Patch build_dll.py to use our gencode flags rather than NVIDIA's very broad defaults.
    lib.optionalString cudaSupport ''
      nixLog "patching $PWD/warp/build_dll.py to use our gencode flags"
  postPatch = ''
    nixLog "patching $PWD/build_llvm.py to remove pre-C++11 ABI flag"
    substituteInPlace "$PWD/build_llvm.py" \
      --replace-fail \
        '"-D", f"CMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=0 {abi_version}",  # The pre-C++11 ABI is still the default on the CentOS 7 toolchain' \
        ""

    substituteInPlace "$PWD/warp/build_dll.py" \
      --replace-fail " -D_GLIBCXX_USE_CXX11_ABI=0" ""
  ''
  + lib.optionalString effectiveStdenv.hostPlatform.isDarwin (
    ''
      nixLog "patching $PWD/warp/build_dll.py to link against libc++"
      substituteInPlace "$PWD/warp/build_dll.py" \
        --replace-fail 'ld_inputs = []' "ld_inputs = ['-L\"${llvmPackages.libcxx}/lib\" -lc++']"
    ''
    # AssertionError: 0.4082476496696472 != 0.40824246406555176 within 5 places
    + ''
      nixLog "patching $PWD/warp/tests/test_fem.py to disable broken tests on darwin"
      substituteInPlace "$PWD/warp/tests/test_codegen.py" \
        --replace-fail 'places=5' 'places=4'
    ''
  )
  + lib.optionalString effectiveStdenv.cc.isClang ''
    substituteInPlace "$PWD/warp/build_dll.py" \
      --replace-fail "clang++" "${effectiveStdenv.cc}/bin/cc"
  ''
  + lib.optionalString standaloneSupport ''
    substituteInPlace "$PWD/warp/build_dll.py" \
      --replace-fail \
          '*gencode_opts,' \
          '${
            lib.concatMapStringsSep ", " (gencodeString: ''"${gencodeString}"'') cudaPackages.flags.gencode
          },' \
        '-I"{warp_home_path.parent}/external/llvm-project/out/install/{mode}-{arch}/include"' \
        '-I"${llvmPackages.llvm.dev}/include"' \
      --replace-fail \
          '*clang_arch_flags,' \
          '${
            lib.concatMapStringsSep ", " (
        '-I"{warp_home_path.parent}/_build/host-deps/llvm-project/release-{arch}/include"' \
        '-I"${llvmPackages.libclang.dev}/include"' \

  ''
  # Patch build_dll.py to use our gencode flags rather than NVIDIA's very broad defaults.
  + lib.optionalString cudaSupport (
    let
      gencodeOpts = lib.concatMapStringsSep ", " (
        gencodeString: ''"${gencodeString}"''
      ) cudaPackages.flags.gencode;

      clangArchFlags = lib.concatMapStringsSep ", " (
        realArch: ''"--cuda-gpu-arch=${realArch}"''
            ) cudaPackages.flags.realArches
          },'
      ) cudaPackages.flags.realArches;
    in
    ''
      nixLog "patching $PWD/warp/build_dll.py to use our gencode flags"
      substituteInPlace "$PWD/warp/build_dll.py" \
        --replace-fail '*gencode_opts,' '${gencodeOpts},' \
        --replace-fail '*clang_arch_flags,' '${clangArchFlags},'
    ''
    # Patch build_dll.py to use dynamic libraries rather than static ones.
    # NOTE: We do not patch the `nvptxcompiler_static` path because it is not available as a dynamic library.
    + lib.optionalString cudaSupport ''
    + ''
      nixLog "patching $PWD/warp/build_dll.py to use dynamic libraries"
      substituteInPlace "$PWD/warp/build_dll.py" \
        --replace-fail \
          '-lcudart_static' \
          '-lcudart' \
        --replace-fail \
          '-lnvrtc_static' \
          '-lnvrtc' \
        --replace-fail \
          '-lnvrtc-builtins_static' \
          '-lnvrtc-builtins' \
        --replace-fail \
          '-lnvJitLink_static' \
          '-lnvJitLink' \
        --replace-fail \
          '-lmathdx_static' \
          '-lmathdx'
    ''
    # AssertionError: 0.4082476496696472 != 0.40824246406555176 within 5 places
    + lib.optionalString effectiveStdenv.hostPlatform.isDarwin ''
      nixLog "patching $PWD/warp/tests/test_fem.py to disable broken tests on darwin"
      substituteInPlace "$PWD/warp/tests/test_codegen.py" \
        --replace-fail \
          'places=5' \
          'places=4'
        --replace-fail '-lcudart_static' '-lcudart' \
        --replace-fail '-lnvrtc_static' '-lnvrtc' \
        --replace-fail '-lnvrtc-builtins_static' '-lnvrtc-builtins' \
        --replace-fail '-lnvJitLink_static' '-lnvJitLink' \
        --replace-fail '-lmathdx_static' '-lmathdx'
    ''
  )
  # These tests fail on CPU and CUDA.
  + ''
    nixLog "patching $PWD/warp/tests/test_reload.py to disable broken tests"
Loading