Skip to content

Commit 735b665

Browse files
committed
feat: move some cmake options to build section
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 2942230 commit 735b665

File tree

7 files changed

+214
-52
lines changed

7 files changed

+214
-52
lines changed

Diff for: README.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ cmake.args = []
167167
# A table of defines to pass to CMake when configuring the project. Additive.
168168
cmake.define = {}
169169

170-
# Verbose printout when building.
171-
cmake.verbose = false
170+
# DEPRECATED in 0.10, use build.verbose instead.
171+
cmake.verbose = ""
172172

173173
# The build type to use when building the project. Valid options are: "Debug",
174174
# "Release", "RelWithDebInfo", "MinSizeRel", "", etc.
@@ -178,9 +178,8 @@ cmake.build-type = "Release"
178178
# the native builder (not the setuptools plugin).
179179
cmake.source-dir = "."
180180

181-
# The build targets to use when building the project. Empty builds the default
182-
# target.
183-
cmake.targets = []
181+
# DEPRECATED in 0.10; use build.targets instead.
182+
cmake.targets = ""
184183

185184
# DEPRECATED in 0.8; use version instead.
186185
ninja.minimum-version = ""
@@ -275,6 +274,13 @@ editable.rebuild = false
275274
# Extra args to pass directly to the builder in the build step.
276275
build.tool-args = []
277276

277+
# The build targets to use when building the project. Empty builds the default
278+
# target.
279+
build.targets = []
280+
281+
# Verbose printout when building.
282+
build.verbose = false
283+
278284
# The components to install. If empty, all default components are installed.
279285
install.components = []
280286

Diff for: src/scikit_build_core/builder/builder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ def build(self, build_args: Sequence[str]) -> None:
244244

245245
self.config.build(
246246
build_args=build_args,
247-
targets=self.settings.cmake.targets,
248-
verbose=self.settings.cmake.verbose,
247+
targets=self.settings.build.targets,
248+
verbose=self.settings.build.verbose,
249249
)
250250

251251
def install(self, install_dir: Path | None) -> None:

Diff for: src/scikit_build_core/resources/scikit-build.schema.json

+19-3
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
},
7272
"verbose": {
7373
"type": "boolean",
74-
"default": false,
75-
"description": "Verbose printout when building."
74+
"description": "DEPRECATED in 0.10, use build.verbose instead.",
75+
"deprecated": true
7676
},
7777
"build-type": {
7878
"type": "string",
@@ -89,7 +89,8 @@
8989
"items": {
9090
"type": "string"
9191
},
92-
"description": "The build targets to use when building the project. Empty builds the default target."
92+
"description": "DEPRECATED in 0.10; use build.targets instead.",
93+
"deprecated": true
9394
}
9495
}
9596
},
@@ -263,6 +264,18 @@
263264
"type": "string"
264265
},
265266
"description": "Extra args to pass directly to the builder in the build step."
267+
},
268+
"targets": {
269+
"type": "array",
270+
"items": {
271+
"type": "string"
272+
},
273+
"description": "The build targets to use when building the project. Empty builds the default target."
274+
},
275+
"verbose": {
276+
"type": "boolean",
277+
"default": false,
278+
"description": "Verbose printout when building."
266279
}
267280
}
268281
},
@@ -500,6 +513,9 @@
500513
"properties": {
501514
"tool-args": {
502515
"$ref": "#/$defs/inherit"
516+
},
517+
"targets": {
518+
"$ref": "#/$defs/inherit"
503519
}
504520
}
505521
},

Diff for: src/scikit_build_core/settings/skbuild_model.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ class CMakeSettings:
5353
A table of defines to pass to CMake when configuring the project. Additive.
5454
"""
5555

56-
verbose: bool = False
56+
verbose: Optional[bool] = None
5757
"""
58-
Verbose printout when building.
58+
DEPRECATED in 0.10, use build.verbose instead.
5959
"""
6060

6161
build_type: str = "Release"
@@ -71,10 +71,9 @@ class CMakeSettings:
7171
affects the native builder (not the setuptools plugin).
7272
"""
7373

74-
targets: List[str] = dataclasses.field(default_factory=list)
74+
targets: Optional[List[str]] = None
7575
"""
76-
The build targets to use when building the project. Empty builds the
77-
default target.
76+
DEPRECATED in 0.10; use build.targets instead.
7877
"""
7978

