Skip to content

Commit

Permalink
Zephyr build change: location of Unity. (#916)
Browse files Browse the repository at this point in the history
When building for Zephyr, Unity, which is required for the runner build and for testing, is now located as follows:

1.  if the environment variable UNITY_PATH is set, then Unity is taken from there, else...
2.  if Zephyr is being brought in with the nRF Connect SDK then Unity is taken from the nRF Connect SDK, else...
3.  the platform must include Unity (the single unity.c and the include path for the headers).

(1) is the new bit, which is now the default for the runner build and the test system.  This _should_ mean that native Zephyr can be used, i.e. outside of the nRF Connect SDK.
  • Loading branch information
RobMeades committed Jun 17, 2023
1 parent cbf54cf commit 84565ee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 3 additions & 1 deletion port/platform/common/automation/tasks/nrfconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ def check_installation(ctx):
ctx.zephyr_pre_command = ""

# Load required packages
pkgs = u_package.load(ctx, ["arm_embedded_gcc", "nrfconnectsdk", "ninja", "cmake", "gperf", "nrf_cli", "segger_jlink"])
pkgs = u_package.load(ctx, ["arm_embedded_gcc", "nrfconnectsdk", "ninja", "cmake", "gperf", "nrf_cli", "segger_jlink", "unity"])
ncs_pkg = pkgs["nrfconnectsdk"]
ae_gcc_pkg = pkgs["arm_embedded_gcc"]
unity_pkg = pkgs["unity"]

ctx.config.run.env["ZEPHYR_BASE"] = f'{ncs_pkg.get_install_path()}/zephyr'
ctx.config.run.env["ZEPHYR_TOOLCHAIN_VARIANT"] = 'gnuarmemb'
ctx.config.run.env["GNUARMEMB_TOOLCHAIN_PATH"] = ae_gcc_pkg.get_install_path()
ctx.arm_toolchain_path = ae_gcc_pkg.get_install_path() + "/bin"
ctx.config.run.env["UNITY_PATH"] = f'{unity_pkg.get_install_path()}'

@task(
pre=[check_installation],
Expand Down
22 changes: 17 additions & 5 deletions port/platform/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,30 @@ if (CONFIG_UBXLIB_TEST)
${UBXLIB_TEST_INC}
)

# If we are building outside of Platform IO then we
# bring in unity from the NRF Connect SDK in which
# Zephyr is contained. However, under Platform IO that
# doesn't exist, you get it from Platform IO
# instead, hence make this a "weak" inclusion
# If the environment variable UNITY_PATH is defined then we get
# unity from there, else it might be in the nRF SDK, otherwise
# the platform itself must build it and include the head file
# (which is the case for Platform IO)
if (DEFINED ENV{UNITY_PATH})
message("Unity from $ENV{UNITY_PATH} will be used")
target_sources(app PRIVATE
$ENV{UNITY_PATH}/src/unity.c
)
zephyr_include_directories(
$ENV{UNITY_PATH}/src
)
else()
if (EXISTS "${ZEPHYR_BASE}/../test/cmock/vendor/unity/src/unity.c")
message("Unity from ${ZEPHYR_BASE}/../test/cmock/vendor/unity will be used")
target_sources(app PRIVATE
${ZEPHYR_BASE}/../test/cmock/vendor/unity/src/unity.c
)
zephyr_include_directories(
${ZEPHYR_BASE}/../test/cmock/vendor/unity/src
)
else()
message("Assuming that the platform will bring in Unity")
endif()
endif()

endif()
Expand Down
2 changes: 2 additions & 0 deletions port/platform/zephyr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ CONFIG_UBXLIB=y

`ubxlib` also requires some Zephyr config to be enabled: check [default.conf](default.conf) for the basics or, for details to do with BLE configuration or including I2C/SPI etc., check [runner/prj.conf](runner/prj.conf)/[runner_linux/prj.conf](runner_linux/prj.conf).

If you wish to build the default `runner` build and associated tests _without_ nRF Connect SDK then you will need to bring in a copy of Unity from somewhere, identifying the Unity directory by defining the environment variable `UNITY_PATH`, e.g. `UNITY_PATH=/home/ubxlib/unity`.

# SDK Usage

## Nordic MCUs: Segger Embedded Studio
Expand Down

0 comments on commit 84565ee

Please sign in to comment.