diff --git a/.gitmodules b/.gitmodules index 5083c4e..c755479 100644 --- a/.gitmodules +++ b/.gitmodules @@ -15,4 +15,4 @@ url = https://github.com/Cyan4973/xxHash.git [submodule "lwtnn"] path = lwtnn - url = https://github.com/lwtnn/lwtnn.git + url = https://github.com/sbein/lwtnn.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 3491301..80ab6af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,10 +4,13 @@ if(NOT SKBUILD_PROJECT_VERSION) set(SKBUILD_PROJECT_VERSION "0.0.0") # provided by scikit-build-core endif() string(REPLACE "." ";" VERSION_SPLIT ${SKBUILD_PROJECT_VERSION}) +set(CORRECTIONLIB_SKBUILD_PROJECT_VERSION "${SKBUILD_PROJECT_VERSION}") list(GET VERSION_SPLIT 0 SPLIT_VERSION_MAJOR) list(GET VERSION_SPLIT 1 SPLIT_VERSION_MINOR) project(correctionlib VERSION ${SPLIT_VERSION_MAJOR}.${SPLIT_VERSION_MINOR} LANGUAGES CXX) +set(CORRECTIONLIB_VERSION_MAJOR "${correctionlib_VERSION_MAJOR}") +set(CORRECTIONLIB_VERSION_MINOR "${correctionlib_VERSION_MINOR}") option(BUILD_DEMO "Build demo program" ON) @@ -61,8 +64,8 @@ if(MSVC) target_compile_options(correctionlib PRIVATE /Zc:__cplusplus /utf-8) else() target_compile_options(correctionlib PRIVATE -Wall -Wextra -Wpedantic -Werror) -target_link_libraries(correctionlib PRIVATE lwtnn-stat) endif() +target_link_libraries(correctionlib PRIVATE lwtnn-stat) if(ZLIB_FOUND) target_link_libraries(correctionlib PRIVATE ZLIB::ZLIB) endif() diff --git a/include/version.h.in b/include/version.h.in index 2e87d6d..b73f84c 100644 --- a/include/version.h.in +++ b/include/version.h.in @@ -4,9 +4,9 @@ #include namespace correction { - constexpr std::string_view correctionlib_version{"@SKBUILD_PROJECT_VERSION@"}; - constexpr int correctionlib_major_version{@correctionlib_VERSION_MAJOR@}; - constexpr int correctionlib_minor_version{@correctionlib_VERSION_MINOR@}; + constexpr std::string_view correctionlib_version{"@CORRECTIONLIB_SKBUILD_PROJECT_VERSION@"}; + constexpr int correctionlib_major_version{@CORRECTIONLIB_VERSION_MAJOR@}; + constexpr int correctionlib_minor_version{@CORRECTIONLIB_VERSION_MINOR@}; } #endif // CORRECTIONLIB_VERSION_H diff --git a/lwtnn b/lwtnn index 8243609..7056a15 160000 --- a/lwtnn +++ b/lwtnn @@ -1 +1 @@ -Subproject commit 82436098bf76f9784fd89e2c760355bc40cec35c +Subproject commit 7056a1524b07d97d5376f72c20030f831c0dffff diff --git a/src/correctionlib/cli.py b/src/correctionlib/cli.py index ae3c26f..d187332 100644 --- a/src/correctionlib/cli.py +++ b/src/correctionlib/cli.py @@ -152,10 +152,24 @@ def setup_merge(subparsers): return parser -def config(console: Console, args: argparse.Namespace) -> int: +def _artifact_base_dir(): + from pathlib import Path + + import correctionlib._core as _core + + # Prefer extension-module path in editable installs, since headers live with built artifacts, not the source tree. + # Prevents failure in test_cmake_static_compilation: fatal error: correction.h: No such file or directory + base = Path(_core.__file__).resolve().parent + if (base / "cmake").exists() and (base / "include").exists(): + return base + from .util import this_module_path - base_dir = this_module_path() + return this_module_path() + + +def config(console: Console, args: argparse.Namespace) -> int: + base_dir = _artifact_base_dir() incdir = base_dir / "include" libdir = base_dir / "lib" out = [] diff --git a/tests/test_binding.py b/tests/test_binding.py index 853ccf1..4125b2e 100644 --- a/tests/test_binding.py +++ b/tests/test_binding.py @@ -90,9 +90,13 @@ def test_cmake_static_compilation(csetstr: str): with open(cmake, "w") as f: f.write(CMAKELIST_SRC) testprog = os.path.join(tmpdir, "test.cc") - # SKBUILD_PROJECT_VERSION only includes major.minor.patch - # it also trims any prerelease suffixes - versionstr = ".".join(map(str, correctionlib.version.__version_tuple__[:3])) + + # SKBUILD_PROJECT_VERSION stores the normalized base version and trims + # any prerelease/dev suffixes, so mirror that behavior here. + from packaging.version import Version + + versionstr = Version(correctionlib.version.version).base_version + with open(testprog, "w") as f: f.write(TESTPROG_SRC % (versionstr, csetstr)) flags = ( @@ -114,3 +118,21 @@ def test_cmake_static_compilation(csetstr: str): subprocess.run( [os.path.join(tmpdir, prog)], capture_output=True, check=True, cwd=tmpdir ) + + +def test_cli_config_paths(): + import subprocess + from pathlib import Path + + incdir = Path( + subprocess.check_output(["correction", "config", "--incdir"]).decode().strip() + ) + cmakeflag = ( + subprocess.check_output(["correction", "config", "--cmake"]).decode().strip() + ) + cmakedir = Path(cmakeflag.split("=", 1)[1]) + + assert incdir.exists() + assert (incdir / "correction.h").exists() + assert cmakedir.exists() + assert (cmakedir / "correctionlibConfig.cmake").exists()