Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might have noticed my patch is not in that repo either. Actually you can get a commit in any fork on github from the main repo.

5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions include/version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <string_view>

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
2 changes: 1 addition & 1 deletion lwtnn
Submodule lwtnn updated 1 files
+8 −3 CMakeLists.txt
18 changes: 16 additions & 2 deletions src/correctionlib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,24 @@ def setup_merge(subparsers):
return parser


def config(console: Console, args: argparse.Namespace) -> int:
def _artifact_base_dir():
Comment thread
nsmith- marked this conversation as resolved.
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 = []
Expand Down
28 changes: 25 additions & 3 deletions tests/test_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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()
Loading