Skip to content

Commit e9b6e2c

Browse files
authored
Fix to windows-latest MSVC lwtnn linkage (#334)
* Fix correction config paths for editable installs * Link lwtnn-stat on MSVC builds * Added comment about editable configuration check and ran formatting * Match pre-commit import ordering in test_binding * updating spooky spaces that might be causing a problem? * Preserve correctionlib version variables across lwtnn subproject * updating version call * Update lwtnn submodule for MSVC warning flags * Point lwtnn submodule to fork for MSVC fix validation
1 parent 5c9aa7a commit e9b6e2c

6 files changed

Lines changed: 50 additions & 11 deletions

File tree

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
url = https://github.com/Cyan4973/xxHash.git
1616
[submodule "lwtnn"]
1717
path = lwtnn
18-
url = https://github.com/lwtnn/lwtnn.git
18+
url = https://github.com/sbein/lwtnn.git

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ if(NOT SKBUILD_PROJECT_VERSION)
44
set(SKBUILD_PROJECT_VERSION "0.0.0") # provided by scikit-build-core
55
endif()
66
string(REPLACE "." ";" VERSION_SPLIT ${SKBUILD_PROJECT_VERSION})
7+
set(CORRECTIONLIB_SKBUILD_PROJECT_VERSION "${SKBUILD_PROJECT_VERSION}")
78
list(GET VERSION_SPLIT 0 SPLIT_VERSION_MAJOR)
89
list(GET VERSION_SPLIT 1 SPLIT_VERSION_MINOR)
910

1011
project(correctionlib VERSION ${SPLIT_VERSION_MAJOR}.${SPLIT_VERSION_MINOR} LANGUAGES CXX)
12+
set(CORRECTIONLIB_VERSION_MAJOR "${correctionlib_VERSION_MAJOR}")
13+
set(CORRECTIONLIB_VERSION_MINOR "${correctionlib_VERSION_MINOR}")
1114

1215
option(BUILD_DEMO "Build demo program" ON)
1316

@@ -61,8 +64,8 @@ if(MSVC)
6164
target_compile_options(correctionlib PRIVATE /Zc:__cplusplus /utf-8)
6265
else()
6366
target_compile_options(correctionlib PRIVATE -Wall -Wextra -Wpedantic -Werror)
64-
target_link_libraries(correctionlib PRIVATE lwtnn-stat)
6567
endif()
68+
target_link_libraries(correctionlib PRIVATE lwtnn-stat)
6669
if(ZLIB_FOUND)
6770
target_link_libraries(correctionlib PRIVATE ZLIB::ZLIB)
6871
endif()

include/version.h.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#include <string_view>
55

66
namespace correction {
7-
constexpr std::string_view correctionlib_version{"@SKBUILD_PROJECT_VERSION@"};
8-
constexpr int correctionlib_major_version{@correctionlib_VERSION_MAJOR@};
9-
constexpr int correctionlib_minor_version{@correctionlib_VERSION_MINOR@};
7+
constexpr std::string_view correctionlib_version{"@CORRECTIONLIB_SKBUILD_PROJECT_VERSION@"};
8+
constexpr int correctionlib_major_version{@CORRECTIONLIB_VERSION_MAJOR@};
9+
constexpr int correctionlib_minor_version{@CORRECTIONLIB_VERSION_MINOR@};
1010
}
1111

1212
#endif // CORRECTIONLIB_VERSION_H

lwtnn

src/correctionlib/cli.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,24 @@ def setup_merge(subparsers):
152152
return parser
153153

154154

155-
def config(console: Console, args: argparse.Namespace) -> int:
155+
def _artifact_base_dir():
156+
from pathlib import Path
157+
158+
import correctionlib._core as _core
159+
160+
# Prefer extension-module path in editable installs, since headers live with built artifacts, not the source tree.
161+
# Prevents failure in test_cmake_static_compilation: fatal error: correction.h: No such file or directory
162+
base = Path(_core.__file__).resolve().parent
163+
if (base / "cmake").exists() and (base / "include").exists():
164+
return base
165+
156166
from .util import this_module_path
157167

158-
base_dir = this_module_path()
168+
return this_module_path()
169+
170+
171+
def config(console: Console, args: argparse.Namespace) -> int:
172+
base_dir = _artifact_base_dir()
159173
incdir = base_dir / "include"
160174
libdir = base_dir / "lib"
161175
out = []

tests/test_binding.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,13 @@ def test_cmake_static_compilation(csetstr: str):
9090
with open(cmake, "w") as f:
9191
f.write(CMAKELIST_SRC)
9292
testprog = os.path.join(tmpdir, "test.cc")
93-
# SKBUILD_PROJECT_VERSION only includes major.minor.patch
94-
# it also trims any prerelease suffixes
95-
versionstr = ".".join(map(str, correctionlib.version.__version_tuple__[:3]))
93+
94+
# SKBUILD_PROJECT_VERSION stores the normalized base version and trims
95+
# any prerelease/dev suffixes, so mirror that behavior here.
96+
from packaging.version import Version
97+
98+
versionstr = Version(correctionlib.version.version).base_version
99+
96100
with open(testprog, "w") as f:
97101
f.write(TESTPROG_SRC % (versionstr, csetstr))
98102
flags = (
@@ -114,3 +118,21 @@ def test_cmake_static_compilation(csetstr: str):
114118
subprocess.run(
115119
[os.path.join(tmpdir, prog)], capture_output=True, check=True, cwd=tmpdir
116120
)
121+
122+
123+
def test_cli_config_paths():
124+
import subprocess
125+
from pathlib import Path
126+
127+
incdir = Path(
128+
subprocess.check_output(["correction", "config", "--incdir"]).decode().strip()
129+
)
130+
cmakeflag = (
131+
subprocess.check_output(["correction", "config", "--cmake"]).decode().strip()
132+
)
133+
cmakedir = Path(cmakeflag.split("=", 1)[1])
134+
135+
assert incdir.exists()
136+
assert (incdir / "correction.h").exists()
137+
assert cmakedir.exists()
138+
assert (cmakedir / "correctionlibConfig.cmake").exists()

0 commit comments

Comments
 (0)