From f1a5999dd84715ff4a91219173895b8c3dc39270 Mon Sep 17 00:00:00 2001 From: Eric Xiao Date: Sat, 4 Apr 2026 17:44:27 -0700 Subject: [PATCH 01/12] Add portable wrapper around feenableexcept --- src/shared/test_util/tbots_gtest_main.cpp | 43 ++++++++++++++++++- .../simulation/er_force_simulator_test.cpp | 4 -- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/shared/test_util/tbots_gtest_main.cpp b/src/shared/test_util/tbots_gtest_main.cpp index 91e0cc254c..31d9c21b8f 100644 --- a/src/shared/test_util/tbots_gtest_main.cpp +++ b/src/shared/test_util/tbots_gtest_main.cpp @@ -14,11 +14,49 @@ bool TbotsGtestMain::stop_ai_on_start = false; std::string TbotsGtestMain::runtime_dir = "/tmp/tbots/yellow_test"; double TbotsGtestMain::test_speed = 1.0; +/** + * Portable wrapper for feenableexcept. + * Returns the previous set of enabled exceptions, or -1 on failure. + */ +int enable_fp_exceptions(unsigned int excepts) +{ +#if defined(__linux__) && defined(__GNUC__) + return feenableexcept(excepts); + +#elif defined(__APPLE__) + fenv_t fenv; + if (fegetenv(&fenv) != 0) + { + return -1; + } + unsigned int old_excepts = (unsigned int)(fenv.__fpcr & FE_ALL_EXCEPT); + + // On ARM64, setting bits in FPCR enables the trap + fenv.__fpcr |= (excepts & FE_ALL_EXCEPT); + + return (fesetenv(&fenv) == 0) ? (int)old_excepts : -1; + +#else + // Unsupported platform + return -1; +#endif +} int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); - feenableexcept(FE_INVALID | FE_OVERFLOW); + + // Crash on invalid operations like division by zero and floating-point overflow + if (enable_fp_exceptions(FE_INVALID | FE_OVERFLOW) < 0) + { + std::cerr << "Warning: Could not enable floating-point exceptions." << std::endl; + } + + // Crash on invalid operations like division by zero and floating-point overflow + if (enable_fp_exceptions(FE_INVALID | FE_OVERFLOW) < 0) + { + std::cerr << "Warning: Could not enable floating-point exceptions." << std::endl; + } boost::program_options::options_description desc{"Options"}; @@ -63,7 +101,8 @@ int main(int argc, char **argv) { // disable floating point errors when using visualizer due to potential // floating point errors in QT - fedisableexcept(FE_INVALID | FE_OVERFLOW); + // TODO #(2510) Remove this once we port over to simulated pytests entirely + // fedisableexcept(FE_INVALID | FE_OVERFLOW); } return RUN_ALL_TESTS(); } diff --git a/src/software/simulation/er_force_simulator_test.cpp b/src/software/simulation/er_force_simulator_test.cpp index bda9a6d7c2..ec72d7dbcc 100644 --- a/src/software/simulation/er_force_simulator_test.cpp +++ b/src/software/simulation/er_force_simulator_test.cpp @@ -1,8 +1,6 @@ #include "software/simulation/er_force_simulator.h" #include -// TODO (#2419): remove this -#include #include "proto/message_translation/er_force_world.h" #include "proto/message_translation/tbots_protobuf.h" @@ -15,8 +13,6 @@ class ErForceSimulatorTest : public ::testing::Test protected: void SetUp() override { - // TODO (#2419): remove this to re-enable sigfpe checks - fedisableexcept(FE_INVALID | FE_OVERFLOW); auto realism_config = ErForceSimulator::createDefaultRealismConfig(); simulator = std::make_shared(TbotsProto::FieldType::DIV_B, robot_constants, realism_config); From 3f999c43c4c719bc5fb2e585ed54c9421e015dd6 Mon Sep 17 00:00:00 2001 From: Eric Xiao Date: Sat, 4 Apr 2026 17:44:55 -0700 Subject: [PATCH 02/12] Add specific linker flags for macos --- src/starlark/nanopb/nanopb.bzl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/starlark/nanopb/nanopb.bzl b/src/starlark/nanopb/nanopb.bzl index 83fc6bf648..4e99a0c663 100644 --- a/src/starlark/nanopb/nanopb.bzl +++ b/src/starlark/nanopb/nanopb.bzl @@ -227,6 +227,9 @@ def _construct_cc_info( user_compile_flags = copts, ) + # Linker flags required for macos, doesn't affect linux + link_flags = ["-Wl,-undefined,dynamic_lookup"] + (linking_context, linking_outputs) = \ cc_common.create_linking_context_from_compilation_outputs( name = "link_nanopb_outputs", @@ -235,6 +238,7 @@ def _construct_cc_info( feature_configuration = feature_configuration, cc_toolchain = cc_toolchain, linking_contexts = nanopb_linking_contexts, + user_link_flags = link_flags, ) extra_context = cc_common.create_compilation_context( From 13405a677b541c79ca8ae78bce05f23c8094da18 Mon Sep 17 00:00:00 2001 From: Eric Xiao Date: Sat, 4 Apr 2026 18:08:22 -0700 Subject: [PATCH 03/12] Remove other calls to feenableexcept --- .../simulated_er_force_sim_test_fixture.cpp | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/software/simulated_tests/simulated_er_force_sim_test_fixture.cpp b/src/software/simulated_tests/simulated_er_force_sim_test_fixture.cpp index a855576af0..79525c0236 100644 --- a/src/software/simulated_tests/simulated_er_force_sim_test_fixture.cpp +++ b/src/software/simulated_tests/simulated_er_force_sim_test_fixture.cpp @@ -2,9 +2,6 @@ #include "proto/message_translation/tbots_protobuf.h" -// TODO (#2419): remove this -#include - #include #include @@ -107,11 +104,7 @@ bool SimulatedErForceSimTestFixture::validateAndCheckCompletion( void SimulatedErForceSimTestFixture::updateSensorFusion( std::shared_ptr simulator) { - // TODO (#2419): remove this to re-enable sigfpe checks - fedisableexcept(FE_INVALID | FE_OVERFLOW); auto ssl_wrapper_packets = simulator->getSSLWrapperPackets(); - // TODO (#2419): remove this to re-enable sigfpe checks - feenableexcept(FE_INVALID | FE_OVERFLOW); auto blue_robot_statuses = simulator->getBlueRobotStatuses(); auto yellow_robot_statuses = simulator->getYellowRobotStatuses(); @@ -183,15 +176,11 @@ void SimulatedErForceSimTestFixture::runTest( std::shared_ptr simulator(std::make_shared( field_type, create2021RobotConstants(), realism_config, ramping)); - // TODO (#2419): remove this to re-enable sigfpe checks - fedisableexcept(FE_INVALID | FE_OVERFLOW); simulator->setBallState(ball); // step the simulator to make sure the robots and the ball are in position simulator->stepSimulation(simulation_time_step); simulator->setYellowRobots(friendly_robots); simulator->setBlueRobots(enemy_robots); - // TODO (#2419): remove this to re-enable sigfpe checks - feenableexcept(FE_INVALID | FE_OVERFLOW); updateSensorFusion(simulator); std::shared_ptr friendly_world; @@ -521,11 +510,7 @@ bool SimulatedErForceSimTestFixture::tickTest( auto wall_start_time = std::chrono::steady_clock::now(); bool validation_functions_done = false; - // TODO (#2419): remove this to re-enable sigfpe checks - fedisableexcept(FE_INVALID | FE_OVERFLOW); simulator->stepSimulation(simulation_time_step); - // TODO (#2419): remove this to re-enable sigfpe checks - feenableexcept(FE_INVALID | FE_OVERFLOW); updateSensorFusion(simulator); if (friendly_sensor_fusion.getWorld().has_value() && From d822e30452727dde73214b826293780684760076 Mon Sep 17 00:00:00 2001 From: Eric Xiao Date: Mon, 6 Apr 2026 14:14:39 -0700 Subject: [PATCH 04/12] Update enable_fp_exceptions function --- src/shared/test_util/tbots_gtest_main.cpp | 35 +++++++++++------------ 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/shared/test_util/tbots_gtest_main.cpp b/src/shared/test_util/tbots_gtest_main.cpp index 31d9c21b8f..13067e3a85 100644 --- a/src/shared/test_util/tbots_gtest_main.cpp +++ b/src/shared/test_util/tbots_gtest_main.cpp @@ -15,30 +15,33 @@ std::string TbotsGtestMain::runtime_dir = "/tmp/tbots/yellow_test"; double TbotsGtestMain::test_speed = 1.0; /** - * Portable wrapper for feenableexcept. - * Returns the previous set of enabled exceptions, or -1 on failure. + * Portable wrapper for feenableexcept. Use to specify which floating-point + * exceptions should crash the program when they occur. + * + * @param excepts A bitmask of floating-point exceptions to be enabled. + * @return True on success, false on failure to set floating-point exceptions. */ -int enable_fp_exceptions(unsigned int excepts) +bool enable_fp_exceptions(unsigned int excepts) { #if defined(__linux__) && defined(__GNUC__) - return feenableexcept(excepts); + feenableexcept(excepts); + return true; #elif defined(__APPLE__) - fenv_t fenv; - if (fegetenv(&fenv) != 0) + // https://stackoverflow.com/questions/71821666/trapping-floating-point-exceptions-and-signal-handling-on-apple-silicon + fenv_t env; + if (fegetenv(&env) != 0) { - return -1; + return false; } - unsigned int old_excepts = (unsigned int)(fenv.__fpcr & FE_ALL_EXCEPT); - // On ARM64, setting bits in FPCR enables the trap - fenv.__fpcr |= (excepts & FE_ALL_EXCEPT); + env.__fpcr |= (excepts & FE_ALL_EXCEPT); - return (fesetenv(&fenv) == 0) ? (int)old_excepts : -1; + return fesetenv(&env) == 0; #else // Unsupported platform - return -1; + return false; #endif } @@ -47,13 +50,7 @@ int main(int argc, char **argv) testing::InitGoogleTest(&argc, argv); // Crash on invalid operations like division by zero and floating-point overflow - if (enable_fp_exceptions(FE_INVALID | FE_OVERFLOW) < 0) - { - std::cerr << "Warning: Could not enable floating-point exceptions." << std::endl; - } - - // Crash on invalid operations like division by zero and floating-point overflow - if (enable_fp_exceptions(FE_INVALID | FE_OVERFLOW) < 0) + if (!enable_fp_exceptions(FE_INVALID | FE_OVERFLOW)) { std::cerr << "Warning: Could not enable floating-point exceptions." << std::endl; } From 58d7e180105726fa7e3222443350041ed98d9440 Mon Sep 17 00:00:00 2001 From: Eric Xiao Date: Mon, 6 Apr 2026 14:36:03 -0700 Subject: [PATCH 05/12] Remove macos floating point exception trap after testing --- src/shared/test_util/tbots_gtest_main.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/shared/test_util/tbots_gtest_main.cpp b/src/shared/test_util/tbots_gtest_main.cpp index 13067e3a85..8911f9212b 100644 --- a/src/shared/test_util/tbots_gtest_main.cpp +++ b/src/shared/test_util/tbots_gtest_main.cpp @@ -18,6 +18,10 @@ double TbotsGtestMain::test_speed = 1.0; * Portable wrapper for feenableexcept. Use to specify which floating-point * exceptions should crash the program when they occur. * + * @note On MacOS ARM, there are no floating-point exception traps, so tests may + * pass on MacOS that wouldn't pass on other platforms if floating-point + * exceptions occur. + * * @param excepts A bitmask of floating-point exceptions to be enabled. * @return True on success, false on failure to set floating-point exceptions. */ @@ -26,19 +30,6 @@ bool enable_fp_exceptions(unsigned int excepts) #if defined(__linux__) && defined(__GNUC__) feenableexcept(excepts); return true; - -#elif defined(__APPLE__) - // https://stackoverflow.com/questions/71821666/trapping-floating-point-exceptions-and-signal-handling-on-apple-silicon - fenv_t env; - if (fegetenv(&env) != 0) - { - return false; - } - // On ARM64, setting bits in FPCR enables the trap - env.__fpcr |= (excepts & FE_ALL_EXCEPT); - - return fesetenv(&env) == 0; - #else // Unsupported platform return false; @@ -49,7 +40,7 @@ int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); - // Crash on invalid operations like division by zero and floating-point overflow + // Crash on invalid operations like sqrt of negative and floating-point overflow if (!enable_fp_exceptions(FE_INVALID | FE_OVERFLOW)) { std::cerr << "Warning: Could not enable floating-point exceptions." << std::endl; From 779d584f44eab82a7adb97f17a96d30cdf00fcb1 Mon Sep 17 00:00:00 2001 From: Eric Xiao Date: Mon, 6 Apr 2026 14:36:49 -0700 Subject: [PATCH 06/12] Formatting --- .../simulated_tests/simulated_er_force_sim_test_fixture.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/software/simulated_tests/simulated_er_force_sim_test_fixture.cpp b/src/software/simulated_tests/simulated_er_force_sim_test_fixture.cpp index 79525c0236..ed93a705e7 100644 --- a/src/software/simulated_tests/simulated_er_force_sim_test_fixture.cpp +++ b/src/software/simulated_tests/simulated_er_force_sim_test_fixture.cpp @@ -1,7 +1,5 @@ #include "software/simulated_tests/simulated_er_force_sim_test_fixture.h" -#include "proto/message_translation/tbots_protobuf.h" - #include #include From 28fcbe457370b4ebeb1ce571953b2a01329ba0db Mon Sep 17 00:00:00 2001 From: Eric Xiao Date: Mon, 6 Apr 2026 15:14:49 -0700 Subject: [PATCH 07/12] Update thunderscope requirements_lock.darwin.txt --- src/software/thunderscope/requirements_lock.darwin.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/software/thunderscope/requirements_lock.darwin.txt b/src/software/thunderscope/requirements_lock.darwin.txt index 87532ad2ba..55045c79c5 100644 --- a/src/software/thunderscope/requirements_lock.darwin.txt +++ b/src/software/thunderscope/requirements_lock.darwin.txt @@ -120,7 +120,13 @@ pyqtgraph==0.13.7 \ --hash=sha256:64f84f1935c6996d0e09b1ee66fe478a7771e3ca6f3aaa05f00f6e068321d9e3 \ --hash=sha256:7754edbefb6c367fa0dfb176e2d0610da3ada20aa7a5318516c74af5fb72bf7a # via -r software/thunderscope/requirements.in +qtawesome==1.4.0 \ + --hash=sha256:783e414d1317f3e978bf67ea8e8a1b1498bad9dbd305dec814027e3b50521be6 \ + --hash=sha256:a4d689fa071c595aa6184171ce1f0f847677cb8d2db45382c43129f1d72a3d93 + # via -r software/thunderscope/requirements.in qtpy==2.4.2 \ --hash=sha256:5a696b1dd7a354cb330657da1d17c20c2190c72d4888ba923f8461da67aa1a1c \ --hash=sha256:9d6ec91a587cc1495eaebd23130f7619afa5cdd34a277acb87735b4ad7c65156 - # via pyqt-toast-notification + # via + # pyqt-toast-notification + # qtawesome From e6ed708b014d2d11d6931d15cdd03868cac34888 Mon Sep 17 00:00:00 2001 From: Eric Xiao Date: Mon, 6 Apr 2026 15:15:05 -0700 Subject: [PATCH 08/12] Fix and add comment explaining differences in typename test --- src/software/util/typename/typename_test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/software/util/typename/typename_test.cpp b/src/software/util/typename/typename_test.cpp index f28a4b25cd..4acd815c25 100644 --- a/src/software/util/typename/typename_test.cpp +++ b/src/software/util/typename/typename_test.cpp @@ -17,7 +17,13 @@ class TestTypeA : public TestType TEST(TypeNameTest, abstract_base_class_concrete_subtype) { std::shared_ptr test_type = std::make_shared(); +#ifdef __APPLE__ + // With clang / libc++, the standard library uses an inline namespace '__1' for + // ABI versioning, which is reflected in the demangled type name. + EXPECT_EQ("std::__1::shared_ptr", objectTypeName(test_type)); +#else EXPECT_EQ("std::shared_ptr", objectTypeName(test_type)); +#endif EXPECT_EQ("TestTypeA", objectTypeName(*test_type)); } From 793110c573ba2c1c85adf6aba2014947ee70193e Mon Sep 17 00:00:00 2001 From: Eric Xiao Date: Mon, 6 Apr 2026 15:25:30 -0700 Subject: [PATCH 09/12] Use EXPECT_NEAR for floating point calculations --- src/software/math/math_functions_test.cpp | 40 +++++++++++------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/software/math/math_functions_test.cpp b/src/software/math/math_functions_test.cpp index c5a48dd605..8effc174c1 100644 --- a/src/software/math/math_functions_test.cpp +++ b/src/software/math/math_functions_test.cpp @@ -5,66 +5,66 @@ TEST(LinearUtilFunctionTest, testZeroCase) { double out = linear(0, 0, 2); - EXPECT_EQ(out, 0.5); + EXPECT_NEAR(out, 0.5, 1e-15); } TEST(LinearUtilFunctionTest, testOneQuarter) { double out = linear(-1, 0, 4); - EXPECT_EQ(out, 0.25); + EXPECT_NEAR(out, 0.25, 1e-15); } TEST(LinearUtilFunctionTest, testTwoThirds) { double out = linear(0.75, 0, 4.5); - EXPECT_EQ(out, 2.0 / 3.0); + EXPECT_NEAR(out, 2.0 / 3.0, 1e-15); } TEST(LinearUtilFunctionTest, testMinimumNoOffset) { double out = linear(-1.5, 0, 3); - EXPECT_EQ(out, 0.0); + EXPECT_NEAR(out, 0.0, 1e-15); } TEST(LinearUtilFunctionTest, testMaximumNoOffset) { double out = linear(2.5, 0, 5.0); - EXPECT_EQ(out, 1.0); -} - -TEST(LinearUtilFunctionTest, testClampBelowNoOffset) -{ - double out = linear(-2, 0, 1); - EXPECT_EQ(out, 0.0); -} - -TEST(LinearUtilFunctionTest, testClampAboveNoOffset) -{ - double out = linear(4.2, 0, 6); - EXPECT_EQ(out, 1.0); + EXPECT_NEAR(out, 1.0, 1e-15); } TEST(LinearUtilFunctionTest, testMinimumNegativeOffset) { double out = linear(-4, -2, 4); - EXPECT_EQ(out, 0.0); + EXPECT_NEAR(out, 0.0, 1e-15); } TEST(LinearUtilFunctionTest, testMaximumNegativeOffset) { double out = linear(1.5, -1, 5.0); - EXPECT_EQ(out, 1.0); + EXPECT_NEAR(out, 1.0, 1e-15); } TEST(LinearUtilFunctionTest, testMinimumPositiveOffset) { double out = linear(0, 3, 6); - EXPECT_EQ(out, 0.0); + EXPECT_NEAR(out, 0.0, 1e-15); } TEST(LinearUtilFunctionTest, testMaximumPositiveOffset) { double out = linear(6, 1.5, 9); + EXPECT_NEAR(out, 1.0, 1e-15); +} + +TEST(LinearUtilFunctionTest, testClampBelowNoOffset) +{ + double out = linear(-2, 0, 1); + EXPECT_EQ(out, 0.0); +} + +TEST(LinearUtilFunctionTest, testClampAboveNoOffset) +{ + double out = linear(4.2, 0, 6); EXPECT_EQ(out, 1.0); } From 031ab83713f1843f8a5b395342d8b7fe8ca70fa3 Mon Sep 17 00:00:00 2001 From: Eric Xiao Date: Tue, 7 Apr 2026 19:59:49 -0700 Subject: [PATCH 10/12] Remove fedisableexcept --- src/shared/test_util/tbots_gtest_main.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/shared/test_util/tbots_gtest_main.cpp b/src/shared/test_util/tbots_gtest_main.cpp index 8911f9212b..0abce8db4d 100644 --- a/src/shared/test_util/tbots_gtest_main.cpp +++ b/src/shared/test_util/tbots_gtest_main.cpp @@ -84,14 +84,6 @@ int main(int argc, char **argv) if (!TbotsGtestMain::help) { LoggerSingleton::initializeLogger(TbotsGtestMain::runtime_dir, nullptr); - - if (TbotsGtestMain::enable_visualizer || TbotsGtestMain::run_sim_in_realtime) - { - // disable floating point errors when using visualizer due to potential - // floating point errors in QT - // TODO #(2510) Remove this once we port over to simulated pytests entirely - // fedisableexcept(FE_INVALID | FE_OVERFLOW); - } return RUN_ALL_TESTS(); } else From bbf6240f8123340032047f43b5a304ffb230154e Mon Sep 17 00:00:00 2001 From: Eric Xiao Date: Tue, 7 Apr 2026 20:01:47 -0700 Subject: [PATCH 11/12] Use numeric_limits epsilon instead of 1e-15 --- src/software/math/math_functions_test.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/software/math/math_functions_test.cpp b/src/software/math/math_functions_test.cpp index 8effc174c1..033aee4d29 100644 --- a/src/software/math/math_functions_test.cpp +++ b/src/software/math/math_functions_test.cpp @@ -2,58 +2,60 @@ #include +#include + TEST(LinearUtilFunctionTest, testZeroCase) { double out = linear(0, 0, 2); - EXPECT_NEAR(out, 0.5, 1e-15); + EXPECT_NEAR(out, 0.5, std::numeric_limits::epsilon()); } TEST(LinearUtilFunctionTest, testOneQuarter) { double out = linear(-1, 0, 4); - EXPECT_NEAR(out, 0.25, 1e-15); + EXPECT_NEAR(out, 0.25, std::numeric_limits::epsilon()); } TEST(LinearUtilFunctionTest, testTwoThirds) { double out = linear(0.75, 0, 4.5); - EXPECT_NEAR(out, 2.0 / 3.0, 1e-15); + EXPECT_NEAR(out, 2.0 / 3.0, std::numeric_limits::epsilon()); } TEST(LinearUtilFunctionTest, testMinimumNoOffset) { double out = linear(-1.5, 0, 3); - EXPECT_NEAR(out, 0.0, 1e-15); + EXPECT_NEAR(out, 0.0, std::numeric_limits::epsilon()); } TEST(LinearUtilFunctionTest, testMaximumNoOffset) { double out = linear(2.5, 0, 5.0); - EXPECT_NEAR(out, 1.0, 1e-15); + EXPECT_NEAR(out, 1.0, std::numeric_limits::epsilon()); } TEST(LinearUtilFunctionTest, testMinimumNegativeOffset) { double out = linear(-4, -2, 4); - EXPECT_NEAR(out, 0.0, 1e-15); + EXPECT_NEAR(out, 0.0, std::numeric_limits::epsilon()); } TEST(LinearUtilFunctionTest, testMaximumNegativeOffset) { double out = linear(1.5, -1, 5.0); - EXPECT_NEAR(out, 1.0, 1e-15); + EXPECT_NEAR(out, 1.0, std::numeric_limits::epsilon()); } TEST(LinearUtilFunctionTest, testMinimumPositiveOffset) { double out = linear(0, 3, 6); - EXPECT_NEAR(out, 0.0, 1e-15); + EXPECT_NEAR(out, 0.0, std::numeric_limits::epsilon()); } TEST(LinearUtilFunctionTest, testMaximumPositiveOffset) { double out = linear(6, 1.5, 9); - EXPECT_NEAR(out, 1.0, 1e-15); + EXPECT_NEAR(out, 1.0, std::numeric_limits::epsilon()); } TEST(LinearUtilFunctionTest, testClampBelowNoOffset) From 0dcc1c5e77f8d5fa41ac613c9e36df79b8294c44 Mon Sep 17 00:00:00 2001 From: Eric Xiao Date: Sat, 9 May 2026 15:46:04 -0700 Subject: [PATCH 12/12] Only use -undefined linker flag for macos --- src/starlark/nanopb/nanopb.bzl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/starlark/nanopb/nanopb.bzl b/src/starlark/nanopb/nanopb.bzl index 4e99a0c663..cdec9947de 100644 --- a/src/starlark/nanopb/nanopb.bzl +++ b/src/starlark/nanopb/nanopb.bzl @@ -227,8 +227,10 @@ def _construct_cc_info( user_compile_flags = copts, ) - # Linker flags required for macos, doesn't affect linux - link_flags = ["-Wl,-undefined,dynamic_lookup"] + # Flags required for macos linker which allow symbols to be resolved at runtime + link_flags = [] + if "darwin" in cc_toolchain.cpu: + link_flags = ["-Wl,-undefined,dynamic_lookup"] (linking_context, linking_outputs) = \ cc_common.create_linking_context_from_compilation_outputs(