Skip to content

Commit

Permalink
Add crypto target to build examples (#20958)
Browse files Browse the repository at this point in the history
* Add crypto lib support for host builds. Fix up arm64 a bit

* Restyled by autopep8

* Update naming for builds for linux arm compiles

* Fix rejection for clang build variants

* update bload names with arm64 clang name

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Aug 29, 2023
1 parent 632b66e commit 2432000
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 187 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/examples-linux-arm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,26 @@ jobs:
run: |
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py \
--target linux-arm64-all-clusters \
--target linux-arm64-chip-tool-ipv6only \
--target linux-arm64-lock \
--target linux-arm64-minmdns \
--target linux-arm64-thermostat-no-ble \
--target linux-arm64-clang-all-clusters \
--target linux-arm64-clang-chip-tool-ipv6only \
--target linux-arm64-clang-lock \
--target linux-arm64-clang-minmdns \
--target linux-arm64-clang-thermostat-no-ble \
build \
"
- name: Bloat report - chip-tool
timeout-minutes: 5
run: |
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
linux arm64 chip-tool-ipv6only \
out/linux-arm64-chip-tool-ipv6only/chip-tool \
out/linux-arm64-clang-chip-tool-ipv6only/chip-tool \
/tmp/bloat_reports/
- name: Bloat report - thermostat
timeout-minutes: 5
run: |
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
linux arm64 thermostat-no-ble \
out/linux-arm64-thermostat-no-ble/thermostat-app \
out/linux-arm64-clang-thermostat-no-ble/thermostat-app \
/tmp/bloat_reports/
- name: Uploading Size Reports
uses: actions/upload-artifact@v2
Expand Down
31 changes: 26 additions & 5 deletions scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from builders.cyw30739 import Cyw30739App, Cyw30739Board, Cyw30739Builder
from builders.efr32 import Efr32App, Efr32Board, Efr32Builder
from builders.esp32 import Esp32App, Esp32Board, Esp32Builder
from builders.host import HostApp, HostBoard, HostBuilder
from builders.host import HostApp, HostBoard, HostBuilder, HostCryptoLibrary
from builders.infineon import InfineonApp, InfineonBoard, InfineonBuilder
from builders.k32w import K32WApp, K32WBuilder
from builders.mbed import MbedApp, MbedBoard, MbedBuilder, MbedProfile
Expand Down Expand Up @@ -116,6 +116,17 @@ def Accept(self, name: str):
return False


class RejectNameWithSubstrings:
def __init__(self, substr: List[str]):
self.substr = substr

def Accept(self, name: str):
for s in self.substr:
if s in name:
return False
return True


class BuildVariant:
def __init__(self, name: str, validator=AcceptAnyName(),
conflicts: List[str] = [], requires: List[str] = [],
Expand Down Expand Up @@ -226,7 +237,7 @@ def HostTargets():
# x64 linux supports cross compile
cross_compile = (HostBoard.NATIVE.PlatformName() == 'linux') and (HostBoard.NATIVE.BoardName() != HostBoard.ARM64.BoardName())
if cross_compile:
targets.append(target.Extend('arm64', board=HostBoard.ARM64))
targets.append(target.Extend('arm64-clang', board=HostBoard.ARM64, use_clang=True))

app_targets = []

Expand Down Expand Up @@ -276,11 +287,19 @@ def HostTargets():
builder.AppendVariant(name="no-ble", enable_ble=False),
builder.AppendVariant(name="no-wifi", enable_wifi=False),
builder.AppendVariant(name="no-thread", enable_thread=False),
builder.AppendVariant(name="mbedtls", conflicts=['boringssl'], crypto_library=HostCryptoLibrary.MBEDTLS),
builder.AppendVariant(name="boringssl", conflicts=['mbedtls'], crypto_library=HostCryptoLibrary.BORINGSSL),
builder.AppendVariant(name="tsan", conflicts=['asan'], use_tsan=True),
builder.AppendVariant(name="asan", conflicts=['tsan'], use_asan=True),
builder.AppendVariant(name="libfuzzer", requires=[
"clang"], use_libfuzzer=True),
builder.AppendVariant(name="clang", use_clang=True),
if cross_compile:
builder.AppendVariant(name="clang", use_clang=True, validator=RejectNameWithSubstrings(
['arm64']
)),
else:
builder.AppendVariant(name="clang", use_clang=True)

builder.AppendVariant(name="test", extra_tests=True),

builder.WhitelistVariantNameForGlob('ipv6only')
Expand Down Expand Up @@ -310,8 +329,10 @@ def HostTargets():
use_platform_mdns=True, enable_ipv4=False).GlobBlacklist("Reduce default build variants")

yield target_native.Extend('tests', app=HostApp.TESTS)
yield target_native.Extend('tests-coverage', app=HostApp.TESTS, use_coverage=True)
yield target_native.Extend('tests-clang', app=HostApp.TESTS, use_clang=True)
yield target_native.Extend('tests-mbedtls', app=HostApp.TESTS, crypto_library=HostCryptoLibrary.MBEDTLS).GlobBlacklist("Non-default test")
yield target_native.Extend('tests-boringssl', app=HostApp.TESTS, crypto_library=HostCryptoLibrary.BORINGSSL).GlobBlacklist("Non-default test")
yield target_native.Extend('tests-coverage', app=HostApp.TESTS, use_coverage=True).GlobBlacklist("Non-default test")
yield target_native.Extend('tests-clang', app=HostApp.TESTS, use_clang=True).GlobBlacklist("Non-default test")

test_target = Target(HostBoard.NATIVE.PlatformName(), HostBuilder)
yield test_target.Extend(HostBoard.FAKE.BoardName() + '-tests', board=HostBoard.FAKE, app=HostApp.TESTS)
Expand Down
37 changes: 28 additions & 9 deletions scripts/build/builders/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@
from .gn import GnBuilder


class HostCryptoLibrary(Enum):
"""Defines what cryptographic backend applications should use."""
OPENSSL = auto()
MBEDTLS = auto()
BORINGSSL = auto()

@property
def gn_argument(self):
if self == HostCryptoLibrary.OPENSSL:
return 'chip_crypto="openssl"'
elif self == HostCryptoLibrary.MBEDTLS:
return 'chip_crypto="mbedtls"'
elif self == HostCryptoLibrary.BORINGSSL:
return 'chip_crypto="boringssl"'


class HostApp(Enum):
ALL_CLUSTERS = auto()
ALL_CLUSTERS_MINIMAL = auto()
Expand Down Expand Up @@ -198,7 +214,7 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE,
separate_event_loop=True, use_libfuzzer=False, use_clang=False,
interactive_mode=True, extra_tests=False,
use_platform_mdns=False, enable_rpcs=False,
use_coverage=False):
use_coverage=False, crypto_library: HostCryptoLibrary = None):
super(HostBuilder, self).__init__(
root=os.path.join(root, 'examples', app.ExamplePath()),
runner=runner)
Expand Down Expand Up @@ -264,14 +280,19 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE,
if app == HostApp.NL_TEST_RUNNER:
self.build_command = 'runner'

