Skip to content
Open
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
7 changes: 6 additions & 1 deletion cibuildwheel/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from typing import Literal, Self, get_args

from cibuildwheel.logger import log
from cibuildwheel.util.helpers import parse_key_value_string
from cibuildwheel.typing import PathOrStr
from cibuildwheel.util.helpers import parse_key_value_string, prepare_command

BuildFrontendName = Literal["pip", "build", "build[uv]", "uv"]

Expand Down Expand Up @@ -58,6 +59,10 @@ def _split_config_settings(config_settings: str) -> list[str]:
return [f"-C{setting}" for setting in config_settings_list]


def prepare_config_settings(config_settings: str, *, project: PathOrStr, package: PathOrStr) -> str:
return prepare_command(config_settings, project=project, package=package)


# Based on build.__main__.main.
def parse_config_settings(config_settings_str: str) -> dict[str, str | list[str]]:
config_settings: dict[str, str | list[str]] = {}
Expand Down
18 changes: 15 additions & 3 deletions cibuildwheel/platforms/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@

from cibuildwheel import errors, platforms # pylint: disable=cyclic-import
from cibuildwheel.architecture import Architecture, arch_synonym
from cibuildwheel.frontend import get_build_frontend_extra_flags, parse_config_settings
from cibuildwheel.frontend import (
get_build_frontend_extra_flags,
parse_config_settings,
prepare_config_settings,
)
from cibuildwheel.logger import log
from cibuildwheel.options import BuildOptions, Options
from cibuildwheel.selector import BuildSelector
Expand Down Expand Up @@ -463,7 +467,11 @@ def build_wheel(state: BuildState) -> Path:
*get_build_frontend_extra_flags(
state.options.build_frontend,
state.options.build_verbosity,
state.options.config_settings,
prepare_config_settings(
state.options.config_settings,
project=".",
package=state.options.package_dir,
),
py38=False,
),
env=state.android_env,
Expand All @@ -481,7 +489,11 @@ def build_wheel(state: BuildState) -> Path:
*get_build_frontend_extra_flags(
state.options.build_frontend,
state.options.build_verbosity,
state.options.config_settings,
prepare_config_settings(
state.options.config_settings,
project=".",
package=state.options.package_dir,
),
py38=False,
),
env=state.android_env,
Expand Down
12 changes: 10 additions & 2 deletions cibuildwheel/platforms/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
from cibuildwheel import errors
from cibuildwheel.architecture import Architecture
from cibuildwheel.environment import ParsedEnvironment
from cibuildwheel.frontend import BuildFrontendName, get_build_frontend_extra_flags
from cibuildwheel.frontend import (
BuildFrontendName,
get_build_frontend_extra_flags,
prepare_config_settings,
)
from cibuildwheel.logger import log
from cibuildwheel.options import Options
from cibuildwheel.platforms.macos import install_cpython as install_build_cpython
Expand Down Expand Up @@ -477,7 +481,11 @@ def build(options: Options, tmp_path: Path) -> None:
extra_flags = get_build_frontend_extra_flags(
build_frontend,
build_options.build_verbosity,
build_options.config_settings,
prepare_config_settings(
build_options.config_settings,
project=".",
package=build_options.package_dir,
),
py38=False,
)

