Skip to content

Commit

Permalink
ifcopenshell: fix build and use relevant release
Browse files Browse the repository at this point in the history
By relevant release, I mean the ifcopenshell-python release, and not the blenderbim release
  • Loading branch information
autra committed Jul 23, 2024
1 parent f11a6a0 commit 640e0fc
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 16 deletions.
127 changes: 114 additions & 13 deletions pkgs/development/python-modules/ifcopenshell/default.nix
Original file line number Diff line number Diff line change
@@ -1,67 +1,168 @@
{
lib,
stdenv,
testers,
buildPythonPackage,
# fetchers
fetchFromGitHub,
gcc10,
# testers
runCommand,
# native dep
python3,
# build tools
cmake,
gcc10,
swig,
# dependencies
eigen,
boost179,
cgal,
gmp,
hdf5,
icu,
swig,
pcre,
libaec,
libxml2,
mpfr,
nlohmann_json,
opencascade-occt_7_6,
opencollada,
libxml2,
pcre,
zlib,
# for tests
# python deps
python3Packages,
setuptools,
build,
wheel,
}:
let
opencascade-occt = opencascade-occt_7_6;
in
buildPythonPackage rec {
pname = "ifcopenshell";
version = "240611";
version = "0.7.10";
format = "other";

src = fetchFromGitHub {
owner = "IfcOpenShell";
repo = "IfcOpenShell";
rev = "refs/tags/blenderbim-${version}";
rev = "refs/tags/ifcopenshell-python-${version}";
fetchSubmodules = true;
hash = "sha256-fCgxSambC01qb14EoZTrVxNNw8H3nX8oMi6gk0O/HmQ=";
hash = "";
};

nativeBuildInputs = [
gcc10
# c++
cmake
gcc10
swig
# python
build
python3
setuptools
wheel
];

pythonImportsCheck = [ "ifcopenshell" ];

buildInputs = [
# ifcopenshell needs stdc++
stdenv.cc.cc.lib
boost179
cgal
eigen
gmp
hdf5
icu
pcre
libaec
libxml2
mpfr
nlohmann_json
opencascade-occt
pcre
];

preConfigure = ''
cd cmake
'';

PYTHONUSERBASE = ".";

# We still build with python to generate ifcopenshell_wrapper.py and ifcopenshell_wrapper.so
cmakeFlags = [
"-DUSERSPACE_PYTHON_PREFIX=ON"
"-DBUILD_SHARED_LIBS=ON"
"-DBUILD_IFCPYTHON=ON"
"-DCITYJSON_SUPPORT=OFF"
"-DEIGEN_DIR=${eigen}/include/eigen3"
"-DJSON_INCLUDE_DIR=${nlohmann_json}/include/"
"-DOCC_INCLUDE_DIR=${opencascade-occt}/include/opencascade"
"-DOCC_LIBRARY_DIR=${opencascade-occt}/lib"
"-DOPENCOLLADA_INCLUDE_DIR=${opencollada}/include/opencollada"
"-DOPENCOLLADA_LIBRARY_DIR=${opencollada}/lib/opencollada"
"-DSWIG_EXECUTABLE=${swig}/bin/swig"
"-DLIBXML2_INCLUDE_DIR=${libxml2.dev}/include/libxml2"
"-DLIBXML2_LIBRARIES=${libxml2.out}/lib/libxml2${stdenv.hostPlatform.extensions.sharedLibrary}"
"-DGMP_LIBRARY_DIR=${gmp.out}/lib/"
"-DMPFR_LIBRARY_DIR=${mpfr.out}/lib/"
# HDF5 support is currently not optional, see https://github.com/IfcOpenShell/IfcOpenShell/issues/1815
"-DHDF5_SUPPORT=ON"
"-DHDF5_INCLUDE_DIR=${hdf5.dev}/include/"
"-DHDF5_LIBRARIES=${hdf5.out}/lib/libhdf5_cpp.so;${hdf5.out}/lib/libhdf5.so;${zlib.out}/lib/libz.so;${libaec.out}/lib/libaec.so;" # /usr/lib64/libsz.so;"
];

preConfigure = ''
pushd src/ifcopenshell-python
# The build process is here: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/ifcopenshell-python/Makefile#L131
# but we'd have to patch the copied pyproject.toml anyway, as the version is incorrect (even after their `make dist` btw), and the `where = ["dist"]` does not apply to us.
# so let's just create it from scratch
cat << EOF > pyproject.toml
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[project]
name = "ifcopenshell"
version = "${version}"
authors = [
{ name="Dion Moult", email="[email protected]" },
]
description = "Python bindings, utility functions, and high-level API for IfcOpenShell"
readme = "README.md"
requires-python = ">=3.6,<3.12"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)",
]
[project.optional-dependencies]
geometry = ["mathutils", "shapely"]
date = ["isodate"]
[project.urls]
"Homepage" = "http://ifcopenshell.org"
"Bug Tracker" = "https://github.com/ifcopenshell/ifcopenshell/issues"
[tool.setuptools.packages.find]
include = ["ifcopenshell*"]
[tool.setuptools.package-data]
ifcopenshell = ["*.pyd", "*.so", "*.json"]
"ifcopenshell.util" = ["*.json", "schema/*.ifc"]
EOF
# NOTE: the following is directly inspired by https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/ifcopenshell-python/Makefile#L131
# these 2 files are wrapper over a C api. They are put in the python3.12 in the ifcopenshell cmake build process folder
# because the default python3 is 3.11 at the time of writing this, but AFAIK there is nothing specific to 3.11 here.
# distutils cannot access anything outside the cwd, so hackishly swap out the README.md
cp README.md ../README.bak
cp ../../README.md README.md
popd
cd cmake
'';

meta = with lib; {
broken = stdenv.isDarwin;
description = "Open source IFC library and geometry engine";
homepage = "http://ifcopenshell.org/";
license = licenses.lgpl3;
maintainers = with maintainers; [ fehnomenal ];
};

passthru.tests = {
version = testers.testVersion {
# package = ifcopenshell;
command = "IfcConvert --version";
};
};
}
2 changes: 0 additions & 2 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8957,8 +8957,6 @@ with pkgs;

idle3tools = callPackage ../tools/system/idle3tools { };

ifcopenshell = with python3Packages; toPythonApplication ifcopenshell;

iftop = callPackage ../tools/networking/iftop { };

ifwifi = callPackage ../tools/networking/ifwifi {
Expand Down
4 changes: 3 additions & 1 deletion pkgs/top-level/python-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5804,7 +5804,9 @@ self: super: with self; {

ifconfig-parser = callPackage ../development/python-modules/ifconfig-parser { };

ifcopenshell = callPackage ../development/python-modules/ifcopenshell { };
ifcopenshell = callPackage ../development/python-modules/ifcopenshell {
inherit (pkgs) libxml2;
};

ignite = callPackage ../development/python-modules/ignite { };

Expand Down

0 comments on commit 640e0fc

Please sign in to comment.