Skip to content

Commit

Permalink
Add configure script to set up a light-weight build environment (#26154)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ksperling-apple authored and pull[bot] committed Oct 19, 2023
1 parent ba564c1 commit f895998
Show file tree
Hide file tree
Showing 15 changed files with 581 additions and 28 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/minimal-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (c) 2023 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Minimal Build (Linux / configure)

on:
push:
pull_request:
merge_group:

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}-${{ (github.event_name == 'pull_request' && github.event.number) || (github.event_name == 'workflow_dispatch' && github.run_number) || github.sha }}
cancel-in-progress: true

jobs:
minimal:
name: Linux / configure build of all-clusters-app
timeout-minutes: 60

if: github.actor != 'restyled-io[bot]'
runs-on: ubuntu-latest

container:
image: connectedhomeip/chip-build-minimal:0.7.2

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout submodules
run: scripts/checkout_submodules.py --allow-changing-global-git-config --shallow --platform linux
- name: Configure and build All Clusters App
timeout-minutes: 10
run: |
CC=gcc CXX=g++ scripts/configure --project=examples/all-clusters-app/linux && ./ninja-build
11 changes: 10 additions & 1 deletion build/config/BUILDCONFIG.gn
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,17 @@ if (host_toolchain == "") {
}
}

_custom_toolchain = {
import("${_build_overrides.build_root}/toolchain/custom/custom.gni")
}

if (_chip_defaults.custom_toolchain != "") {
_default_toolchain = _chip_defaults.custom_toolchain
if (filter_include([ _chip_defaults.custom_toolchain ], [ "/*" ]) == []) {
# Interpret relative toolchain names relative to ${build_root}/toolchain/
_default_toolchain = "${_build_overrides.build_root}/toolchain/${_chip_defaults.custom_toolchain}"
} else {
_default_toolchain = _chip_defaults.custom_toolchain
}
} else if (target_os == "all") {
_default_toolchain = "${_pigweed_overrides.dir_pw_toolchain}/default"
} else if (target_os == "linux") {
Expand Down
12 changes: 1 addition & 11 deletions build/toolchain/custom/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,9 @@

import("//build_overrides/build.gni")
import("${build_root}/config/compiler/compiler.gni")
import("${build_root}/toolchain/custom/custom.gni")
import("${build_root}/toolchain/gcc_toolchain.gni")

declare_args() {
# C compiler to use for target build.
target_cc = ""

# C++ compiler to use for target build.
target_cxx = ""

# Archive tool to use for target build.
target_ar = ""
}

gcc_toolchain("custom") {
if (target_cc == "" || target_cxx == "" || target_ar == "") {
assert(false,
Expand Down
27 changes: 27 additions & 0 deletions build/toolchain/custom/custom.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2023 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

declare_args() {
# C compiler to use for target build.
# Only relevant with custom_toolchain = "custom".
target_cc = ""

# C++ compiler to use for target build.
# Only relevant with custom_toolchain = "custom".
target_cxx = ""

# Archive tool to use for target build.
# Only relevant with custom_toolchain = "custom".
target_ar = ""
}
25 changes: 17 additions & 8 deletions examples/build_overrides/pigweed_environment.gni
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ _bootstrap_root = "//third_party/connectedhomeip"
import("${_bootstrap_root}/build_overrides/pigweed_environment.gni")

# Rebase paths to our root.
pw_env_setup_CIPD_ARM =
get_path_info("${_bootstrap_root}/${pw_env_setup_CIPD_ARM}", "abspath")
pw_env_setup_CIPD_PIGWEED =
get_path_info("${_bootstrap_root}/${pw_env_setup_CIPD_PIGWEED}", "abspath")
pw_env_setup_CIPD_PYTHON =
get_path_info("${_bootstrap_root}/${pw_env_setup_CIPD_PYTHON}", "abspath")
pw_env_setup_VIRTUAL_ENV =
get_path_info("${_bootstrap_root}/${pw_env_setup_VIRTUAL_ENV}", "abspath")
if (defined(pw_env_setup_CIPD_ARM)) {
pw_env_setup_CIPD_ARM =
get_path_info("${_bootstrap_root}/${pw_env_setup_CIPD_ARM}", "abspath")
}
if (defined(pw_env_setup_CIPD_PIGWEED)) {
pw_env_setup_CIPD_PIGWEED =
get_path_info("${_bootstrap_root}/${pw_env_setup_CIPD_PIGWEED}",
"abspath")
}
if (defined(pw_env_setup_CIPD_PYTHON)) {
pw_env_setup_CIPD_PYTHON =
get_path_info("${_bootstrap_root}/${pw_env_setup_CIPD_PYTHON}", "abspath")
}
if (defined(pw_env_setup_VIRTUAL_ENV)) {
pw_env_setup_VIRTUAL_ENV =
get_path_info("${_bootstrap_root}/${pw_env_setup_VIRTUAL_ENV}", "abspath")
}
27 changes: 27 additions & 0 deletions integrations/docker/images/chip-build-minimal/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This minimal build image is intentionally not based on chip-build
FROM ubuntu:focal

# ARG NINJA_VERSION=v1.11.1
ARG GN_HASH=5a004f9427a050c6c393c07ddb85cba8ff3849fa

RUN set -x \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get upgrade -y \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential ca-certificates git pkg-config python3-venv ninja-build \
&& git config --global advice.detachedHead false

# RUN set -x && cd /var/tmp \
# && git clone --branch "$NINJA_VERSION" https://github.com/ninja-build/ninja.git \
# && ( cd ninja && ./configure.py --bootstrap && install -m 0755 ninja /usr/local/bin/ ) \
# && rm -rf ninja

RUN set -x && cd /var/tmp \
&& git clone https://gn.googlesource.com/gn \
&& ( cd gn && git checkout "$GN_HASH" && CXX=g++ build/gen.py && ninja -C out && install -m 0755 out/gn /usr/local/bin/ ) \
&& rm -rf gn

# CHIP build dependencies
RUN set -x \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
libssl-dev libglib2.0-dev
1 change: 1 addition & 0 deletions integrations/docker/images/chip-build-minimal/build.sh
1 change: 1 addition & 0 deletions integrations/docker/images/chip-build-minimal/run.sh
1 change: 1 addition & 0 deletions integrations/docker/images/chip-build-minimal/version
Loading

0 comments on commit f895998

Please sign in to comment.