From 55a37de75b69ef0322fcc2a0e0802b7350582e67 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 31 Jul 2025 13:52:18 -0700 Subject: [PATCH 1/3] gnu: Add legacy Zephyr bisectability In setup.sh, add option to create symlinks from gnu/ so that paths match previous SDK versions. In Zephyr-sdkConfig.cmake, set ZEPHYR_TOOLCHAIN_VARIANT to zephyr/gnu only when Zephyr sets ZEPHYR_TOOLCHAIN_VARIANT_COMPILER_SUPPORT before finding the SDK module. This will require a change to Zephyr, which is unfortunate. Ideally, we'd use some existing mechanism to detect when to make this switch, but it needs to be synchronous with with changes in Zephyr which enable this support, and I couldn't find anything in that series which looked workable. Signed-off-by: Keith Packard --- cmake/Zephyr-sdkConfig.cmake | 6 +++++- scripts/template_setup_posix | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cmake/Zephyr-sdkConfig.cmake b/cmake/Zephyr-sdkConfig.cmake index e9662d5e..8104c43f 100644 --- a/cmake/Zephyr-sdkConfig.cmake +++ b/cmake/Zephyr-sdkConfig.cmake @@ -13,7 +13,11 @@ get_filename_component(ZEPHYR_SDK_INSTALL_DIR ${CMAKE_CURRENT_LIST_DIR}/.. ABSOL set(ZEPHYR_SDK_INSTALL_DIR ${ZEPHYR_SDK_INSTALL_DIR}) if(NOT DEFINED ZEPHYR_TOOLCHAIN_VARIANT) - set(ZEPHYR_TOOLCHAIN_VARIANT "zephyr/gnu") + if(DEFINED ZEPHYR_TOOLCHAIN_VARIANT_COMPILER_SUPPORT) + set(ZEPHYR_TOOLCHAIN_VARIANT "zephyr/gnu") + else() + set(ZEPHYR_TOOLCHAIN_VARIANT "zephyr") + endif() endif() # Those are CMake package parameters. diff --git a/scripts/template_setup_posix b/scripts/template_setup_posix index d680bf85..036e27d0 100644 --- a/scripts/template_setup_posix +++ b/scripts/template_setup_posix @@ -69,6 +69,7 @@ usage() echo " all Install all GNU toolchains" echo " -l Install LLVM toolchain" echo " -h Install host tools" + echo " -o Create symbolic links matching the old SDK layout for old Zephyr (< 4.3) bisectability" echo " -c Register Zephyr SDK CMake package" echo echo "Supported GNU Toolchains:" @@ -117,6 +118,8 @@ user_prompt() # Environment Configurations ask_yn "Register Zephyr SDK CMake package" && do_cmake_pkg="y" + ask_yn "Create symbolic links for old Zephyr bisectability" && do_old_zephyr="y" + echo } @@ -159,6 +162,9 @@ else -c) do_cmake_pkg="y" ;; + -o) + do_old_zephyr="y" + ;; '-?') usage exit 0 @@ -301,6 +307,15 @@ if [ "${do_cmake_pkg}" = "y" ]; then echo fi +# Create links for old Zephyr versions +if [ "${do_old_zephyr}" = "y" ]; then + echo "Creating links for old Zephyr bisectability ..." + ln -sr gnu/* . || assert_rc "ERROR: Creating toolchain links" 50 + ln -sr cmake/zephyr/gnu/* cmake/zephyr || assert_rc "ERROR: Creating cmake links" 50 + ln -sr hosttools/* . || assert_rc "ERROR: Creating hosttools links" 50 + echo +fi + echo "All done." if [ "${interactive}" = "y" ]; then read -n 1 -s -r -p "Press any key to exit ..." From b7f98b01cc13c46714fca2a0ebc79feb155a828b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 30 Sep 2025 12:00:51 -0700 Subject: [PATCH 2/3] cmake: Remove stale comment about riscv and -Os The underlying test was removed, but the comment left in place. Signed-off-by: Keith Packard --- cmake/zephyr/Kconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/zephyr/Kconfig b/cmake/zephyr/Kconfig index 96db3576..ef29a6ae 100644 --- a/cmake/zephyr/Kconfig +++ b/cmake/zephyr/Kconfig @@ -24,7 +24,6 @@ config PICOLIBC_DEFAULT Zephyr SDK >=0.17.1 always uses Picolibc # libstdc++ is built without exception support in -Os mode -# gcc 14.3 has bugs compiling with -Os on riscv choice COMPILER_OPTIMIZATIONS default SPEED_OPTIMIZATIONS if ("$(TOOLCHAIN_VARIANT_COMPILER)" = "gnu") && CPP_EXCEPTIONS endchoice From 1af31ad2c743c746b47fc0903e7ed3d7b57aca1c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 30 Sep 2025 12:01:28 -0700 Subject: [PATCH 3/3] cmake: Switch TOOLCHAIN_VARIANT_COMPILER test around for old Zephyr bisectabilty When building with Zephyr that doesn't have full SDK 1.0 support, the TOOLCHAIN_VARIANT_COMPILER variable will not be set. So, instead of checking whether that is equal to "gnu", check if it is not equal to "llvm" so that we ensure that we use the -O2 version of libstdc++ when exceptions are required. Signed-off-by: Keith Packard --- cmake/zephyr/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/zephyr/Kconfig b/cmake/zephyr/Kconfig index ef29a6ae..16341bf2 100644 --- a/cmake/zephyr/Kconfig +++ b/cmake/zephyr/Kconfig @@ -25,5 +25,5 @@ config PICOLIBC_DEFAULT # libstdc++ is built without exception support in -Os mode choice COMPILER_OPTIMIZATIONS - default SPEED_OPTIMIZATIONS if ("$(TOOLCHAIN_VARIANT_COMPILER)" = "gnu") && CPP_EXCEPTIONS + default SPEED_OPTIMIZATIONS if ("$(TOOLCHAIN_VARIANT_COMPILER)" != "llvm") && CPP_EXCEPTIONS endchoice