Skip to content

Commit 1d7cf36

Browse files
tariChromeos LUCI
authored andcommitted
zmake: allow specifying EXTRA_CFLAGS
The Zephyr build system supports passing extra CFLAGS via CMake, which is useful for experimenting with compiler options. Add an option to zmake which allows this to be passed through when configuring a build. BUG=b:223044986 TEST=EXTRA_CFLAGS is set in generated cmake configurations when used BRANCH=none Signed-off-by: Peter Marheine <pmarheine@chromium.org> Change-Id: I3fca24ada4cdcfe442d610c93ae7f60137764dfa Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3535542 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
1 parent 9e85143 commit 1d7cf36

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

zephyr/zmake/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Chromium OS's meta-build tool for Zephyr
3535

3636
### zmake configure
3737

38-
**Usage:** `zmake configure [-h] [-b] [--test] [-t TOOLCHAIN] [--bringup] [--clobber] [--allow-warnings] [-B BUILD_DIR] [-c] (-a | --host-tests-only | project_name [project_name ...])`
38+
**Usage:** `zmake configure [-h] [-b] [--test] [-t TOOLCHAIN] [--bringup] [--clobber] [--allow-warnings] [-B BUILD_DIR] [-c] [--extra-cflags EXTRA_CFLAGS] (-a | --host-tests-only | project_name [project_name ...])`
3939

4040
#### Positional Arguments
4141

@@ -56,12 +56,13 @@ Chromium OS's meta-build tool for Zephyr
5656
| `--allow-warnings` | Do not treat warnings as errors |
5757
| `-B BUILD_DIR`, `--build-dir BUILD_DIR` | Root build directory, project files will be in ${build_dir}/${project_name} |
5858
| `-c`, `--coverage` | Enable CONFIG_COVERAGE Kconfig. |
59+
| `--extra-cflags EXTRA_CFLAGS` | Additional CFLAGS to use for target builds |
5960
| `-a`, `--all` | Select all projects |
6061
| `--host-tests-only` | Select all test projects |
6162

6263
### zmake build
6364

64-
**Usage:** `zmake build [-h] [-t TOOLCHAIN] [--bringup] [--clobber] [--allow-warnings] [-B BUILD_DIR] [-c] (-a | --host-tests-only | project_name [project_name ...])`
65+
**Usage:** `zmake build [-h] [-t TOOLCHAIN] [--bringup] [--clobber] [--allow-warnings] [-B BUILD_DIR] [-c] [--extra-cflags EXTRA_CFLAGS] (-a | --host-tests-only | project_name [project_name ...])`
6566

6667
#### Positional Arguments
6768

@@ -80,6 +81,7 @@ Chromium OS's meta-build tool for Zephyr
8081
| `--allow-warnings` | Do not treat warnings as errors |
8182
| `-B BUILD_DIR`, `--build-dir BUILD_DIR` | Root build directory, project files will be in ${build_dir}/${project_name} |
8283
| `-c`, `--coverage` | Enable CONFIG_COVERAGE Kconfig. |
84+
| `--extra-cflags EXTRA_CFLAGS` | Additional CFLAGS to use for target builds |
8385
| `-a`, `--all` | Select all projects |
8486
| `--host-tests-only` | Select all test projects |
8587

@@ -102,7 +104,7 @@ Chromium OS's meta-build tool for Zephyr
102104

103105
### zmake test
104106

105-
**Usage:** `zmake test [-h] [--no-rebuild] [-t TOOLCHAIN] [--bringup] [--clobber] [--allow-warnings] [-B BUILD_DIR] [-c] (-a | --host-tests-only | project_name [project_name ...])`
107+
**Usage:** `zmake test [-h] [--no-rebuild] [-t TOOLCHAIN] [--bringup] [--clobber] [--allow-warnings] [-B BUILD_DIR] [-c] [--extra-cflags EXTRA_CFLAGS] (-a | --host-tests-only | project_name [project_name ...])`
106108

107109
#### Positional Arguments
108110

@@ -122,6 +124,7 @@ Chromium OS's meta-build tool for Zephyr
122124
| `--allow-warnings` | Do not treat warnings as errors |
123125
| `-B BUILD_DIR`, `--build-dir BUILD_DIR` | Root build directory, project files will be in ${build_dir}/${project_name} |
124126
| `-c`, `--coverage` | Enable CONFIG_COVERAGE Kconfig. |
127+
| `--extra-cflags EXTRA_CFLAGS` | Additional CFLAGS to use for target builds |
125128
| `-a`, `--all` | Select all projects |
126129
| `--host-tests-only` | Select all test projects |
127130

zephyr/zmake/zmake/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ def add_common_configure_args(sub_parser: argparse.ArgumentParser):
300300
dest="coverage",
301301
help="Enable CONFIG_COVERAGE Kconfig.",
302302
)
303+
sub_parser.add_argument(
304+
"--extra-cflags",
305+
help="Additional CFLAGS to use for target builds",
306+
)
303307
group = sub_parser.add_mutually_exclusive_group(required=True)
304308
group.add_argument(
305309
"-a",

zephyr/zmake/zmake/zmake.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ def configure(
225225
allow_warnings=False,
226226
all_projects=False,
227227
host_tests_only=False,
228+
extra_cflags=None,
228229
):
229230
"""Locate and configure the specified projects."""
230231
# Resolve build_dir if needed.
@@ -248,6 +249,7 @@ def configure(
248249
bringup=bringup,
249250
coverage=coverage,
250251
allow_warnings=allow_warnings,
252+
extra_cflags=extra_cflags,
251253
)
252254
)
253255
if self._sequential:
@@ -288,6 +290,7 @@ def build(
288290
allow_warnings=False,
289291
all_projects=False,
290292
host_tests_only=False,
293+
extra_cflags=None,
291294
):
292295
"""Locate and build the specified projects."""
293296
return self.configure(
@@ -300,6 +303,7 @@ def build(
300303
allow_warnings=allow_warnings,
301304
all_projects=all_projects,
302305
host_tests_only=host_tests_only,
306+
extra_cflags=extra_cflags,
303307
build_after_configure=True,
304308
)
305309

@@ -314,6 +318,7 @@ def test(
314318
allow_warnings=False,
315319
all_projects=False,
316320
host_tests_only=False,
321+
extra_cflags=None,
317322
no_rebuild=False,
318323
):
319324
"""Locate and build the specified projects."""
@@ -328,6 +333,7 @@ def test(
328333
allow_warnings=allow_warnings,
329334
all_projects=all_projects,
330335
host_tests_only=host_tests_only,
336+
extra_cflags=extra_cflags,
331337
test_after_configure=True,
332338
)
333339
# Resolve build_dir if needed.
@@ -403,6 +409,7 @@ def _configure(
403409
bringup=False,
404410
coverage=False,
405411
allow_warnings=False,
412+
extra_cflags=None,
406413
):
407414
"""Set up a build directory to later be built by "zmake build"."""
408415
# Resolve build_dir if needed.
@@ -460,6 +467,10 @@ def _configure(
460467
base_config |= zmake.build_config.BuildConfig(
461468
cmake_defs={"ALLOW_WARNINGS": "ON"}
462469
)
470+
if extra_cflags:
471+
base_config |= zmake.build_config.BuildConfig(
472+
cmake_defs={"EXTRA_CFLAGS": extra_cflags},
473+
)
463474
if self.goma:
464475
base_config |= zmake.build_config.BuildConfig(
465476
cmake_defs={

0 commit comments

Comments
 (0)