Expand Down
8 changes: 6 additions & 2 deletions cibuildwheel/platforms/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from cibuildwheel import errors
from cibuildwheel.architecture import Architecture
from cibuildwheel.frontend import get_build_frontend_extra_flags
from cibuildwheel.frontend import get_build_frontend_extra_flags, prepare_config_settings
from cibuildwheel.logger import log
from cibuildwheel.oci_container import OCIContainer, OCIContainerEngineConfig, OCIPlatform
from cibuildwheel.options import BuildOptions, Options
Expand Down Expand Up @@ -276,7 +276,11 @@ def build_in_container(
extra_flags = get_build_frontend_extra_flags(
build_frontend,
build_options.build_verbosity,
build_options.config_settings,
prepare_config_settings(
build_options.config_settings,
project=container_project_path,
package=container_package_dir,
),
py38=config.identifier[1:].startswith("p38"),
)

Expand Down
12 changes: 10 additions & 2 deletions cibuildwheel/platforms/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
from cibuildwheel.architecture import Architecture
from cibuildwheel.ci import detect_ci_provider
from cibuildwheel.environment import ParsedEnvironment
from cibuildwheel.frontend import BuildFrontendName, get_build_frontend_extra_flags
from cibuildwheel.frontend import (
BuildFrontendName,
get_build_frontend_extra_flags,
prepare_config_settings,
)
from cibuildwheel.logger import log
from cibuildwheel.options import Options
from cibuildwheel.selector import BuildSelector
Expand Down Expand Up @@ -477,7 +481,11 @@ def build(options: Options, tmp_path: Path) -> None:
extra_flags = get_build_frontend_extra_flags(
build_frontend,
build_options.build_verbosity,
build_options.config_settings,
prepare_config_settings(
build_options.config_settings,
project=".",
package=build_options.package_dir,
),
py38=config.identifier[1:].startswith("p38"),
)

Expand Down
8 changes: 6 additions & 2 deletions cibuildwheel/platforms/pyodide.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from cibuildwheel import errors
from cibuildwheel.architecture import Architecture
from cibuildwheel.environment import ParsedEnvironment
from cibuildwheel.frontend import get_build_frontend_extra_flags
from cibuildwheel.frontend import get_build_frontend_extra_flags, prepare_config_settings
from cibuildwheel.logger import log
from cibuildwheel.options import Options
from cibuildwheel.selector import BuildSelector
Expand Down Expand Up @@ -424,7 +424,11 @@ def build(options: Options, tmp_path: Path) -> None:
extra_flags = get_build_frontend_extra_flags(
build_frontend,
build_options.build_verbosity,
build_options.config_settings,
prepare_config_settings(
build_options.config_settings,
project=".",
package=build_options.package_dir,
),
py38=False,
)

Expand Down
12 changes: 10 additions & 2 deletions cibuildwheel/platforms/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
from cibuildwheel import errors
from cibuildwheel.architecture import Architecture
from cibuildwheel.environment import ParsedEnvironment
from cibuildwheel.frontend import BuildFrontendName, get_build_frontend_extra_flags
from cibuildwheel.frontend import (
BuildFrontendName,
get_build_frontend_extra_flags,
prepare_config_settings,
)
from cibuildwheel.logger import log
from cibuildwheel.options import Options
from cibuildwheel.selector import BuildSelector
Expand Down Expand Up @@ -462,7 +466,11 @@ def build(options: Options, tmp_path: Path) -> None:
extra_flags = get_build_frontend_extra_flags(
build_frontend,
build_options.build_verbosity,
build_options.config_settings,
prepare_config_settings(
build_options.config_settings,
project=".",
package=options.globals.package_dir,
),
py38=config.identifier[1:].startswith("p38"),
)

Expand Down
11 changes: 11 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@ Specify config settings for the build backend. Each space separated
item will be passed via `--config-setting`. In TOML, you can specify
a table of items, including arrays.

You can use the `{project}` or `{package}` placeholders in `config-settings`
to refer to the project root or package being built, respectively.

!!! tip
Currently, "build" supports arrays for options, but "pip" only supports
single values.
Expand All @@ -575,6 +578,14 @@ Platform-specific environment variables also available:<br/>
CIBW_CONFIG_SETTINGS: "--build-option=--use-mypyc"
```

```yaml
CIBW_CONFIG_SETTINGS_LINUX: "setup-args=--cross-file={project}/cross_file.txt"
```
Comment thread
henryiii marked this conversation as resolved.

```yaml
CIBW_CONFIG_SETTINGS: "editable-verbose=true source-dir={package}"
```




Expand Down
26 changes: 25 additions & 1 deletion unit_test/options_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

from cibuildwheel import errors
from cibuildwheel.bashlex_eval import local_environment_executor
from cibuildwheel.frontend import BuildFrontendConfig, get_build_frontend_extra_flags
from cibuildwheel.frontend import (
BuildFrontendConfig,
get_build_frontend_extra_flags,
prepare_config_settings,
)
from cibuildwheel.logger import Logger
from cibuildwheel.options import (
CommandLineArguments,
Expand Down Expand Up @@ -638,6 +642,26 @@ def test_get_build_frontend_extra_flags_warning(
mock_warning.assert_called_once()


@pytest.mark.parametrize(
("config_settings", "expected"),
[
(
"setup-args=--cross-file={project}/meson_cross_files/windows-386.ini",
"setup-args=--cross-file=C:/project/meson_cross_files/windows-386.ini",
),
(
"setup-args=--cross-file={package}/meson_cross_files/windows-386.ini",
"setup-args=--cross-file=C:/project/pkg/meson_cross_files/windows-386.ini",
),
],
)
def test_prepare_config_settings(config_settings: str, expected: str) -> None:
assert (
prepare_config_settings(config_settings, project="C:/project", package="C:/project/pkg")
== expected
)


@pytest.mark.parametrize(
("definition", "expected_args"),
[
Expand Down
Loading