# Crypto library has per-platform defaults (like openssl for linux/mac
# and mbedtls for android/freertos/zephyr/mbed/...)
if crypto_library:
self.extra_gn_options.append(crypto_library.gn_argument)

if self.board == HostBoard.ARM64:
if not use_clang:
raise Exception("Cross compile only supported using clang")

if app == HostApp.CERT_TOOL:
# Certification only built for openssl
if self.board == HostBoard.ARM64:
# OpenSSL and mbedTLS conflicts.
# We only cross compile with mbedTLS.
raise Exception(
"Cannot cross compile CERT TOOL: ssl library conflict")
self.extra_gn_options.append('chip_crypto="openssl"')
if self.board == HostBoard.ARM64 and crypto_library == HostCryptoLibrary.MBEDTLS:
raise Exception("MbedTLS not supported for cross compiling cert tool")
self.build_command = 'src/tools/chip-cert'
elif app == HostApp.ADDRESS_RESOLVE:
self.build_command = 'src/lib/address_resolve:address-resolve-tool'
Expand All @@ -287,8 +308,6 @@ def GnBuildArgs(self):
self.extra_gn_options.extend(
[
'target_cpu="arm64"',
'is_clang=true',
'chip_crypto="mbedtls"',
'sysroot="%s"' % self.SysRootPath('SYSROOT_AARCH64')
]
)
Expand Down
Loading

0 comments on commit 2432000

Please sign in to comment.