Skip to content

Commit

Permalink
feat: move some cmake options to build section (#793)
Browse files Browse the repository at this point in the history
Fix #747.

Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Jul 6, 2024
1 parent 2440c45 commit 3287d2c
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 52 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ cmake.args = []
# A table of defines to pass to CMake when configuring the project. Additive.
cmake.define = {}

# Verbose printout when building.
cmake.verbose = false
# DEPRECATED in 0.10, use build.verbose instead.
cmake.verbose = ""

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

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

# The versions of Ninja to allow. If Ninja is not present on the system or does
# not pass this specifier, it will be downloaded via PyPI if possible. An empty
Expand Down Expand Up @@ -269,6 +268,13 @@ editable.rebuild = false
# Extra args to pass directly to the builder in the build step.
build.tool-args = []

# The build targets to use when building the project. Empty builds the default
# target.
build.targets = []

# Verbose printout when building.
build.verbose = false

# The components to install. If empty, all default components are installed.
install.components = []

Expand Down
4 changes: 2 additions & 2 deletions src/scikit_build_core/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ def build(self, build_args: Sequence[str]) -> None:

self.config.build(
build_args=build_args,
targets=self.settings.cmake.targets,
verbose=self.settings.cmake.verbose,
targets=self.settings.build.targets,
verbose=self.settings.build.verbose,
)

def install(self, install_dir: Path | None) -> None:
Expand Down
22 changes: 19 additions & 3 deletions src/scikit_build_core/resources/scikit-build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
},
"verbose": {
"type": "boolean",
"default": false,
"description": "Verbose printout when building."
"description": "DEPRECATED in 0.10, use build.verbose instead.",
"deprecated": true
},
"build-type": {
"type": "string",
Expand All @@ -89,7 +89,8 @@
"items": {
"type": "string"
},
"description": "The build targets to use when building the project. Empty builds the default target."
"description": "DEPRECATED in 0.10; use build.targets instead.",
"deprecated": true
}
}
},
Expand Down Expand Up @@ -263,6 +264,18 @@
"type": "string"
},
"description": "Extra args to pass directly to the builder in the build step."
},
"targets": {
"type": "array",
"items": {
"type": "string"
},
"description": "The build targets to use when building the project. Empty builds the default target."
},
"verbose": {
"type": "boolean",
"default": false,
"description": "Verbose printout when building."
}
}
},
Expand Down Expand Up @@ -500,6 +513,9 @@
"properties": {
"tool-args": {
"$ref": "#/$defs/inherit"
},
"targets": {
"$ref": "#/$defs/inherit"
}
}
},
Expand Down
20 changes: 15 additions & 5 deletions src/scikit_build_core/settings/skbuild_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class CMakeSettings:
A table of defines to pass to CMake when configuring the project. Additive.
"""

verbose: bool = False
verbose: Optional[bool] = None
"""
Verbose printout when building.
DEPRECATED in 0.10, use build.verbose instead.
"""

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

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


Expand Down Expand Up @@ -240,6 +239,17 @@ class BuildSettings:
Extra args to pass directly to the builder in the build step.
"""

targets: List[str] = dataclasses.field(default_factory=list)
"""
The build targets to use when building the project. Empty builds the
default target.
"""

verbose: bool = False
"""
Verbose printout when building.
"""


@dataclasses.dataclass
class InstallSettings:
Expand Down
67 changes: 66 additions & 1 deletion src/scikit_build_core/settings/skbuild_read_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import re
import sys
from pathlib import Path
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, TypeVar

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


T = TypeVar("T")


def strtobool(value: str) -> bool:
"""
Converts a environment variable string into a boolean value.
Expand Down Expand Up @@ -191,6 +194,51 @@ def _handle_minimum_version(
dc.version = SpecifierSet(f">={dc.minimum_version}")


def _handle_move(
before_name: str,
before: T | None,
after_name: str,
after: T,
minimum_version: Version | None,
introduced_in: Version,
) -> T:
"""
Backward_compat for moving names around. The default must be false-like.
"""

if after and minimum_version is not None and minimum_version < introduced_in:
rich_print(
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)"
)
raise SystemExit(7)

if (
before is not None
and minimum_version is not None
and minimum_version >= introduced_in
):
rich_print(
f"[red][bold]ERROR:[/bold] Cannot set {before_name} if minimum-version is set to {introduced_in} or higher"
)
raise SystemExit(7)

if before is not None and after:
rich_print(
f"[red][bold]ERROR:[/bold] Cannot set {before_name} and {after_name} at the same time"
)
raise SystemExit(7)

if before is None:
return after

if minimum_version is None:
rich_print(
f"[yellow][bold]WARNING:[/bold] Use {after_name} instead of {before_name} for scikit-build-core >= {introduced_in}"
)

return before


def inherit_join(
value: list[str] | dict[str, str] | str | int | bool,
previous: list[str] | dict[str, str] | str | int | bool | None,
Expand Down Expand Up @@ -336,6 +384,23 @@ def __init__(
_handle_minimum_version(self.settings.cmake, self.settings.minimum_version)
_handle_minimum_version(self.settings.ninja, self.settings.minimum_version)

self.settings.build.verbose = _handle_move(
"cmake.verbose",
self.settings.cmake.verbose,
"build.verbose",
self.settings.build.verbose,
self.settings.minimum_version,
Version("0.10"),
)
self.settings.build.targets = _handle_move(
"cmake.targets",
self.settings.cmake.targets,
"build.targets",
self.settings.build.targets,
self.settings.minimum_version,
Version("0.10"),
)

def unrecognized_options(self) -> Generator[str, None, None]:
return self.sources.unrecognized_options(ScikitBuildSettings)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_build_tool_args():
)
tmpbuilder.build(["a"])
config.build.assert_called_once_with(
build_args=["a", "--", "b"], targets=[], verbose=settings.cmake.verbose
build_args=["a", "--", "b"], targets=[], verbose=settings.build.verbose
)


Expand Down
Loading

0 comments on commit 3287d2c

Please sign in to comment.