Skip to content

Commit 3902c35

Browse files
Add configure script to set up a light-weight build environment (#26154)
* Add configure script to set up a light-weight build environment ... and optionally configure a GN build from environment variables and command line options. This simplifies building a CHIP app as a component within an existing buildroot style build system. Make the custom_toolchain build arg easier to use by interpreting relative paths as relative to ${build_root}/toolchain. Also move the declare_args statements for the 'custom' toolchain into a gni file so they can be discovered correctly. * Factor out python code into configure.utils.py Ensure //build_overrides/pigweed_environment.gni exists. Install wheel in the venv before installing dependencies. * Add chip-build-minimal docker image and minimal-build workflow The chip-build-minimal contains only the minimal build tools for compiling a CHIP app on Linux (c++ toolchain, python3, gn, ninja) and minimal library dependencies (openssl, glib). * Nits from code review * Update with latest zap version from master
1 parent 084eb3c commit 3902c35

File tree

15 files changed

+581
-28
lines changed

15 files changed

+581
-28
lines changed

.github/workflows/minimal-build.yaml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) 2023 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Minimal Build (Linux / configure)
16+
17+
on:
18+
push:
19+
pull_request:
20+
merge_group:
21+
22+
concurrency:
23+
group: ${{ github.ref }}-${{ github.workflow }}-${{ (github.event_name == 'pull_request' && github.event.number) || (github.event_name == 'workflow_dispatch' && github.run_number) || github.sha }}
24+
cancel-in-progress: true
25+
26+
jobs:
27+
minimal:
28+
name: Linux / configure build of all-clusters-app
29+
timeout-minutes: 60
30+
31+
if: github.actor != 'restyled-io[bot]'
32+
runs-on: ubuntu-latest
33+
34+
container:
35+
image: connectedhomeip/chip-build-minimal:0.7.2
36+
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v3
40+
- name: Checkout submodules
41+
run: scripts/checkout_submodules.py --allow-changing-global-git-config --shallow --platform linux
42+
- name: Configure and build All Clusters App
43+
timeout-minutes: 10
44+
run: |
45+
CC=gcc CXX=g++ scripts/configure --project=examples/all-clusters-app/linux && ./ninja-build

build/config/BUILDCONFIG.gn

+10-1
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,17 @@ if (host_toolchain == "") {
5757
}
5858
}
5959

