-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
python3Packages.taichi: init at 1.7.3 #370780
Open
arunoruto
wants to merge
1
commit into
NixOS:master
Choose a base branch
from
arunoruto:taichi
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
{ | ||
lib, | ||
fetchFromGitHub, | ||
buildPythonPackage, | ||
autoPatchelfHook, | ||
versionCheckHook, | ||
autoAddDriverRunpath, | ||
llvmPackages_15, | ||
cmake, | ||
ninja, | ||
setuptools, | ||
wheel, | ||
pybind11, | ||
scikit-build, | ||
git, | ||
pythonImportsCheckHook, | ||
pythonCatchConflictsHook, | ||
|
||
colorama, | ||
dill, | ||
matplotlib, | ||
numpy, | ||
rich, | ||
|
||
cudaPackages, | ||
elfutils, | ||
libbfd, | ||
libdwarf, | ||
libffi, | ||
libGL, | ||
libX11, | ||
libXrandr, | ||
libXinerama, | ||
libXcursor, | ||
libXi, | ||
libxml2, | ||
vulkan-headers, | ||
vulkan-loader, | ||
|
||
gtest, | ||
pytest, | ||
|
||
config, | ||
cudaSupport ? config.cudaSupport, | ||
rocmSupport ? config.rocmSupport, | ||
stdenv, | ||
enableMetal ? stdenv.isDarwin, | ||
enableOpenGL ? stdenv.isLinux, | ||
enableVulkan ? stdenv.isLinux, | ||
}: | ||
let | ||
pname = "taichi"; | ||
version = "1.7.3"; | ||
src = fetchFromGitHub { | ||
owner = "taichi-dev"; | ||
repo = pname; | ||
tag = "v${version}"; | ||
hash = "sha256-QWtxPgR8RGnIEpbGO18Y8TFNhbKd4pOi9VLEkK2nhfk="; | ||
fetchSubmodules = true; | ||
# leaveDotGit = true; | ||
}; | ||
|
||
llvmPackages = llvmPackages_15; | ||
libllvm = llvmPackages.libllvm; | ||
stdenv = llvmPackages.stdenv; | ||
|
||
platformLibs = | ||
lib.optionals cudaSupport [ cudaPackages.cudatoolkit ] | ||
++ lib.optionals enableMetal [ ] | ||
++ lib.optionals rocmSupport [ ] | ||
++ lib.optionals enableVulkan [ | ||
vulkan-loader | ||
vulkan-headers | ||
] | ||
++ lib.optionals enableOpenGL [ libGL ]; | ||
|
||
# If the flag is a boolean, we'll pass "ON" or "OFF" to CMake. | ||
# Otherwise, we'll pass the value of the flag. | ||
cmakeFlag = | ||
cflag: flag: | ||
"-D" + cflag + "=" + (if (lib.typeOf flag == "bool") then (if flag then "ON" else "OFF") else flag); | ||
|
||
cmakeFlags = lib.attrsets.mapAttrsToList (name: value: (cmakeFlag name value)) { | ||
TI_BUILD_EXAMPLES = true; | ||
TI_BUILD_RHI_EXAMPLES = true; | ||
TI_BUILD_TESTS = true; | ||
TI_WITH_BACKTRACE = stdenv.isLinux; | ||
TI_WITH_C_API = true; | ||
TI_WITH_GGUI = true; | ||
TI_WITH_STATIC_C_API = with stdenv; (isDarwin && isAarch64); | ||
TI_WITH_PYTHON = true; | ||
TI_WITH_AMDGPU = rocmSupport; | ||
TI_WITH_CUDA = cudaSupport; | ||
TI_WITH_CUDA_TOOLKIT = false; | ||
TI_WITH_LLVM = true; | ||
TI_WITH_METAL = enableMetal; | ||
TI_WITH_OPENGL = enableOpenGL; | ||
TI_WITH_VULKAN = enableVulkan; | ||
|
||
# Should be resolved with buildinputs, not as a flag! | ||
LIBDWARF_INCLUDE_DIR = "${lib.getInclude libdwarf}/include"; | ||
}; | ||
|
||
# The echos are for debugging purposes | ||
# Can be removed later | ||
preConfigure = '' | ||
echo "CUDA: ${builtins.toString cudaSupport}" | ||
echo "Metal: ${builtins.toString enableMetal}" | ||
echo "ROCm: ${builtins.toString rocmSupport}" | ||
|
||
echo "OpenGL: ${builtins.toString enableOpenGL}" | ||
echo "Vulkan: ${builtins.toString enableVulkan}" | ||
|
||
echo "Platform libs: ${builtins.toString platformLibs}" | ||
|
||
git init | ||
git config user.email "[email protected]" | ||
git commit -m "initial commit" --allow-empty | ||
git describe --match=DummyTagNotExisting --always --abbrev=40 --dirty | ||
# echo "${src.gitRepoUrl}" | ||
# git clone --no-checkout --depth 1 --branch ${src.tag} ${src.gitRepoUrl} ./tmp | ||
# cp -t ./tmp/.git . | ||
# rm -rf ./tmp | ||
''; | ||
|
||
taichi = stdenv.mkDerivation { | ||
inherit | ||
pname | ||
version | ||
src | ||
cmakeFlags | ||
preConfigure | ||
; | ||
|
||
propagatedNativeBuildInputs = [ | ||
autoPatchelfHook | ||
cmake | ||
pybind11 | ||
git | ||
] ++ lib.optionals cudaSupport [ autoAddDriverRunpath ]; | ||
|
||
propagatedBuildInputs = [ | ||
elfutils | ||
libbfd | ||
libdwarf | ||
libdwarf.dev | ||
libffi.dev | ||
libxml2.dev | ||
|
||
libX11 | ||
libXrandr | ||
libXinerama | ||
libXcursor | ||
libXi | ||
|
||
libllvm | ||
] ++ platformLibs; | ||
|
||
# See https://github.com/NixOS/nixpkgs/issues/144170 | ||
# Taken from original PR, | ||
# maybe this is more future proof: | ||
# https://github.com/NixOS/nixpkgs/issues/144170#issuecomment-1423195220 | ||
postPatch = '' | ||
substituteInPlace \ | ||
external/SPIRV-Headers/SPIRV-Headers.pc.in \ | ||
external/SPIRV-Cross/pkg-config/spirv-cross-c-shared.pc.in \ | ||
external/SPIRV-Tools/cmake/SPIRV-Tools.pc.in \ | ||
external/SPIRV-Tools/cmake/SPIRV-Tools-shared.pc.in \ | ||
--replace-warn '$'{prefix}/@CMAKE_INSTALL_LIBDIR@ @CMAKE_INSTALL_FULL_LIBDIR@ \ | ||
--replace-warn '$'{prefix}/@CMAKE_INSTALL_INCLUDEDIR@ @CMAKE_INSTALL_FULL_INCLUDEDIR@ | ||
''; | ||
|
||
doCheck = true; | ||
nativeCheckInputs = [ gtest ]; | ||
}; | ||
in | ||
buildPythonPackage { | ||
inherit | ||
pname | ||
version | ||
src | ||
cmakeFlags | ||
stdenv | ||
preConfigure | ||
; | ||
|
||
nativeBuildInputs = | ||
[ | ||
ninja | ||
numpy | ||
scikit-build | ||
setuptools | ||
wheel | ||
] | ||
++ lib.optionals (stdenv.hostPlatform == stdenv.buildPlatform) [ | ||
pythonImportsCheckHook | ||
pythonCatchConflictsHook | ||
]; | ||
|
||
buildInputs = [ | ||
taichi | ||
]; | ||
|
||
dependencies = [ | ||
colorama | ||
dill | ||
matplotlib | ||
numpy | ||
rich | ||
]; | ||
|
||
postConfigure = '' | ||
cd .. | ||
''; | ||
|
||
# This is needed for the libraries like opengl and vulkan to be found at runtime | ||
preInstallCheck = '' | ||
shopt -s globstar | ||
|
||
for file in $out/**/*.so; do | ||
patchelf --add-rpath "${lib.makeLibraryPath platformLibs}" "$file" | ||
done | ||
''; | ||
|
||
dontUseNinjaCheck = true; | ||
|
||
nativeCheckInputs = [ pytest ]; | ||
nativeInstallCheckInputs = [ versionCheckHook ]; | ||
|
||
pythonImportsCheck = [ "taichi" ]; | ||
|
||
meta = { | ||
description = "Productive & portable high-performance programming in Python"; | ||
homepage = "https://github.com/taichi-dev/taichi"; | ||
license = lib.licenses.asl20; | ||
maintainers = with lib.maintainers; [ arunoruto ]; | ||
platforms = [ | ||
"x86_64-linux" | ||
"x86_64-darwin" | ||
"aarch64-darwin" | ||
]; | ||
mainProgram = "ti"; | ||
arunoruto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use rec instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only point I am not sure how to do.
Most attributes are needed both in the taichi cmake build phase (compiling the c-api) and the taichi python packaging in
buildPythonPackage
. If I usedrec
, I would have to maintain everything twice 🤔