Skip to content

Commit 6a16d42

Browse files
committed
Ch
1 parent af28533 commit 6a16d42

File tree

10 files changed

+47
-19
lines changed

10 files changed

+47
-19
lines changed

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@
1515
},
1616
"editor.defaultFormatter": "charliermarsh.ruff"
1717
},
18-
"cmake.ignoreCMakeListsMissing": true
18+
"cmake.ignoreCMakeListsMissing": true,
19+
"files.associations": {
20+
"*.md": "markdown",
21+
"xstring": "cpp"
22+
}
1923
}

cppython/build/backend.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,23 @@ def _inject_toolchain(config_settings: dict[str, Any] | None, toolchain_file: Pa
2828
settings = dict(config_settings) if config_settings else {}
2929

3030
if toolchain_file and toolchain_file.exists():
31-
# scikit-build-core accepts cmake.define.VAR_NAME format
32-
toolchain_key = 'cmake.define.CMAKE_TOOLCHAIN_FILE'
33-
34-
# Don't override if user explicitly set a toolchain file
35-
if toolchain_key not in settings:
36-
settings[toolchain_key] = str(toolchain_file.absolute())
37-
logger.info('CPPython: Injected CMAKE_TOOLCHAIN_FILE=%s', toolchain_file)
31+
# scikit-build-core accepts cmake.args for passing CMake arguments
32+
# Using cmake.args passes the toolchain via -DCMAKE_TOOLCHAIN_FILE=...
33+
args_key = 'cmake.args'
34+
toolchain_arg = f'-DCMAKE_TOOLCHAIN_FILE={toolchain_file.absolute()}'
35+
36+
# Append to existing args or create new
37+
if args_key in settings:
38+
existing = settings[args_key]
39+
# Check if toolchain is already specified
40+
if 'CMAKE_TOOLCHAIN_FILE' not in existing:
41+
settings[args_key] = f'{existing};{toolchain_arg}'
42+
logger.info('CPPython: Appended CMAKE_TOOLCHAIN_FILE to cmake.args')
43+
else:
44+
logger.info('CPPython: User-specified toolchain file takes precedence')
3845
else:
39-
logger.info(
40-
'CPPython: User-specified toolchain file takes precedence: %s',
41-
settings[toolchain_key],
42-
)
46+
settings[args_key] = toolchain_arg
47+
logger.info('CPPython: Injected CMAKE_TOOLCHAIN_FILE=%s', toolchain_file)
4348

4449
return settings
4550

cppython/plugins/conan/plugin.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def _install_dependencies(self, *, update: bool = False, groups: list[str] | Non
8787
raise ProviderInstallationError('conan', f'Failed to prepare {operation} environment: {e}', e) from e
8888

8989
try:
90-
build_types = ['Release', 'Debug']
90+
build_types = self.data.build_types
9191
for build_type in build_types:
9292
logger.info('Installing dependencies for build type: %s', build_type)
9393
self._run_conan_install(conanfile_path, update, build_type, logger)
@@ -161,6 +161,13 @@ def _run_conan_install(self, conanfile_path: Path, update: bool, build_type: str
161161
# Build conan install command arguments
162162
command_args = ['install', str(conanfile_path)]
163163

164+
# Use build_path as the output folder directly
165+
output_folder = self.core_data.cppython_data.build_path
166+
command_args.extend(['--output-folder', str(output_folder)])
167+
168+
# Override cmake_layout's default 'build' subfolder to normalize path structure
169+
command_args.extend(['-c', 'tools.cmake.cmake_layout:build_folder=.'])
170+
164171
# Add build missing flag
165172
command_args.extend(['--build', 'missing'])
166173

@@ -276,6 +283,8 @@ def _create_cmake_sync_data(self) -> CMakeSyncData:
276283
Returns:
277284
CMakeSyncData configured for Conan integration
278285
"""
286+
# With tools.cmake.cmake_layout:build_folder=. and --output-folder=build_path,
287+
# generators are placed directly in build_path/generators/
279288
conan_toolchain_path = self.core_data.cppython_data.build_path / 'generators' / 'conan_toolchain.cmake'
280289

281290
return CMakeSyncData(

cppython/plugins/conan/resolution.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,5 @@ def resolve_conan_data(data: dict[str, Any], core_data: CorePluginData) -> Conan
123123
remotes=parsed_data.remotes,
124124
skip_upload=parsed_data.skip_upload,
125125
profile_dir=profile_dir,
126+
build_types=parsed_data.build_types,
126127
)

cppython/plugins/conan/schema.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ class ConanData(CPPythonModel):
295295
remotes: list[str]
296296
skip_upload: bool
297297
profile_dir: Path
298+
build_types: list[str]
298299

299300

300301
class ConanfileGenerationData(CPPythonModel):
@@ -328,3 +329,13 @@ class ConanConfiguration(CPPythonModel):
328329
"If a relative path is provided, it will be resolved relative to the tool's working directory."
329330
),
330331
] = 'profiles'
332+
build_types: Annotated[
333+
list[str],
334+
Field(
335+
alias='build-types',
336+
description='List of CMake build types to install dependencies for. '
337+
'For multi-config generators (Visual Studio), use both Release and Debug. '
338+
'For single-config generators or build backends like scikit-build-core, '
339+
'use only the build type you need (e.g., ["Release"]).',
340+
),
341+
] = ['Release', 'Debug']

examples/conan_cmake/extension/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.15...3.30)
1+
cmake_minimum_required(VERSION 4.0)
22
project(example_extension LANGUAGES CXX)
33

44
# Find Python and nanobind (nanobind will be found via Conan toolchain)

examples/conan_cmake/extension/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ dependencies = ["fmt>=11.0.2", "nanobind>=2.4.0"]
2727

2828
[tool.cppython.providers.conan]
2929
# Conan provider configuration
30+
# Only install Release build type for scikit-build-core (single-config builds)
31+
build-types = ["Release"]

examples/conan_cmake/extension/src/example_extension/_core.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include <nanobind/nanobind.h>
9+
#include <nanobind/stl/string.h>
910
#include <fmt/core.h>
1011

1112
namespace nb = nanobind;

examples/conan_cmake/library/pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ install-path = "install"
1717

1818
dependencies = ["fmt>=12.1.0"]
1919

20-
[tool.cppython.generators.cmake]
21-
cmake_binary = "C:/Program Files/CMake/bin/cmake.exe"
2220

2321
[tool.cppython.providers.conan]
2422

examples/conan_cmake/simple/pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ install-path = "install"
1717

1818
dependencies = ["fmt>=12.1.0"]
1919

20-
[tool.cppython.generators.cmake]
21-
cmake_binary = "C:/Program Files/CMake/bin/cmake.exe"
22-
2320
[tool.cppython.providers.conan]
2421

2522
[tool.pdm]

0 commit comments

Comments
 (0)