60+
_custom_toolchain = {
61+
import("${_build_overrides.build_root}/toolchain/custom/custom.gni")
62+
}
63+
6064
if (_chip_defaults.custom_toolchain != "") {
61-
_default_toolchain = _chip_defaults.custom_toolchain
65+
if (filter_include([ _chip_defaults.custom_toolchain ], [ "/*" ]) == []) {
66+
# Interpret relative toolchain names relative to ${build_root}/toolchain/
67+
_default_toolchain = "${_build_overrides.build_root}/toolchain/${_chip_defaults.custom_toolchain}"
68+
} else {
69+
_default_toolchain = _chip_defaults.custom_toolchain
70+
}
6271
} else if (target_os == "all") {
6372
_default_toolchain = "${_pigweed_overrides.dir_pw_toolchain}/default"
6473
} else if (target_os == "linux") {

build/toolchain/custom/BUILD.gn

+1-11
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,9 @@
1414

1515
import("//build_overrides/build.gni")
1616
import("${build_root}/config/compiler/compiler.gni")
17+
import("${build_root}/toolchain/custom/custom.gni")
1718
import("${build_root}/toolchain/gcc_toolchain.gni")
1819

19-
declare_args() {
20-
# C compiler to use for target build.
21-
target_cc = ""
22-
23-
# C++ compiler to use for target build.
24-
target_cxx = ""
25-
26-
# Archive tool to use for target build.
27-
target_ar = ""
28-
}
29-
3020
gcc_toolchain("custom") {
3121
if (target_cc == "" || target_cxx == "" || target_ar == "") {
3222
assert(false,

build/toolchain/custom/custom.gni

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) 2023 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
declare_args() {
16+
# C compiler to use for target build.
17+
# Only relevant with custom_toolchain = "custom".
18+
target_cc = ""
19+
20+
# C++ compiler to use for target build.
21+
# Only relevant with custom_toolchain = "custom".
22+
target_cxx = ""
23+
24+
# Archive tool to use for target build.
25+
# Only relevant with custom_toolchain = "custom".
26+
target_ar = ""
27+
}

examples/build_overrides/pigweed_environment.gni

+17-8
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,20 @@ _bootstrap_root = "//third_party/connectedhomeip"
2020
import("${_bootstrap_root}/build_overrides/pigweed_environment.gni")
2121

2222
# Rebase paths to our root.
23-
pw_env_setup_CIPD_ARM =
24-
get_path_info("${_bootstrap_root}/${pw_env_setup_CIPD_ARM}", "abspath")
25-
pw_env_setup_CIPD_PIGWEED =
26-
get_path_info("${_bootstrap_root}/${pw_env_setup_CIPD_PIGWEED}", "abspath")
27-
pw_env_setup_CIPD_PYTHON =
28-
get_path_info("${_bootstrap_root}/${pw_env_setup_CIPD_PYTHON}", "abspath")
29-
pw_env_setup_VIRTUAL_ENV =
30-
get_path_info("${_bootstrap_root}/${pw_env_setup_VIRTUAL_ENV}", "abspath")
23+
if (defined(pw_env_setup_CIPD_ARM)) {
24+
pw_env_setup_CIPD_ARM =
25+
get_path_info("${_bootstrap_root}/${pw_env_setup_CIPD_ARM}", "abspath")
26+
}
27+
if (defined(pw_env_setup_CIPD_PIGWEED)) {
28+
pw_env_setup_CIPD_PIGWEED =
29+
get_path_info("${_bootstrap_root}/${pw_env_setup_CIPD_PIGWEED}",
30+
"abspath")
31+
}
32+
if (defined(pw_env_setup_CIPD_PYTHON)) {
33+
pw_env_setup_CIPD_PYTHON =
34+
get_path_info("${_bootstrap_root}/${pw_env_setup_CIPD_PYTHON}", "abspath")
35+
}
36+
if (defined(pw_env_setup_VIRTUAL_ENV)) {
37+
pw_env_setup_VIRTUAL_ENV =
38+
get_path_info("${_bootstrap_root}/${pw_env_setup_VIRTUAL_ENV}", "abspath")
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This minimal build image is intentionally not based on chip-build
2+
FROM ubuntu:focal
3+
4+
# ARG NINJA_VERSION=v1.11.1
5+
ARG GN_HASH=5a004f9427a050c6c393c07ddb85cba8ff3849fa
6+
7+
RUN set -x \
8+
&& apt-get update \
9+
&& DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \
10+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
11+
build-essential ca-certificates git pkg-config python3-venv ninja-build \
12+
&& git config --global advice.detachedHead false
13+
14+
# RUN set -x && cd /var/tmp \
15+
# && git clone --branch "$NINJA_VERSION" https://github.com/ninja-build/ninja.git \
16+
# && ( cd ninja && ./configure.py --bootstrap && install -m 0755 ninja /usr/local/bin/ ) \
17+
# && rm -rf ninja
18+
19+
RUN set -x && cd /var/tmp \
20+
&& git clone https://gn.googlesource.com/gn \
21+
&& ( cd gn && git checkout "$GN_HASH" && CXX=g++ build/gen.py && ninja -C out && install -m 0755 out/gn /usr/local/bin/ ) \
22+
&& rm -rf gn
23+
24+
# CHIP build dependencies
25+
RUN set -x \
26+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
27+
libssl-dev libglib2.0-dev
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../build.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../run.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../chip-build/version

0 commit comments

Comments
 (0)