Skip to content

Commit a5e1281

Browse files
committed
Zephyr: Avoid host library path when running SDK tools
The Zephyr CI image sets LD_LIBRARY_PATH globally to include host system library directories. When Zephyr SDK host tools such as dtc are launched, this can make the SDK dynamic loader resolve libraries from the host instead of the SDK hosttools sysroot. Sanitize LD_LIBRARY_PATH for Zephyr west build commands so SDK host tools use their intended runtime libraries, while preserving sample-specific entries such as FVP paths. Signed-off-by: Zingo Andersen <Zingo.Andersen@arm.com> Change-Id: I036dd0ae732bbfe20c8e6c41831692a3bb7c6f60
1 parent 7044edc commit a5e1281

1 file changed

Lines changed: 51 additions & 2 deletions

File tree

.ci/scripts/test_zephyr.sh

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,48 @@ cd "${EXECUTORCH_PROJ_ROOT}"
9999
. .ci/scripts/utils.sh
100100
. .ci/scripts/zephyr-utils.sh
101101

102+
sanitize_zephyr_ld_library_path() {
103+
local -a ld_entries
104+
local cuda_lib entry output
105+
106+
cuda_lib="${CUDA_HOME:+${CUDA_HOME}/lib64}"
107+
output=""
108+
IFS=':' read -r -a ld_entries <<< "${LD_LIBRARY_PATH:-}"
109+
for entry in "${ld_entries[@]}"; do
110+
if [[ -z "${entry}" || "${entry}" == "/usr/lib/x86_64-linux-gnu" ]]; then
111+
continue
112+
fi
113+
if [[ -n "${cuda_lib}" && "${entry}" == "${cuda_lib}" ]]; then
114+
continue
115+
fi
116+
117+
if [[ -z "${output}" ]]; then
118+
output="${entry}"
119+
else
120+
output="${output}:${entry}"
121+
fi
122+
done
123+
124+
printf '%s\n' "${output}"
125+
}
126+
127+
west() {
128+
local sanitized_ld_library_path
129+
130+
if [[ "${1:-}" != "build" ]]; then
131+
command west "$@"
132+
return
133+
fi
134+
135+
sanitized_ld_library_path="$(sanitize_zephyr_ld_library_path)"
136+
echo "Using sanitized LD_LIBRARY_PATH for west build: ${sanitized_ld_library_path:-<unset>}"
137+
if [[ -n "${sanitized_ld_library_path}" ]]; then
138+
LD_LIBRARY_PATH="${sanitized_ld_library_path}" command west "$@"
139+
else
140+
env -u LD_LIBRARY_PATH west "$@"
141+
fi
142+
}
143+
102144
run_target_test_blocks_from_readme() {
103145
local readme_path="$1"
104146
local target="$2"
@@ -201,7 +243,7 @@ print_tool_details() {
201243
print_path_details() {
202244
local label="$1"
203245
local path="$2"
204-
local interpreter
246+
local interpreter sanitized_ld_library_path
205247

206248
echo "${label}: ${path}"
207249
if [[ -e "${path}" ]]; then
@@ -214,6 +256,13 @@ print_path_details() {
214256
fi
215257
if [[ -x "${path}" ]]; then
216258
"${path}" --version || true
259+
sanitized_ld_library_path="$(sanitize_zephyr_ld_library_path)"
260+
echo "${label} --version with sanitized LD_LIBRARY_PATH: ${sanitized_ld_library_path:-<unset>}"
261+
if [[ -n "${sanitized_ld_library_path}" ]]; then
262+
LD_LIBRARY_PATH="${sanitized_ld_library_path}" "${path}" --version || true
263+
else
264+
env -u LD_LIBRARY_PATH "${path}" --version || true
265+
fi
217266
fi
218267
else
219268
echo "${label}: missing"
@@ -234,7 +283,7 @@ print_zephyr_diagnostics() {
234283
echo "ZEPHYR_SDK_INSTALL_DIR: ${ZEPHYR_SDK_INSTALL_DIR:-<unset>}"
235284
echo "ZEPHYR_TOOLCHAIN_VARIANT: ${ZEPHYR_TOOLCHAIN_VARIANT:-<unset>}"
236285
echo "ZEPHYR_SDK_RELEASE_PROXY_CACHE_DIR: ${ZEPHYR_SDK_RELEASE_PROXY_CACHE_DIR:-<unset>}"
237-
echo "EXECUTORCH_ZEPHYR_DTC: ${EXECUTORCH_ZEPHYR_DTC:-<unset>}"
286+
echo "Sanitized LD_LIBRARY_PATH: $(sanitize_zephyr_ld_library_path || true)"
238287

239288
sdk_version="$(python3 "${EXECUTORCH_PROJ_ROOT}/.ci/docker/common/zephyr_sdk_release_proxy.py" --print-version)"
240289
echo "Zephyr SDK version: ${sdk_version}"

0 commit comments

Comments
 (0)