8079

@@ -240,6 +239,17 @@ class BuildSettings:
240239
Extra args to pass directly to the builder in the build step.
241240
"""
242241

242+
targets: List[str] = dataclasses.field(default_factory=list)
243+
"""
244+
The build targets to use when building the project. Empty builds the
245+
default target.
246+
"""
247+
248+
verbose: bool = False
249+
"""
250+
Verbose printout when building.
251+
"""
252+
243253

244254
@dataclasses.dataclass
245255
class InstallSettings:

Diff for: src/scikit_build_core/settings/skbuild_read_settings.py

+66-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import re
99
import sys
1010
from pathlib import Path
11-
from typing import TYPE_CHECKING, Any
11+
from typing import TYPE_CHECKING, Any, TypeVar
1212

1313
from packaging.specifiers import SpecifierSet
1414
from packaging.version import Version
@@ -32,6 +32,9 @@ def __dir__() -> list[str]:
3232
return __all__
3333

3434

35+
T = TypeVar("T")
36+
37+
3538
def strtobool(value: str) -> bool:
3639
"""
3740
Converts a environment variable string into a boolean value.
@@ -191,6 +194,51 @@ def _handle_minimum_version(
191194
dc.version = SpecifierSet(f">={dc.minimum_version}")
192195

193196

197+
def _handle_move(
198+
before_name: str,
199+
before: T | None,
200+
after_name: str,
201+
after: T,
202+
minimum_version: Version | None,
203+
introduced_in: Version,
204+
) -> T:
205+
"""
206+
Backward_compat for moving names around. The default must be false-like.
207+
"""
208+
209+
if after and minimum_version is not None and minimum_version < introduced_in:
210+
rich_print(
211+
f"[red][bold]ERROR:[/bold] Cannot set {after_name} if minimum-version is set to less than {introduced_in} (which is where it was introduced)"
212+
)
213+
raise SystemExit(7)
214+
215+
if (
216+
before is not None
217+
and minimum_version is not None
218+
and minimum_version >= introduced_in
219+
):
220+
rich_print(
221+
f"[red][bold]ERROR:[/bold] Cannot set {before_name} if minimum-version is set to {introduced_in} or higher"
222+
)
223+
raise SystemExit(7)
224+
225+
if before is not None and after:
226+
rich_print(
227+
f"[red][bold]ERROR:[/bold] Cannot set {before_name} and {after_name} at the same time"
228+
)
229+
raise SystemExit(7)
230+
231+
if before is None:
232+
return after
233+
234+
if minimum_version is None:
235+
rich_print(
236+
f"[yellow][bold]WARNING:[/bold] Use {after_name} instead of {before_name} for scikit-build-core >= {introduced_in}"
237+
)
238+
239+
return before
240+
241+
194242
def inherit_join(
195243
value: list[str] | dict[str, str] | str | int | bool,
196244
previous: list[str] | dict[str, str] | str | int | bool | None,
@@ -336,6 +384,23 @@ def __init__(
336384
_handle_minimum_version(self.settings.cmake, self.settings.minimum_version)
337385
_handle_minimum_version(self.settings.ninja, self.settings.minimum_version)
338386

387+
self.settings.build.verbose = _handle_move(
388+
"cmake.verbose",
389+
self.settings.cmake.verbose,
390+
"build.verbose",
391+
self.settings.build.verbose,
392+
self.settings.minimum_version,
393+
Version("0.10"),
394+
)
395+
self.settings.build.targets = _handle_move(
396+
"cmake.targets",
397+
self.settings.cmake.targets,
398+
"build.targets",
399+
self.settings.build.targets,
400+
self.settings.minimum_version,
401+
Version("0.10"),
402+
)
403+
339404
def unrecognized_options(self) -> Generator[str, None, None]:
340405
return self.sources.unrecognized_options(ScikitBuildSettings)
341406

Diff for: tests/test_builder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def test_build_tool_args():
142142
)
143143
tmpbuilder.build(["a"])
144144
config.build.assert_called_once_with(
145-
build_args=["a", "--", "b"], targets=[], verbose=settings.cmake.verbose
145+
build_args=["a", "--", "b"], targets=[], verbose=settings.build.verbose
146146
)
147147

148148

0 commit comments

Comments
 (0)