From fb8c3b7c044d307b5e1a0767526a3de3465f9761 Mon Sep 17 00:00:00 2001 From: Dominik Fischer Date: Wed, 1 Apr 2026 13:50:40 +0200 Subject: [PATCH 1/6] Bazel gcc arm_none_eabi toolchain POC - Add Bazel workspace setup (.bazelrc, .bazelversion, MODULE.bazel) - Add nonhermetic arm-none-eabi-gcc toolchain for s32k148 platform - Migrate libs/bsw/util, libs/bsw/platform, libs/3rdparty/etl to Bazel - Build artifact analysis for libs/bsw/util Cmake vs. Bazel - Add bazel migration and artifact analysis. Details in bazel_migration/README.md Change-Id: I20082f9a2ba9b451c2a61d2e76d88786782d6235 --- .bazelignore | 5 + .bazelrc | 12 + .bazelversion | 1 + .gitignore | 5 + MODULE.bazel | 12 + MODULE.bazel.lock | 209 +++++++++++++++ bazel/.gitignore | 8 + bazel/config/build_config/BUILD | 38 +++ bazel/platform/BUILD | 7 + bazel/toolchain/BUILD | 29 +++ .../arm_none_eabi_gcc_cc_toolchain_config.bzl | 238 ++++++++++++++++++ bazel_migration/README.md | 70 ++++++ bazel_migration/artifact_comparison__util.md | 86 +++++++ bazel_migration/artifact_comparison_method.md | 80 ++++++ executables/referenceApp/etl_profile/BUILD | 6 + executables/unitTest/etl_profile/BUILD | 6 + libs/3rdparty/etl/BUILD | 19 ++ libs/bsw/platform/BUILD | 6 + libs/bsw/util/BUILD | 48 ++++ 19 files changed, 885 insertions(+) create mode 100644 .bazelignore create mode 100644 .bazelrc create mode 100644 .bazelversion create mode 100644 MODULE.bazel create mode 100644 MODULE.bazel.lock create mode 100644 bazel/.gitignore create mode 100644 bazel/config/build_config/BUILD create mode 100644 bazel/platform/BUILD create mode 100644 bazel/toolchain/BUILD create mode 100644 bazel/toolchain/arm_none_eabi/gcc/arm_none_eabi_gcc_cc_toolchain_config.bzl create mode 100644 bazel_migration/README.md create mode 100644 bazel_migration/artifact_comparison__util.md create mode 100644 bazel_migration/artifact_comparison_method.md create mode 100644 executables/referenceApp/etl_profile/BUILD create mode 100644 executables/unitTest/etl_profile/BUILD create mode 100644 libs/3rdparty/etl/BUILD create mode 100644 libs/bsw/platform/BUILD create mode 100644 libs/bsw/util/BUILD diff --git a/.bazelignore b/.bazelignore new file mode 100644 index 00000000000..ced1c6b3457 --- /dev/null +++ b/.bazelignore @@ -0,0 +1,5 @@ +# The vendored instance of googletest v1.11.0 is not supported by current Bazel version. +# It will cause errors in Bazel if not ignored +# A fixed version exists on the central Bazel registry that can be used on the Bazel side: +# https://registry.bazel.build/modules/googletest/1.11.0 +libs/3rdparty/googletest \ No newline at end of file diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000000..cab137025c0 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,12 @@ +build:s32k148_gcc --platforms=//bazel/platform:s32k148 +# Default to gcc +build:s32k148 --config=s32k148_gcc + +# TODO: Temporary config only needed for artifact analysis +# Make Bazel's build match CMake s32k148-freertos-gcc default config +build:s32k148_relwithdebinfo --config=s32k148 +build:s32k148_relwithdebinfo --copt=-g3 +build:s32k148_relwithdebinfo --copt=-O2 +build:s32k148_relwithdebinfo --copt=-DNDEBUG + +test --//bazel/config/build_config=unit_test diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 00000000000..acd405b1d62 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +8.6.0 diff --git a/.gitignore b/.gitignore index 25f01e15ac8..f401c6f036f 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,8 @@ doc/api/doc-coverage.info doc/api/doxygenOut tools/puncover_tool/output/ venv +bazel-* +bazel-bin +bazel-openbsw +bazel-out +bazel-testlogs \ No newline at end of file diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 00000000000..dccdbdb05a2 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,12 @@ +module( + name = "openbsw", + version = "0.0.1", +) + +bazel_dep(name = "platforms", version = "1.0.0") +bazel_dep(name = "rules_cc", version = "0.2.17") +bazel_dep(name = "bazel_skylib", version = "1.9.0") + +register_toolchains( + "//bazel/toolchain:cc_toolchain_arm_none_eabi_gcc", +) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock new file mode 100644 index 00000000000..6e054f4f6ff --- /dev/null +++ b/MODULE.bazel.lock @@ -0,0 +1,209 @@ +{ + "lockFileVersion": 24, + "registryFileHashes": { + "https://bcr.bazel.build/bazel_registry.json": "8a28e4aff06ee60aed2a8c281907fb8bcbf3b753c91fb5a5c57da3215d5b3497", + "https://bcr.bazel.build/modules/abseil-cpp/20210324.2/MODULE.bazel": "7cd0312e064fde87c8d1cd79ba06c876bd23630c83466e9500321be55c96ace2", + "https://bcr.bazel.build/modules/abseil-cpp/20211102.0/MODULE.bazel": "70390338f7a5106231d20620712f7cccb659cd0e9d073d1991c038eb9fc57589", + "https://bcr.bazel.build/modules/abseil-cpp/20230125.1/MODULE.bazel": "89047429cb0207707b2dface14ba7f8df85273d484c2572755be4bab7ce9c3a0", + "https://bcr.bazel.build/modules/abseil-cpp/20230802.0.bcr.1/MODULE.bazel": "1c8cec495288dccd14fdae6e3f95f772c1c91857047a098fad772034264cc8cb", + "https://bcr.bazel.build/modules/abseil-cpp/20230802.0/MODULE.bazel": "d253ae36a8bd9ee3c5955384096ccb6baf16a1b1e93e858370da0a3b94f77c16", + "https://bcr.bazel.build/modules/abseil-cpp/20230802.1/MODULE.bazel": "fa92e2eb41a04df73cdabeec37107316f7e5272650f81d6cc096418fe647b915", + "https://bcr.bazel.build/modules/abseil-cpp/20240116.1/MODULE.bazel": "37bcdb4440fbb61df6a1c296ae01b327f19e9bb521f9b8e26ec854b6f97309ed", + "https://bcr.bazel.build/modules/abseil-cpp/20240116.1/source.json": "9be551b8d4e3ef76875c0d744b5d6a504a27e3ae67bc6b28f46415fd2d2957da", + "https://bcr.bazel.build/modules/bazel_features/1.1.1/MODULE.bazel": "27b8c79ef57efe08efccbd9dd6ef70d61b4798320b8d3c134fd571f78963dbcd", + "https://bcr.bazel.build/modules/bazel_features/1.11.0/MODULE.bazel": "f9382337dd5a474c3b7d334c2f83e50b6eaedc284253334cf823044a26de03e8", + "https://bcr.bazel.build/modules/bazel_features/1.15.0/MODULE.bazel": "d38ff6e517149dc509406aca0db3ad1efdd890a85e049585b7234d04238e2a4d", + "https://bcr.bazel.build/modules/bazel_features/1.17.0/MODULE.bazel": "039de32d21b816b47bd42c778e0454217e9c9caac4a3cf8e15c7231ee3ddee4d", + "https://bcr.bazel.build/modules/bazel_features/1.18.0/MODULE.bazel": "1be0ae2557ab3a72a57aeb31b29be347bcdc5d2b1eb1e70f39e3851a7e97041a", + "https://bcr.bazel.build/modules/bazel_features/1.19.0/MODULE.bazel": "59adcdf28230d220f0067b1f435b8537dd033bfff8db21335ef9217919c7fb58", + "https://bcr.bazel.build/modules/bazel_features/1.28.0/MODULE.bazel": "4b4200e6cbf8fa335b2c3f43e1d6ef3e240319c33d43d60cc0fbd4b87ece299d", + "https://bcr.bazel.build/modules/bazel_features/1.30.0/MODULE.bazel": "a14b62d05969a293b80257e72e597c2da7f717e1e69fa8b339703ed6731bec87", + "https://bcr.bazel.build/modules/bazel_features/1.30.0/source.json": "b07e17f067fe4f69f90b03b36ef1e08fe0d1f3cac254c1241a1818773e3423bc", + "https://bcr.bazel.build/modules/bazel_features/1.4.1/MODULE.bazel": "e45b6bb2350aff3e442ae1111c555e27eac1d915e77775f6fdc4b351b758b5d7", + "https://bcr.bazel.build/modules/bazel_features/1.9.1/MODULE.bazel": "8f679097876a9b609ad1f60249c49d68bfab783dd9be012faf9d82547b14815a", + "https://bcr.bazel.build/modules/bazel_skylib/1.0.3/MODULE.bazel": "bcb0fd896384802d1ad283b4e4eb4d718eebd8cb820b0a2c3a347fb971afd9d8", + "https://bcr.bazel.build/modules/bazel_skylib/1.1.1/MODULE.bazel": "1add3e7d93ff2e6998f9e118022c84d163917d912f5afafb3058e3d2f1545b5e", + "https://bcr.bazel.build/modules/bazel_skylib/1.2.0/MODULE.bazel": "44fe84260e454ed94ad326352a698422dbe372b21a1ac9f3eab76eb531223686", + "https://bcr.bazel.build/modules/bazel_skylib/1.2.1/MODULE.bazel": "f35baf9da0efe45fa3da1696ae906eea3d615ad41e2e3def4aeb4e8bc0ef9a7a", + "https://bcr.bazel.build/modules/bazel_skylib/1.3.0/MODULE.bazel": "20228b92868bf5cfc41bda7afc8a8ba2a543201851de39d990ec957b513579c5", + "https://bcr.bazel.build/modules/bazel_skylib/1.4.1/MODULE.bazel": "a0dcb779424be33100dcae821e9e27e4f2901d9dfd5333efe5ac6a8d7ab75e1d", + "https://bcr.bazel.build/modules/bazel_skylib/1.4.2/MODULE.bazel": "3bd40978e7a1fac911d5989e6b09d8f64921865a45822d8b09e815eaa726a651", + "https://bcr.bazel.build/modules/bazel_skylib/1.5.0/MODULE.bazel": "32880f5e2945ce6a03d1fbd588e9198c0a959bb42297b2cfaf1685b7bc32e138", + "https://bcr.bazel.build/modules/bazel_skylib/1.6.1/MODULE.bazel": "8fdee2dbaace6c252131c00e1de4b165dc65af02ea278476187765e1a617b917", + "https://bcr.bazel.build/modules/bazel_skylib/1.7.0/MODULE.bazel": "0db596f4563de7938de764cc8deeabec291f55e8ec15299718b93c4423e9796d", + "https://bcr.bazel.build/modules/bazel_skylib/1.7.1/MODULE.bazel": "3120d80c5861aa616222ec015332e5f8d3171e062e3e804a2a0253e1be26e59b", + "https://bcr.bazel.build/modules/bazel_skylib/1.9.0/MODULE.bazel": "72997b29dfd95c3fa0d0c48322d05590418edef451f8db8db5509c57875fb4b7", + "https://bcr.bazel.build/modules/bazel_skylib/1.9.0/source.json": "7ad77c1e8c1b84222d9b3f3cae016a76639435744c19330b0b37c0a3c9da7dc0", + "https://bcr.bazel.build/modules/buildozer/7.1.2/MODULE.bazel": "2e8dd40ede9c454042645fd8d8d0cd1527966aa5c919de86661e62953cd73d84", + "https://bcr.bazel.build/modules/buildozer/7.1.2/source.json": "c9028a501d2db85793a6996205c8de120944f50a0d570438fcae0457a5f9d1f8", + "https://bcr.bazel.build/modules/google_benchmark/1.8.2/MODULE.bazel": "a70cf1bba851000ba93b58ae2f6d76490a9feb74192e57ab8e8ff13c34ec50cb", + "https://bcr.bazel.build/modules/googletest/1.11.0/MODULE.bazel": "3a83f095183f66345ca86aa13c58b59f9f94a2f81999c093d4eeaa2d262d12f4", + "https://bcr.bazel.build/modules/googletest/1.14.0.bcr.1/MODULE.bazel": "22c31a561553727960057361aa33bf20fb2e98584bc4fec007906e27053f80c6", + "https://bcr.bazel.build/modules/googletest/1.14.0.bcr.1/source.json": "41e9e129f80d8c8bf103a7acc337b76e54fad1214ac0a7084bf24f4cd924b8b4", + "https://bcr.bazel.build/modules/googletest/1.14.0/MODULE.bazel": "cfbcbf3e6eac06ef9d85900f64424708cc08687d1b527f0ef65aa7517af8118f", + "https://bcr.bazel.build/modules/jsoncpp/1.9.5/MODULE.bazel": "31271aedc59e815656f5736f282bb7509a97c7ecb43e927ac1a37966e0578075", + "https://bcr.bazel.build/modules/jsoncpp/1.9.5/source.json": "4108ee5085dd2885a341c7fab149429db457b3169b86eb081fa245eadf69169d", + "https://bcr.bazel.build/modules/libpfm/4.11.0/MODULE.bazel": "45061ff025b301940f1e30d2c16bea596c25b176c8b6b3087e92615adbd52902", + "https://bcr.bazel.build/modules/platforms/0.0.10/MODULE.bazel": "8cb8efaf200bdeb2150d93e162c40f388529a25852b332cec879373771e48ed5", + "https://bcr.bazel.build/modules/platforms/0.0.11/MODULE.bazel": "0daefc49732e227caa8bfa834d65dc52e8cc18a2faf80df25e8caea151a9413f", + "https://bcr.bazel.build/modules/platforms/0.0.4/MODULE.bazel": "9b328e31ee156f53f3c416a64f8491f7eb731742655a47c9eec4703a71644aee", + "https://bcr.bazel.build/modules/platforms/0.0.5/MODULE.bazel": "5733b54ea419d5eaf7997054bb55f6a1d0b5ff8aedf0176fef9eea44f3acda37", + "https://bcr.bazel.build/modules/platforms/0.0.6/MODULE.bazel": "ad6eeef431dc52aefd2d77ed20a4b353f8ebf0f4ecdd26a807d2da5aa8cd0615", + "https://bcr.bazel.build/modules/platforms/0.0.7/MODULE.bazel": "72fd4a0ede9ee5c021f6a8dd92b503e089f46c227ba2813ff183b71616034814", + "https://bcr.bazel.build/modules/platforms/0.0.8/MODULE.bazel": "9f142c03e348f6d263719f5074b21ef3adf0b139ee4c5133e2aa35664da9eb2d", + "https://bcr.bazel.build/modules/platforms/1.0.0/MODULE.bazel": "f05feb42b48f1b3c225e4ccf351f367be0371411a803198ec34a389fb22aa580", + "https://bcr.bazel.build/modules/platforms/1.0.0/source.json": "f4ff1fd412e0246fd38c82328eb209130ead81d62dcd5a9e40910f867f733d96", + "https://bcr.bazel.build/modules/protobuf/21.7/MODULE.bazel": "a5a29bb89544f9b97edce05642fac225a808b5b7be74038ea3640fae2f8e66a7", + "https://bcr.bazel.build/modules/protobuf/27.0/MODULE.bazel": "7873b60be88844a0a1d8f80b9d5d20cfbd8495a689b8763e76c6372998d3f64c", + "https://bcr.bazel.build/modules/protobuf/27.1/MODULE.bazel": "703a7b614728bb06647f965264967a8ef1c39e09e8f167b3ca0bb1fd80449c0d", + "https://bcr.bazel.build/modules/protobuf/29.0-rc2/MODULE.bazel": "6241d35983510143049943fc0d57937937122baf1b287862f9dc8590fc4c37df", + "https://bcr.bazel.build/modules/protobuf/29.0/MODULE.bazel": "319dc8bf4c679ff87e71b1ccfb5a6e90a6dbc4693501d471f48662ac46d04e4e", + "https://bcr.bazel.build/modules/protobuf/29.0/source.json": "b857f93c796750eef95f0d61ee378f3420d00ee1dd38627b27193aa482f4f981", + "https://bcr.bazel.build/modules/protobuf/3.19.0/MODULE.bazel": "6b5fbb433f760a99a22b18b6850ed5784ef0e9928a72668b66e4d7ccd47db9b0", + "https://bcr.bazel.build/modules/pybind11_bazel/2.11.1/MODULE.bazel": "88af1c246226d87e65be78ed49ecd1e6f5e98648558c14ce99176da041dc378e", + "https://bcr.bazel.build/modules/pybind11_bazel/2.11.1/source.json": "be4789e951dd5301282729fe3d4938995dc4c1a81c2ff150afc9f1b0504c6022", + "https://bcr.bazel.build/modules/re2/2023-09-01/MODULE.bazel": "cb3d511531b16cfc78a225a9e2136007a48cf8a677e4264baeab57fe78a80206", + "https://bcr.bazel.build/modules/re2/2023-09-01/source.json": "e044ce89c2883cd957a2969a43e79f7752f9656f6b20050b62f90ede21ec6eb4", + "https://bcr.bazel.build/modules/rules_android/0.1.1/MODULE.bazel": "48809ab0091b07ad0182defb787c4c5328bd3a278938415c00a7b69b50c4d3a8", + "https://bcr.bazel.build/modules/rules_android/0.1.1/source.json": "e6986b41626ee10bdc864937ffb6d6bf275bb5b9c65120e6137d56e6331f089e", + "https://bcr.bazel.build/modules/rules_cc/0.0.1/MODULE.bazel": "cb2aa0747f84c6c3a78dad4e2049c154f08ab9d166b1273835a8174940365647", + "https://bcr.bazel.build/modules/rules_cc/0.0.10/MODULE.bazel": "ec1705118f7eaedd6e118508d3d26deba2a4e76476ada7e0e3965211be012002", + "https://bcr.bazel.build/modules/rules_cc/0.0.13/MODULE.bazel": "0e8529ed7b323dad0775ff924d2ae5af7640b23553dfcd4d34344c7e7a867191", + "https://bcr.bazel.build/modules/rules_cc/0.0.14/MODULE.bazel": "5e343a3aac88b8d7af3b1b6d2093b55c347b8eefc2e7d1442f7a02dc8fea48ac", + "https://bcr.bazel.build/modules/rules_cc/0.0.15/MODULE.bazel": "6704c35f7b4a72502ee81f61bf88706b54f06b3cbe5558ac17e2e14666cd5dcc", + "https://bcr.bazel.build/modules/rules_cc/0.0.16/MODULE.bazel": "7661303b8fc1b4d7f532e54e9d6565771fea666fbdf839e0a86affcd02defe87", + "https://bcr.bazel.build/modules/rules_cc/0.0.2/MODULE.bazel": "6915987c90970493ab97393024c156ea8fb9f3bea953b2f3ec05c34f19b5695c", + "https://bcr.bazel.build/modules/rules_cc/0.0.6/MODULE.bazel": "abf360251023dfe3efcef65ab9d56beefa8394d4176dd29529750e1c57eaa33f", + "https://bcr.bazel.build/modules/rules_cc/0.0.8/MODULE.bazel": "964c85c82cfeb6f3855e6a07054fdb159aced38e99a5eecf7bce9d53990afa3e", + "https://bcr.bazel.build/modules/rules_cc/0.0.9/MODULE.bazel": "836e76439f354b89afe6a911a7adf59a6b2518fafb174483ad78a2a2fde7b1c5", + "https://bcr.bazel.build/modules/rules_cc/0.1.1/MODULE.bazel": "2f0222a6f229f0bf44cd711dc13c858dad98c62d52bd51d8fc3a764a83125513", + "https://bcr.bazel.build/modules/rules_cc/0.2.17/MODULE.bazel": "1849602c86cb60da8613d2de887f9566a6d354a6df6d7009f9d04a14402f9a84", + "https://bcr.bazel.build/modules/rules_cc/0.2.17/source.json": "3832f45d145354049137c0090df04629d9c2b5493dc5c2bf46f1834040133a07", + "https://bcr.bazel.build/modules/rules_foreign_cc/0.9.0/MODULE.bazel": "c9e8c682bf75b0e7c704166d79b599f93b72cfca5ad7477df596947891feeef6", + "https://bcr.bazel.build/modules/rules_fuzzing/0.5.2/MODULE.bazel": "40c97d1144356f52905566c55811f13b299453a14ac7769dfba2ac38192337a8", + "https://bcr.bazel.build/modules/rules_fuzzing/0.5.2/source.json": "c8b1e2c717646f1702290959a3302a178fb639d987ab61d548105019f11e527e", + "https://bcr.bazel.build/modules/rules_java/4.0.0/MODULE.bazel": "5a78a7ae82cd1a33cef56dc578c7d2a46ed0dca12643ee45edbb8417899e6f74", + "https://bcr.bazel.build/modules/rules_java/5.3.5/MODULE.bazel": "a4ec4f2db570171e3e5eb753276ee4b389bae16b96207e9d3230895c99644b86", + "https://bcr.bazel.build/modules/rules_java/6.0.0/MODULE.bazel": "8a43b7df601a7ec1af61d79345c17b31ea1fedc6711fd4abfd013ea612978e39", + "https://bcr.bazel.build/modules/rules_java/6.4.0/MODULE.bazel": "e986a9fe25aeaa84ac17ca093ef13a4637f6107375f64667a15999f77db6c8f6", + "https://bcr.bazel.build/modules/rules_java/6.5.2/MODULE.bazel": "1d440d262d0e08453fa0c4d8f699ba81609ed0e9a9a0f02cd10b3e7942e61e31", + "https://bcr.bazel.build/modules/rules_java/7.10.0/MODULE.bazel": "530c3beb3067e870561739f1144329a21c851ff771cd752a49e06e3dc9c2e71a", + "https://bcr.bazel.build/modules/rules_java/7.12.2/MODULE.bazel": "579c505165ee757a4280ef83cda0150eea193eed3bef50b1004ba88b99da6de6", + "https://bcr.bazel.build/modules/rules_java/7.2.0/MODULE.bazel": "06c0334c9be61e6cef2c8c84a7800cef502063269a5af25ceb100b192453d4ab", + "https://bcr.bazel.build/modules/rules_java/7.3.2/MODULE.bazel": "50dece891cfdf1741ea230d001aa9c14398062f2b7c066470accace78e412bc2", + "https://bcr.bazel.build/modules/rules_java/7.6.1/MODULE.bazel": "2f14b7e8a1aa2f67ae92bc69d1ec0fa8d9f827c4e17ff5e5f02e91caa3b2d0fe", + "https://bcr.bazel.build/modules/rules_java/8.14.0/MODULE.bazel": "717717ed40cc69994596a45aec6ea78135ea434b8402fb91b009b9151dd65615", + "https://bcr.bazel.build/modules/rules_java/8.14.0/source.json": "8a88c4ca9e8759da53cddc88123880565c520503321e2566b4e33d0287a3d4bc", + "https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/MODULE.bazel": "a56b85e418c83eb1839819f0b515c431010160383306d13ec21959ac412d2fe7", + "https://bcr.bazel.build/modules/rules_jvm_external/5.1/MODULE.bazel": "33f6f999e03183f7d088c9be518a63467dfd0be94a11d0055fe2d210f89aa909", + "https://bcr.bazel.build/modules/rules_jvm_external/5.2/MODULE.bazel": "d9351ba35217ad0de03816ef3ed63f89d411349353077348a45348b096615036", + "https://bcr.bazel.build/modules/rules_jvm_external/5.3/MODULE.bazel": "bf93870767689637164657731849fb887ad086739bd5d360d90007a581d5527d", + "https://bcr.bazel.build/modules/rules_jvm_external/6.1/MODULE.bazel": "75b5fec090dbd46cf9b7d8ea08cf84a0472d92ba3585b476f44c326eda8059c4", + "https://bcr.bazel.build/modules/rules_jvm_external/6.3/MODULE.bazel": "c998e060b85f71e00de5ec552019347c8bca255062c990ac02d051bb80a38df0", + "https://bcr.bazel.build/modules/rules_jvm_external/6.3/source.json": "6f5f5a5a4419ae4e37c35a5bb0a6ae657ed40b7abc5a5189111b47fcebe43197", + "https://bcr.bazel.build/modules/rules_kotlin/1.9.0/MODULE.bazel": "ef85697305025e5a61f395d4eaede272a5393cee479ace6686dba707de804d59", + "https://bcr.bazel.build/modules/rules_kotlin/1.9.6/MODULE.bazel": "d269a01a18ee74d0335450b10f62c9ed81f2321d7958a2934e44272fe82dcef3", + "https://bcr.bazel.build/modules/rules_kotlin/1.9.6/source.json": "2faa4794364282db7c06600b7e5e34867a564ae91bda7cae7c29c64e9466b7d5", + "https://bcr.bazel.build/modules/rules_license/0.0.3/MODULE.bazel": "627e9ab0247f7d1e05736b59dbb1b6871373de5ad31c3011880b4133cafd4bd0", + "https://bcr.bazel.build/modules/rules_license/0.0.7/MODULE.bazel": "088fbeb0b6a419005b89cf93fe62d9517c0a2b8bb56af3244af65ecfe37e7d5d", + "https://bcr.bazel.build/modules/rules_license/1.0.0/MODULE.bazel": "a7fda60eefdf3d8c827262ba499957e4df06f659330bbe6cdbdb975b768bb65c", + "https://bcr.bazel.build/modules/rules_license/1.0.0/source.json": "a52c89e54cc311196e478f8382df91c15f7a2bfdf4c6cd0e2675cc2ff0b56efb", + "https://bcr.bazel.build/modules/rules_pkg/0.7.0/MODULE.bazel": "df99f03fc7934a4737122518bb87e667e62d780b610910f0447665a7e2be62dc", + "https://bcr.bazel.build/modules/rules_pkg/1.0.1/MODULE.bazel": "5b1df97dbc29623bccdf2b0dcd0f5cb08e2f2c9050aab1092fd39a41e82686ff", + "https://bcr.bazel.build/modules/rules_pkg/1.0.1/source.json": "bd82e5d7b9ce2d31e380dd9f50c111d678c3bdaca190cb76b0e1c71b05e1ba8a", + "https://bcr.bazel.build/modules/rules_proto/4.0.0/MODULE.bazel": "a7a7b6ce9bee418c1a760b3d84f83a299ad6952f9903c67f19e4edd964894e06", + "https://bcr.bazel.build/modules/rules_proto/5.3.0-21.7/MODULE.bazel": "e8dff86b0971688790ae75528fe1813f71809b5afd57facb44dad9e8eca631b7", + "https://bcr.bazel.build/modules/rules_proto/6.0.2/MODULE.bazel": "ce916b775a62b90b61888052a416ccdda405212b6aaeb39522f7dc53431a5e73", + "https://bcr.bazel.build/modules/rules_proto/7.0.2/MODULE.bazel": "bf81793bd6d2ad89a37a40693e56c61b0ee30f7a7fdbaf3eabbf5f39de47dea2", + "https://bcr.bazel.build/modules/rules_proto/7.0.2/source.json": "1e5e7260ae32ef4f2b52fd1d0de8d03b606a44c91b694d2f1afb1d3b28a48ce1", + "https://bcr.bazel.build/modules/rules_python/0.10.2/MODULE.bazel": "cc82bc96f2997baa545ab3ce73f196d040ffb8756fd2d66125a530031cd90e5f", + "https://bcr.bazel.build/modules/rules_python/0.23.1/MODULE.bazel": "49ffccf0511cb8414de28321f5fcf2a31312b47c40cc21577144b7447f2bf300", + "https://bcr.bazel.build/modules/rules_python/0.25.0/MODULE.bazel": "72f1506841c920a1afec76975b35312410eea3aa7b63267436bfb1dd91d2d382", + "https://bcr.bazel.build/modules/rules_python/0.28.0/MODULE.bazel": "cba2573d870babc976664a912539b320cbaa7114cd3e8f053c720171cde331ed", + "https://bcr.bazel.build/modules/rules_python/0.31.0/MODULE.bazel": "93a43dc47ee570e6ec9f5779b2e64c1476a6ce921c48cc9a1678a91dd5f8fd58", + "https://bcr.bazel.build/modules/rules_python/0.4.0/MODULE.bazel": "9208ee05fd48bf09ac60ed269791cf17fb343db56c8226a720fbb1cdf467166c", + "https://bcr.bazel.build/modules/rules_python/0.40.0/MODULE.bazel": "9d1a3cd88ed7d8e39583d9ffe56ae8a244f67783ae89b60caafc9f5cf318ada7", + "https://bcr.bazel.build/modules/rules_python/0.40.0/source.json": "939d4bd2e3110f27bfb360292986bb79fd8dcefb874358ccd6cdaa7bda029320", + "https://bcr.bazel.build/modules/rules_shell/0.2.0/MODULE.bazel": "fda8a652ab3c7d8fee214de05e7a9916d8b28082234e8d2c0094505c5268ed3c", + "https://bcr.bazel.build/modules/rules_shell/0.2.0/source.json": "7f27af3c28037d9701487c4744b5448d26537cc66cdef0d8df7ae85411f8de95", + "https://bcr.bazel.build/modules/stardoc/0.5.1/MODULE.bazel": "1a05d92974d0c122f5ccf09291442580317cdd859f07a8655f1db9a60374f9f8", + "https://bcr.bazel.build/modules/stardoc/0.5.3/MODULE.bazel": "c7f6948dae6999bf0db32c1858ae345f112cacf98f174c7a8bb707e41b974f1c", + "https://bcr.bazel.build/modules/stardoc/0.5.6/MODULE.bazel": "c43dabc564990eeab55e25ed61c07a1aadafe9ece96a4efabb3f8bf9063b71ef", + "https://bcr.bazel.build/modules/stardoc/0.7.0/MODULE.bazel": "05e3d6d30c099b6770e97da986c53bd31844d7f13d41412480ea265ac9e8079c", + "https://bcr.bazel.build/modules/stardoc/0.7.1/MODULE.bazel": "3548faea4ee5dda5580f9af150e79d0f6aea934fc60c1cc50f4efdd9420759e7", + "https://bcr.bazel.build/modules/stardoc/0.7.1/source.json": "b6500ffcd7b48cd72c29bb67bcac781e12701cc0d6d55d266a652583cfcdab01", + "https://bcr.bazel.build/modules/upb/0.0.0-20220923-a547704/MODULE.bazel": "7298990c00040a0e2f121f6c32544bab27d4452f80d9ce51349b1a28f3005c43", + "https://bcr.bazel.build/modules/zlib/1.2.11/MODULE.bazel": "07b389abc85fdbca459b69e2ec656ae5622873af3f845e1c9d80fe179f3effa0", + "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/MODULE.bazel": "eec517b5bbe5492629466e11dae908d043364302283de25581e3eb944326c4ca", + "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/source.json": "22bc55c47af97246cfc093d0acf683a7869377de362b5d1c552c2c2e16b7a806", + "https://bcr.bazel.build/modules/zlib/1.3.1/MODULE.bazel": "751c9940dcfe869f5f7274e1295422a34623555916eb98c174c1e945594bf198" + }, + "selectedYankedVersions": {}, + "moduleExtensions": { + "@@rules_kotlin+//src/main/starlark/core/repositories:bzlmod_setup.bzl%rules_kotlin_extensions": { + "general": { + "bzlTransitiveDigest": "nvW/NrBXlAmiQw99EMGKkLaD2KbNp2mQDlxdfpr+0Ls=", + "usagesDigest": "QI2z8ZUR+mqtbwsf2fLqYdJAkPOHdOV+tF2yVAUgRzw=", + "recordedFileInputs": {}, + "recordedDirentsInputs": {}, + "envVariables": {}, + "generatedRepoSpecs": { + "com_github_jetbrains_kotlin_git": { + "repoRuleId": "@@rules_kotlin+//src/main/starlark/core/repositories:compiler.bzl%kotlin_compiler_git_repository", + "attributes": { + "urls": [ + "https://github.com/JetBrains/kotlin/releases/download/v1.9.23/kotlin-compiler-1.9.23.zip" + ], + "sha256": "93137d3aab9afa9b27cb06a824c2324195c6b6f6179d8a8653f440f5bd58be88" + } + }, + "com_github_jetbrains_kotlin": { + "repoRuleId": "@@rules_kotlin+//src/main/starlark/core/repositories:compiler.bzl%kotlin_capabilities_repository", + "attributes": { + "git_repository_name": "com_github_jetbrains_kotlin_git", + "compiler_version": "1.9.23" + } + }, + "com_github_google_ksp": { + "repoRuleId": "@@rules_kotlin+//src/main/starlark/core/repositories:ksp.bzl%ksp_compiler_plugin_repository", + "attributes": { + "urls": [ + "https://github.com/google/ksp/releases/download/1.9.23-1.0.20/artifacts.zip" + ], + "sha256": "ee0618755913ef7fd6511288a232e8fad24838b9af6ea73972a76e81053c8c2d", + "strip_version": "1.9.23-1.0.20" + } + }, + "com_github_pinterest_ktlint": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_file", + "attributes": { + "sha256": "01b2e0ef893383a50dbeb13970fe7fa3be36ca3e83259e01649945b09d736985", + "urls": [ + "https://github.com/pinterest/ktlint/releases/download/1.3.0/ktlint" + ], + "executable": true + } + }, + "rules_android": { + "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive", + "attributes": { + "sha256": "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806", + "strip_prefix": "rules_android-0.1.1", + "urls": [ + "https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip" + ] + } + } + }, + "recordedRepoMappingEntries": [ + [ + "rules_kotlin+", + "bazel_tools", + "bazel_tools" + ] + ] + } + } + }, + "facts": {} +} diff --git a/bazel/.gitignore b/bazel/.gitignore new file mode 100644 index 00000000000..4fe6d2a4382 --- /dev/null +++ b/bazel/.gitignore @@ -0,0 +1,8 @@ + +bazel-bin +bazel-out +bazel-testlogs +bazel-* +.bazel-cache +.bazelrc.local +.bazelrc.user diff --git a/bazel/config/build_config/BUILD b/bazel/config/build_config/BUILD new file mode 100644 index 00000000000..eca86a34e10 --- /dev/null +++ b/bazel/config/build_config/BUILD @@ -0,0 +1,38 @@ + +""" +Build configuration flag for selecting between application build variants. +This allows targets to define variable dependencies/headers/sources based on the +active build variant (reference_app or unit_test). + +Set via: +- --//bazel/config/build_config:build_config= +- Defaults to "reference_app" in general +- Overridden to "unit_test" for bazel test commands in .bazelrc + +NOTE: When adding variance using select() based on this configuration flag: +- Selects should be defined inside the consuming package's BUILD file. This avoids indirection, + keeps variant logic readable and provides a single point of change when adding new variants. +- If the config value is not logically tied to a package or used in many packages it may instead be + defined as a common config in bazel/build/config/: +- Selects should either inlcude a default or raise an specific error. +""" +load("@bazel_skylib//rules:common_settings.bzl", "string_flag") + +string_flag( + name = "build_config", + build_setting_default = "reference_app", + values = ["reference_app", "unit_test"], + visibility = ["//visibility:public"], +) + +config_setting( + name = "reference_app", + flag_values = {":build_config": "reference_app"}, + visibility = ["//visibility:public"], +) + +config_setting( + name = "unit_test", + flag_values = {":build_config": "unit_test"}, + visibility = ["//visibility:public"], +) diff --git a/bazel/platform/BUILD b/bazel/platform/BUILD new file mode 100644 index 00000000000..e32e4f95289 --- /dev/null +++ b/bazel/platform/BUILD @@ -0,0 +1,7 @@ +platform( + name = "s32k148", + constraint_values = [ + "@platforms//cpu:armv7e-m", + "@platforms//os:none", + ], +) diff --git a/bazel/toolchain/BUILD b/bazel/toolchain/BUILD new file mode 100644 index 00000000000..f530dca0212 --- /dev/null +++ b/bazel/toolchain/BUILD @@ -0,0 +1,29 @@ +load(":arm_none_eabi/gcc/arm_none_eabi_gcc_cc_toolchain_config.bzl", "cc_toolchain_config") + +package(default_visibility = ["//visibility:public"]) + +filegroup(name = "empty") + +cc_toolchain_config(name = "arm_none_eabi_gcc_toolchain_config") + +cc_toolchain( + name = "arm_none_eabi_gcc_toolchain", + all_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 0, + toolchain_config = ":arm_none_eabi_gcc_toolchain_config", +) + +toolchain( + name = "cc_toolchain_arm_none_eabi_gcc", + target_compatible_with = [ + "@platforms//os:none", + "@platforms//cpu:armv7e-m", + ], + toolchain = ":arm_none_eabi_gcc_toolchain", + toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", +) diff --git a/bazel/toolchain/arm_none_eabi/gcc/arm_none_eabi_gcc_cc_toolchain_config.bzl b/bazel/toolchain/arm_none_eabi/gcc/arm_none_eabi_gcc_cc_toolchain_config.bzl new file mode 100644 index 00000000000..1931868c9fe --- /dev/null +++ b/bazel/toolchain/arm_none_eabi/gcc/arm_none_eabi_gcc_cc_toolchain_config.bzl @@ -0,0 +1,238 @@ +load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "feature", + "flag_group", + "flag_set", + "tool_path", +) + +_ALL_C_COMPILE_ACTIONS = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.assemble, +] + +_ALL_CXX_COMPILE_ACTIONS = [ + ACTION_NAMES.cpp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, +] + +_ALL_COMPILE_ACTIONS = _ALL_C_COMPILE_ACTIONS + _ALL_CXX_COMPILE_ACTIONS + +_ALL_LINK_ACTIONS = [ + ACTION_NAMES.cpp_link_executable, + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, +] + +_ALL_ASSEMBLE_ACTIONS = [ + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, +] + +def _impl(ctx): + tool_paths = [ + tool_path( + name = "gcc", + path = "/usr/bin/arm-none-eabi-gcc", + ), + tool_path( + name = "ld", + path = "/usr/bin/arm-none-eabi-ld", + ), + tool_path( + name = "ar", + path = "/usr/bin/arm-none-eabi-ar", + ), + tool_path( + name = "cpp", + path = "/usr/bin/arm-none-eabi-cpp", + ), + tool_path( + name = "gcov", + path = "/usr/bin/arm-none-eabi-gcov", + ), + tool_path( + name = "nm", + path = "/usr/bin/arm-none-eabi-nm", + ), + tool_path( + name = "objdump", + path = "/usr/bin/arm-none-eabi-objdump", + ), + tool_path( + name = "strip", + path = "/usr/bin/arm-none-eabi-strip", + ), + ] + + features = [ + feature( + name = "architecture_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = _ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-mcpu=cortex-m4", + "-mfloat-abi=hard", + "-mfpu=fpv4-sp-d16", + "-fmessage-length=0", + ], + ), + ], + ), + ], + ), + feature( + name = "common_compile_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = _ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-Wno-psabi", + "-fdata-sections", + "-ffunction-sections", + "-fno-asynchronous-unwind-tables", + "-fno-builtin", + "-fno-common", + "-fshort-enums", + "-fstack-usage", + "-mno-unaligned-access", + "-mthumb", + ], + ), + ], + ), + ], + ), + feature( + name = "c_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = _ALL_C_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-ffreestanding", + "-funsigned-bitfields", + ], + ), + ], + ), + ], + ), + feature( + name = "cxx_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = _ALL_CXX_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-std=gnu++17", + "-fno-exceptions", + "-fno-non-call-exceptions", + "-fno-rtti", + "-fno-threadsafe-statics", + "-fno-use-cxa-atexit", + "-femit-class-debug-always", + "-funsigned-bitfields", + ], + ), + ], + ), + ], + ), + feature( + name = "assembler_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = _ALL_ASSEMBLE_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-g", + ], + ), + ], + ), + ], + ), + + feature( + name = "realtime_os_define", + enabled = True, + flag_sets = [ + flag_set( + actions = _ALL_COMPILE_ACTIONS, + flag_groups = [ + flag_group( + flags = ["-DREALTIME_OS=1"], + ), + ], + ), + ], + ), + feature( + name = "default_linker_flags", + enabled = True, + flag_sets = [ + flag_set( + actions = _ALL_LINK_ACTIONS, + flag_groups = [ + flag_group( + flags = [ + "-mcpu=cortex-m4", + "-mfloat-abi=hard", + "-mfpu=fpv4-sp-d16", + "-static", + "-Wl,--gc-sections", + "-specs=nano.specs", + "-specs=nosys.specs", + ], + ), + ], + ), + ], + ), + + # TODO: Verify if assumption is correct: bare-metal targets do not use PIC or dynamic linking + feature(name = "supports_pic", enabled = False), + feature(name = "supports_dynamic_linker", enabled = False), + ] + + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + features = features, + cxx_builtin_include_directories = [ + "/usr/lib/gcc/arm-none-eabi", + "/usr/include/newlib", + ], + toolchain_identifier = "arm_none_eabi_gcc_toolchain", + host_system_name = "local", + target_system_name = "arm-none-eabi", + target_cpu = "cortex-m4", + target_libc = "newlib-nano", + compiler = "gcc", + abi_version = "eabi", + abi_libc_version = "newlib", + tool_paths = tool_paths, + ) + +cc_toolchain_config = rule( + implementation = _impl, + attrs = {}, + provides = [CcToolchainConfigInfo], +) diff --git a/bazel_migration/README.md b/bazel_migration/README.md new file mode 100644 index 00000000000..382a466b49c --- /dev/null +++ b/bazel_migration/README.md @@ -0,0 +1,70 @@ +# Bazel migration for OpenBSW + + +## Status + + +- POC `arm-none-eabi-gcc` toolchain for `s32k148` target +- Toolchain setup is currently nonhermetic: host arm-none-eabi instance is used (compareable for Cmake) +- Build output for one example library (`libs/bsw/util`) verfied against CMake output. +- No further libraries or executables have been migrated yet. + + +Open: +- Clang toolchain +- Make toolchains hermetic +- Migration of all libs and executables +- Migration of unit test configs +``` +OpenBSW Bazel migration +├── bazel/ ✅ (toolchain arm-none-eabi-gcc for s32k148) +├── cmake/ ⬛ +├── doc/ ⬛ +├── docker/ ⬛ +├── executables/ +│ ├── referenceApp/ 🔲 +│ └── unitTest/ 🔲 +├── libs/ +│ ├── 3rdparty/ +│ │ └── etl ✅ +│ ├── bsw/ +│ │ ├── platform ✅ +│ │ └── util ✅ +│ └── (remaining) 🔲 +├── platforms/ +│ ├── posix/ 🔲 +│ └── s32k1xx/ 🔲 +├── test/ Scope of Bazel support TBD +└── tools/ Scope of Bazel support TBD + +✅ done +🔲 todo +⬛ not applicable +``` + +## Quick start + +```bash +# Build all targets for s32k148: +bazel build --config=s32k148 //... +# Build example target for s32k148: +bazel build --config=s32k148 //libs/bsw/util:util +``` + +## Toolchain verification +This directory contains build artifact comparisons for the the [s32k148 POC Bazel toolchain](../bazel/toolchain/BUILD) based on the following example: +- `libs/bsw/util` library and its dependencies: + - `libs/3rdparty/etl` + - `libs/bsw/platform` + +### Analysis scope + +The following properties were compared between the CMake (`s32k148-freertos-gcc / RelWithDebInfo`) and Bazel (`s32k148_relwithdebinfo`) builds: + +1. **File size** +2. **Translation units**: Comparison of compiled source files +3. **Symbol table**: Comparison of full symbol table after filtering out debug level information (`wm4.*` GCC debug path markers, `$d`/`$t` ARM section markers). + +### Files +- [`artifact_comparison_method.md`](artifact_comparison_method.md): Commands used to perform the analysis +- [`artifact_comparison__util.md`](artifact_comparison__util.md): Comparison results for `libs/bsw/util` \ No newline at end of file diff --git a/bazel_migration/artifact_comparison__util.md b/bazel_migration/artifact_comparison__util.md new file mode 100644 index 00000000000..6b0a87e75c9 --- /dev/null +++ b/bazel_migration/artifact_comparison__util.md @@ -0,0 +1,86 @@ +# Artifact Comparison: `util` (libs/bsw/util) + +| Artifact | Path | Config | +|---|---|---| +| CMake | `build/s32k148-freertos-gcc/libs/bsw/util/RelWithDebInfo/libutil.a` | s32k148-freertos-gcc / RelWithDebInfo | +| Bazel | `bazel-bin/libs/bsw/util/libutil.a` | s32k148-relwithdebinfo | + +--- + +## Size + +| Build | Size (bytes) | +|---|---| +| CMake | 5005278 | +| Bazel | 4992636 | + +--- + +## Translation Units + +**PASS** — 36 translation units present in both archives. Object file extension differs (`.cpp.obj` CMake vs `.o` Bazel). + +
+Object file list (36 entries) + +| CMake | Bazel | +|---|---| +| assert.cpp.obj | assert.o | +| AttributedString.cpp.obj | AttributedString.o | +| BuddyMemoryManager.cpp.obj | BuddyMemoryManager.o | +| ByteBufferOutputStream.cpp.obj | ByteBufferOutputStream.o | +| CommandContext.cpp.obj | CommandContext.o | +| ComponentInfo.cpp.obj | ComponentInfo.o | +| ConstString.cpp.obj | ConstString.o | +| GroupCommand.cpp.obj | GroupCommand.o | +| HelpCommand.cpp.obj | HelpCommand.o | +| LevelInfo.cpp.obj | LevelInfo.o | +| Logger.cpp.obj | Logger.o | +| LookupTable_0x07.cpp.obj | LookupTable_0x07.o | +| LookupTable_0x1021.cpp.obj | LookupTable_0x1021.o | +| LookupTable_0x1D.cpp.obj | LookupTable_0x1D.o | +| LookupTable_0x2F.cpp.obj | LookupTable_0x2F.o | +| LookupTable_0x31.cpp.obj | LookupTable_0x31.o | +| LookupTable_0x4C11DB7.cpp.obj | LookupTable_0x4C11DB7.o | +| LookupTable_0xCF.cpp.obj | LookupTable_0xCF.o | +| LookupTable_0xF4ACFB13.cpp.obj | LookupTable_0xF4ACFB13.o | +| NormalizeLfOutputStream.cpp.obj | NormalizeLfOutputStream.o | +| NullOutputStream.cpp.obj | NullOutputStream.o | +| ParentCommand.cpp.obj | ParentCommand.o | +| PrintfArgumentReader.cpp.obj | PrintfArgumentReader.o | +| PrintfFormatScanner.cpp.obj | PrintfFormatScanner.o | +| PrintfFormatter.cpp.obj | PrintfFormatter.o | +| SharedOutputStream.cpp.obj | SharedOutputStream.o | +| SharedStringWriter.cpp.obj | SharedStringWriter.o | +| SimpleCommand.cpp.obj | SimpleCommand.o | +| StdinStream.cpp.obj | StdinStream.o | +| StdoutStream.cpp.obj | StdoutStream.o | +| StringBufferOutputStream.cpp.obj | StringBufferOutputStream.o | +| StringWriter.cpp.obj | StringWriter.o | +| TaggedOutputHelper.cpp.obj | TaggedOutputHelper.o | +| TaggedOutputStream.cpp.obj | TaggedOutputStream.o | +| TaggedSharedOutputStream.cpp.obj | TaggedSharedOutputStream.o | +| Vt100AttributedStringFormatter.cpp.obj | Vt100AttributedStringFormatter.o | + +
+ +--- + +## Symbol Comparison + +**PASS** + +| Metric | CMake | Bazel | +|---|---|---| +| Strong defined symbols (T/B/D/R/C) | 229 | 229 | +| Strong defined symbols exclusive to one build (T/B/D/R/C) | 0 | 0 | + +
+Non-functional symbol differences (excluded from functional check) + +| Symbol type | Present in | Count | Category | +|---|---|---|---| +| n | CMake | 36 | Debug symbols | +| n | Bazel | 36 | Debug symbols | + +
\ No newline at end of file diff --git a/bazel_migration/artifact_comparison_method.md b/bazel_migration/artifact_comparison_method.md new file mode 100644 index 00000000000..ea3ee1923f8 --- /dev/null +++ b/bazel_migration/artifact_comparison_method.md @@ -0,0 +1,80 @@ +# Artifact comparison method + +## 1. Build + +```bash +cmake --build --preset s32k148-freertos-gcc --config RelWithDebInfo --target +bazel build --config=s32k148_relwithdebinfo //: +``` + +Set env vars for convenience: + +```bash +CMAKE_ARTIFACT=build/s32k148-freertos-gcc//RelWithDebInfo/lib.a +BAZEL_ARTIFACT=bazel-bin//lib.a +``` + +--- + +## 2. Size + +```bash +wc -c $CMAKE_ARTIFACT $BAZEL_ARTIFACT +``` + +--- + +## 3. Translation Units + +List the object files in each archive and compare stem names (object extensions differ between CMake and Bazel): + +```bash +diff -s --label cmake --label bazel \ + <(ar t $CMAKE_ARTIFACT | sed 's/\..*$//' | sort) \ + <(ar t $BAZEL_ARTIFACT | sed 's/\..*$//' | sort) +``` + +--- + +## 4. Symbol Comparison + +Assumption: Strong defined symbols (type `T`/`B`/`D`/`R`/`C`) represent the functional part of the artifact. Differences in other symbol types should be non-functional (debug symbols, local symbols, weak symbols, absolute symbols, ARM mapping symbols) and do not need to match. + +Extract the full symbol table (type + demangled name) for each artifact: +```bash +nm --demangle $CMAKE_ARTIFACT | awk 'NF >= 3 { print $2, $3 }' | sort > /tmp/cmake_symbols_raw.txt +nm --demangle $BAZEL_ARTIFACT | awk 'NF >= 3 { print $2, $3 }' | sort > /tmp/bazel_symbols_raw.txt +``` + +Filter for strong defined symbols and check for exclusive entries in either artifact: +```bash +grep '^[TBDRC] ' /tmp/cmake_symbols_raw.txt | sort > /tmp/cmake_symbols_strong.txt +grep '^[TBDRC] ' /tmp/bazel_symbols_raw.txt | sort > /tmp/bazel_symbols_strong.txt + +echo "cmake only:"; comm -23 /tmp/cmake_symbols_strong.txt /tmp/bazel_symbols_strong.txt +echo "bazel only:"; comm -13 /tmp/cmake_symbols_strong.txt /tmp/bazel_symbols_strong.txt +``` + +For non-functional differences, invert the filter and print the actual differing entries for each artifact: +```bash +grep -v '^[TBDRC] ' /tmp/cmake_symbols_raw.txt | sort > /tmp/cmake_symbols_nonfunc.txt +grep -v '^[TBDRC] ' /tmp/bazel_symbols_raw.txt | sort > /tmp/bazel_symbols_nonfunc.txt + +echo "cmake-only non-functional:"; comm -23 /tmp/cmake_symbols_nonfunc.txt /tmp/bazel_symbols_nonfunc.txt +echo "bazel-only non-functional:"; comm -13 /tmp/cmake_symbols_nonfunc.txt /tmp/bazel_symbols_nonfunc.txt +``` + +Optional: summarize those differences by type character: +```bash +echo "cmake-only non-functional counts:"; comm -23 /tmp/cmake_symbols_nonfunc.txt /tmp/bazel_symbols_nonfunc.txt | awk '{print $1}' | sort | uniq -c | sort -rn +echo "bazel-only non-functional counts:"; comm -13 /tmp/cmake_symbols_nonfunc.txt /tmp/bazel_symbols_nonfunc.txt | awk '{print $1}' | sort | uniq -c | sort -rn +``` + +Assumption: Non-functional symbols for `arm-none-eabi-gcc` include: +| Type | Meaning | +|---|---| +| `n` | Debug symbols — includes `wm4.*` GCC build-path markers | +| `t`/`d`/`b`/`r` | Local (file-scope) text/data/bss/rodata | +| `a` | Absolute symbols and file-name markers | +| `w`/`v` | Weak symbols and COMDAT guards (template instantiations, vtables) | +| `$t`/`$d`/`$a`/`$x` | ARM mapping symbols (section-type markers) | diff --git a/executables/referenceApp/etl_profile/BUILD b/executables/referenceApp/etl_profile/BUILD new file mode 100644 index 00000000000..ec927c71497 --- /dev/null +++ b/executables/referenceApp/etl_profile/BUILD @@ -0,0 +1,6 @@ +cc_library( + name = "etl_profile", + hdrs = ["etl_profile.h"], + strip_include_prefix = ".", + visibility = ["//libs/3rdparty/etl:__pkg__"], +) diff --git a/executables/unitTest/etl_profile/BUILD b/executables/unitTest/etl_profile/BUILD new file mode 100644 index 00000000000..ec927c71497 --- /dev/null +++ b/executables/unitTest/etl_profile/BUILD @@ -0,0 +1,6 @@ +cc_library( + name = "etl_profile", + hdrs = ["etl_profile.h"], + strip_include_prefix = ".", + visibility = ["//libs/3rdparty/etl:__pkg__"], +) diff --git a/libs/3rdparty/etl/BUILD b/libs/3rdparty/etl/BUILD new file mode 100644 index 00000000000..9c21418a8f5 --- /dev/null +++ b/libs/3rdparty/etl/BUILD @@ -0,0 +1,19 @@ + +alias( + name = "etl_profile", + actual = select({ + "//bazel/config/build_config:reference_app": "//executables/referenceApp/etl_profile", + "//bazel/config/build_config:unit_test": "//executables/unitTest/etl_profile", + "//conditions:default": "//executables/referenceApp/etl_profile", + }), +) + +cc_library( + name = "etl", + hdrs = glob(["include/**/*.h"]), + strip_include_prefix = "include", + visibility = ["//visibility:public"], + deps = [ + ":etl_profile", + ], +) diff --git a/libs/bsw/platform/BUILD b/libs/bsw/platform/BUILD new file mode 100644 index 00000000000..675866fd970 --- /dev/null +++ b/libs/bsw/platform/BUILD @@ -0,0 +1,6 @@ +cc_library( + name = "platform", + hdrs = glob(["include/**/*.h"]), + strip_include_prefix = "include", + visibility = ["//visibility:public"], +) diff --git a/libs/bsw/util/BUILD b/libs/bsw/util/BUILD new file mode 100644 index 00000000000..dce8f04c8ae --- /dev/null +++ b/libs/bsw/util/BUILD @@ -0,0 +1,48 @@ +cc_library( + name = "util", + srcs = [ + "src/util/estd/assert.cpp", + "src/util/logger/ComponentInfo.cpp", + "src/util/logger/Logger.cpp", + "src/util/logger/LevelInfo.cpp", + "src/util/memory/BuddyMemoryManager.cpp", + "src/util/stream/StdoutStream.cpp", + "src/util/stream/TaggedOutputHelper.cpp", + "src/util/stream/StdinStream.cpp", + "src/util/stream/ByteBufferOutputStream.cpp", + "src/util/stream/NormalizeLfOutputStream.cpp", + "src/util/stream/StringBufferOutputStream.cpp", + "src/util/stream/TaggedSharedOutputStream.cpp", + "src/util/stream/NullOutputStream.cpp", + "src/util/stream/SharedOutputStream.cpp", + "src/util/stream/TaggedOutputStream.cpp", + "src/util/crc/LookupTable_0x1D.cpp", + "src/util/crc/LookupTable_0x07.cpp", + "src/util/crc/LookupTable_0x1021.cpp", + "src/util/crc/LookupTable_0xF4ACFB13.cpp", + "src/util/crc/LookupTable_0x4C11DB7.cpp", + "src/util/crc/LookupTable_0xCF.cpp", + "src/util/crc/LookupTable_0x31.cpp", + "src/util/crc/LookupTable_0x2F.cpp", + "src/util/format/Vt100AttributedStringFormatter.cpp", + "src/util/format/PrintfFormatter.cpp", + "src/util/format/StringWriter.cpp", + "src/util/format/PrintfFormatScanner.cpp", + "src/util/format/AttributedString.cpp", + "src/util/format/PrintfArgumentReader.cpp", + "src/util/format/SharedStringWriter.cpp", + "src/util/string/ConstString.cpp", + "src/util/command/CommandContext.cpp", + "src/util/command/GroupCommand.cpp", + "src/util/command/SimpleCommand.cpp", + "src/util/command/HelpCommand.cpp", + "src/util/command/ParentCommand.cpp", + ], + hdrs = glob(["include/**/*.h"]), + strip_include_prefix = "include", + visibility = ["//visibility:public"], + deps = [ + "//libs/3rdparty/etl:etl", + "//libs/bsw/platform:platform", + ], +) From 7483ddf8658d36fe58b7e4421dac37798c33a90c Mon Sep 17 00:00:00 2001 From: Dominik Fischer Date: Thu, 7 May 2026 16:12:19 +0200 Subject: [PATCH 2/6] Implement reviewer suggestions - Use Docker-pinned arm-none-eabi toolchain for reproducible local Bazel builds - Add Bazel and Bazelisk cache directory mounts to development containers - Generate Bazel shell completion lazily on first shell start, persisted via cache mount - Use label_flag for etl_config - Rename build_config to executable_config to match naming in CMake - Document build configuration points and usage - Adjust util Bazel target sources to replicate recent changes on the Cmake side Change-Id: I48609afd53e88c6e24fcc6cbf4a5ecbbde3ca029 --- .bazelignore | 2 +- .bazelrc | 2 +- bazel/config/build_config/BUILD | 38 ------------------- bazel/config/executable_config/BUILD | 29 ++++++++++++++ .../arm_none_eabi_gcc_cc_toolchain_config.bzl | 22 ++++++----- bazel_migration/README.md | 30 ++++++++++++--- docker-compose.yaml | 22 +++++++++++ docker/development/Dockerfile | 11 ++++++ docker/development/files/.bashrc | 11 ++++++ libs/3rdparty/etl/BUILD | 12 ++++-- libs/bsw/util/BUILD | 1 - 11 files changed, 121 insertions(+), 59 deletions(-) delete mode 100644 bazel/config/build_config/BUILD create mode 100644 bazel/config/executable_config/BUILD diff --git a/.bazelignore b/.bazelignore index ced1c6b3457..a74b17b8304 100644 --- a/.bazelignore +++ b/.bazelignore @@ -2,4 +2,4 @@ # It will cause errors in Bazel if not ignored # A fixed version exists on the central Bazel registry that can be used on the Bazel side: # https://registry.bazel.build/modules/googletest/1.11.0 -libs/3rdparty/googletest \ No newline at end of file +libs/3rdparty/googletest diff --git a/.bazelrc b/.bazelrc index cab137025c0..6a0b100d22e 100644 --- a/.bazelrc +++ b/.bazelrc @@ -9,4 +9,4 @@ build:s32k148_relwithdebinfo --copt=-g3 build:s32k148_relwithdebinfo --copt=-O2 build:s32k148_relwithdebinfo --copt=-DNDEBUG -test --//bazel/config/build_config=unit_test +test --//bazel/config/executable_config=unit_test diff --git a/bazel/config/build_config/BUILD b/bazel/config/build_config/BUILD deleted file mode 100644 index eca86a34e10..00000000000 --- a/bazel/config/build_config/BUILD +++ /dev/null @@ -1,38 +0,0 @@ - -""" -Build configuration flag for selecting between application build variants. -This allows targets to define variable dependencies/headers/sources based on the -active build variant (reference_app or unit_test). - -Set via: -- --//bazel/config/build_config:build_config= -- Defaults to "reference_app" in general -- Overridden to "unit_test" for bazel test commands in .bazelrc - -NOTE: When adding variance using select() based on this configuration flag: -- Selects should be defined inside the consuming package's BUILD file. This avoids indirection, - keeps variant logic readable and provides a single point of change when adding new variants. -- If the config value is not logically tied to a package or used in many packages it may instead be - defined as a common config in bazel/build/config/: -- Selects should either inlcude a default or raise an specific error. -""" -load("@bazel_skylib//rules:common_settings.bzl", "string_flag") - -string_flag( - name = "build_config", - build_setting_default = "reference_app", - values = ["reference_app", "unit_test"], - visibility = ["//visibility:public"], -) - -config_setting( - name = "reference_app", - flag_values = {":build_config": "reference_app"}, - visibility = ["//visibility:public"], -) - -config_setting( - name = "unit_test", - flag_values = {":build_config": "unit_test"}, - visibility = ["//visibility:public"], -) diff --git a/bazel/config/executable_config/BUILD b/bazel/config/executable_config/BUILD new file mode 100644 index 00000000000..3daf05ca471 --- /dev/null +++ b/bazel/config/executable_config/BUILD @@ -0,0 +1,29 @@ +""" +Build configuration flag for selecting between application build variants. +This allows targets to define variable dependencies/headers/sources based on the +active build variant (reference_app or unit_test). + +- Set via --//bazel/config/executable_config= +- Defaults to "reference_app" +- Overridden to "unit_test" for bazel test commands in .bazelrc +""" +load("@bazel_skylib//rules:common_settings.bzl", "string_flag") + +string_flag( + name = "executable_config", + build_setting_default = "reference_app", + values = ["reference_app", "unit_test"], + visibility = ["//visibility:public"], +) + +config_setting( + name = "reference_app", + flag_values = {":executable_config": "reference_app"}, + visibility = ["//visibility:public"], +) + +config_setting( + name = "unit_test", + flag_values = {":executable_config": "unit_test"}, + visibility = ["//visibility:public"], +) diff --git a/bazel/toolchain/arm_none_eabi/gcc/arm_none_eabi_gcc_cc_toolchain_config.bzl b/bazel/toolchain/arm_none_eabi/gcc/arm_none_eabi_gcc_cc_toolchain_config.bzl index 1931868c9fe..ef510cfbc01 100644 --- a/bazel/toolchain/arm_none_eabi/gcc/arm_none_eabi_gcc_cc_toolchain_config.bzl +++ b/bazel/toolchain/arm_none_eabi/gcc/arm_none_eabi_gcc_cc_toolchain_config.bzl @@ -33,39 +33,41 @@ _ALL_ASSEMBLE_ACTIONS = [ ACTION_NAMES.preprocess_assemble, ] +_ARM_GNU_TOOLCHAIN_ROOT = "/opt/arm-gnu-toolchain" + def _impl(ctx): tool_paths = [ tool_path( name = "gcc", - path = "/usr/bin/arm-none-eabi-gcc", + path = _ARM_GNU_TOOLCHAIN_ROOT + "/bin/arm-none-eabi-gcc", ), tool_path( name = "ld", - path = "/usr/bin/arm-none-eabi-ld", + path = _ARM_GNU_TOOLCHAIN_ROOT + "/bin/arm-none-eabi-ld", ), tool_path( name = "ar", - path = "/usr/bin/arm-none-eabi-ar", + path = _ARM_GNU_TOOLCHAIN_ROOT + "/bin/arm-none-eabi-ar", ), tool_path( name = "cpp", - path = "/usr/bin/arm-none-eabi-cpp", + path = _ARM_GNU_TOOLCHAIN_ROOT + "/bin/arm-none-eabi-cpp", ), tool_path( name = "gcov", - path = "/usr/bin/arm-none-eabi-gcov", + path = _ARM_GNU_TOOLCHAIN_ROOT + "/bin/arm-none-eabi-gcov", ), tool_path( name = "nm", - path = "/usr/bin/arm-none-eabi-nm", + path = _ARM_GNU_TOOLCHAIN_ROOT + "/bin/arm-none-eabi-nm", ), tool_path( name = "objdump", - path = "/usr/bin/arm-none-eabi-objdump", + path = _ARM_GNU_TOOLCHAIN_ROOT + "/bin/arm-none-eabi-objdump", ), tool_path( name = "strip", - path = "/usr/bin/arm-none-eabi-strip", + path = _ARM_GNU_TOOLCHAIN_ROOT + "/bin/arm-none-eabi-strip", ), ] @@ -217,8 +219,8 @@ def _impl(ctx): ctx = ctx, features = features, cxx_builtin_include_directories = [ - "/usr/lib/gcc/arm-none-eabi", - "/usr/include/newlib", + _ARM_GNU_TOOLCHAIN_ROOT + "/lib/gcc/arm-none-eabi", + _ARM_GNU_TOOLCHAIN_ROOT + "/arm-none-eabi/include", ], toolchain_identifier = "arm_none_eabi_gcc_toolchain", host_system_name = "local", diff --git a/bazel_migration/README.md b/bazel_migration/README.md index 382a466b49c..19bc0c7bd5e 100644 --- a/bazel_migration/README.md +++ b/bazel_migration/README.md @@ -3,18 +3,20 @@ ## Status - - POC `arm-none-eabi-gcc` toolchain for `s32k148` target -- Toolchain setup is currently nonhermetic: host arm-none-eabi instance is used (compareable for Cmake) -- Build output for one example library (`libs/bsw/util`) verfied against CMake output. +- Toolchain reproducibility is provided by the Docker container (pins `arm-none-eabi-gcc` at a fixed version under `/opt/arm-gnu-toolchain`). This does not represent full hermeticity and would break cache correctness in remote cache scenarios. +- Build output for one example library (`libs/bsw/util`) verified against CMake output. +- Conditional dependency selection via `label_flag` (`etl_profile`) for build variants (`reference_app` / `unit_test`) - No further libraries or executables have been migrated yet. - Open: +- Bazel readme and integration guide +- Bazel CI tests - Clang toolchain -- Make toolchains hermetic +- Consider if toolchain should be made fully hermetic - Migration of all libs and executables - Migration of unit test configs + ``` OpenBSW Bazel migration ├── bazel/ ✅ (toolchain arm-none-eabi-gcc for s32k148) @@ -49,6 +51,24 @@ OpenBSW Bazel migration bazel build --config=s32k148 //... # Build example target for s32k148: bazel build --config=s32k148 //libs/bsw/util:util +# Run unit tests for s32k148: +bazel test --config=s32k148 //... +``` + +## Build Configuration + +Implemented config points: + +| Config point | Explanation | CLI | Bazel mechanism | Values | Default | +|---|---|---|---|---|---| +| [`platform`](../bazel/platform/BUILD) | Selects toolchain based on target platform | `--config=s32k148` | `platform` | `//bazel/platform:s32k148`, `@platforms//host` | `@platforms//host` | +| [`executable_config`](../bazel/config/executable_config/BUILD) | Controls executable config; `unit_test` is incompatible with baremetal platforms (e.g `s32k148`) | `--//bazel/config/executable_config` | `string_flag` | `reference_app`, `unit_test` | `reference_app`, `unit_test` (bazel test invocations) | +| [`etl_profile`](../libs/3rdparty/etl/BUILD) | Injects custom ETL profile; otherwise use default based on executable_config | `--//libs/3rdparty/etl:etl_profile` | `label_flag` | any `cc_library` label | `//executables/referenceApp/etl_profile` (`executable_config:reference_app`), `//executables/unitTest/etl_profile` (`executable_config:unit_test`) | + +Examples: +```bash +# Inject a custom ETL profile +bazel build --config=s32k148 --//libs/3rdparty/etl:etl_profile=//custom/path:my_profile //libs/3rdparty/etl:etl ``` ## Toolchain verification diff --git a/docker-compose.yaml b/docker-compose.yaml index f150161b641..61eb65cb283 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -39,6 +39,17 @@ services: target: /home/build/.bash_history bind: create_host_path: false + - type: bind + source: ${BAZEL_CACHE_DIR:-${XDG_CACHE_HOME:-${HOME}/.cache}/bazel} + target: /home/build/.cache/bazel + bind: + create_host_path: true + - type: bind + source: ${BAZELISK_CACHE_DIR:-${XDG_CACHE_HOME:-${HOME}/.cache}/bazelisk} + target: /home/build/.cache/bazelisk + bind: + create_host_path: true + development-sil: image: openbsw-development:local build: @@ -84,6 +95,17 @@ services: target: /lib/modules bind: create_host_path: false + - type: bind + source: ${BAZEL_CACHE_DIR:-${XDG_CACHE_HOME:-${HOME}/.cache}/bazel} + target: /home/build/.cache/bazel + bind: + create_host_path: true + - type: bind + source: ${BAZELISK_CACHE_DIR:-${XDG_CACHE_HOME:-${HOME}/.cache}/bazelisk} + target: /home/build/.cache/bazelisk + bind: + create_host_path: true + devices: - /dev/net/tun:/dev/net/tun cap_add: diff --git a/docker/development/Dockerfile b/docker/development/Dockerfile index 54d8cd2a2ab..4a2faaa48b0 100644 --- a/docker/development/Dockerfile +++ b/docker/development/Dockerfile @@ -13,6 +13,9 @@ RUN echo "f659c625302f6d3fb50f040f748206f6fd6bb1fc7e398057dd2deaf1c1f5e8d1 clang RUN wget -O treefmt.tar.gz https://github.com/numtide/treefmt/releases/download/v2.1.0/treefmt_2.1.0_linux_amd64.tar.gz RUN echo "ce0863a3a9d73707eb8cb9887c7f97ad3fd4ed506ad0429a6ab67a6290905966 treefmt.tar.gz" | sha256sum -c +RUN wget -O bazelisk https://github.com/bazelbuild/bazelisk/releases/download/v1.29.0/bazelisk-linux-amd64 +RUN echo "5a408715e932c0250d28bd84555f12edbf70117de42f9181691c736eacc4a992 bazelisk" | sha256sum -c + FROM base-image AS arm64-downloads RUN apt-get update && apt-get install -y wget @@ -25,6 +28,9 @@ RUN echo "0172cf1768072a398572cb1fc0bb42551d60181b3280f12c19401d94ca5162e6 clang RUN wget -O treefmt.tar.gz https://github.com/numtide/treefmt/releases/download/v2.1.0/treefmt_2.1.0_linux_arm64.tar.gz RUN echo "7c00ea14f69a95782063e8f86e143bede29c8a6757fea9075ffdfdb6590aa934 treefmt.tar.gz" | sha256sum -c +RUN wget -O bazelisk https://github.com/bazelbuild/bazelisk/releases/download/v1.29.0/bazelisk-linux-arm64 +RUN echo "e20e8b0f4f240091b7a55bf17b9398bd4f40ee70ae0208dff95dd4c445fb4010 bazelisk" | sha256sum -c + # Use TARGETARCH (docker built-in variable) to decide what external binary files to use ARG TARGETARCH FROM ${TARGETARCH}-downloads AS external-downloads @@ -71,6 +77,11 @@ RUN tar -xf treefmt.tar.gz \ && install -m 755 treefmt /usr/bin/treefmt \ && rm LICENSE README.md treefmt treefmt.tar.gz +COPY --from=external-downloads /bazelisk /bazelisk +RUN install -m 755 bazelisk /usr/bin/bazelisk \ + && ln -s bazelisk /usr/bin/bazel \ + && rm bazelisk + RUN gem install esr-rim diff --git a/docker/development/files/.bashrc b/docker/development/files/.bashrc index dce086f59a6..a7f1ee3ada5 100644 --- a/docker/development/files/.bashrc +++ b/docker/development/files/.bashrc @@ -1,2 +1,13 @@ [[ $- != *i* ]] && return export PS1="openbsw> $PS1" + +# Bazel shell completion, generated once, persisted via the bazelisk cache mount +_bazelisk_cache_dir="$HOME/.cache/bazelisk" +_bazel_completions="$_bazelisk_cache_dir/bazel-complete.bash" +if [[ ! -s "$_bazel_completions" ]]; then + # In case completions script does not exist generate completions script via bazelisk + mkdir -p "$_bazelisk_cache_dir" + bazelisk completion bash > "$_bazel_completions" +fi +[[ -s "$_bazel_completions" ]] && source "$_bazel_completions" +unset _bazelisk_cache_dir _bazel_completions diff --git a/libs/3rdparty/etl/BUILD b/libs/3rdparty/etl/BUILD index 9c21418a8f5..f76be4ed93f 100644 --- a/libs/3rdparty/etl/BUILD +++ b/libs/3rdparty/etl/BUILD @@ -1,13 +1,19 @@ alias( - name = "etl_profile", + name = "etl_profile_default", actual = select({ - "//bazel/config/build_config:reference_app": "//executables/referenceApp/etl_profile", - "//bazel/config/build_config:unit_test": "//executables/unitTest/etl_profile", + "//bazel/config/executable_config:reference_app": "//executables/referenceApp/etl_profile", + "//bazel/config/executable_config:unit_test": "//executables/unitTest/etl_profile", "//conditions:default": "//executables/referenceApp/etl_profile", }), ) +label_flag( + name = "etl_profile", + build_setting_default = ":etl_profile_default", + visibility = ["//visibility:public"], +) + cc_library( name = "etl", hdrs = glob(["include/**/*.h"]), diff --git a/libs/bsw/util/BUILD b/libs/bsw/util/BUILD index dce8f04c8ae..ea26ffb0c03 100644 --- a/libs/bsw/util/BUILD +++ b/libs/bsw/util/BUILD @@ -1,7 +1,6 @@ cc_library( name = "util", srcs = [ - "src/util/estd/assert.cpp", "src/util/logger/ComponentInfo.cpp", "src/util/logger/Logger.cpp", "src/util/logger/LevelInfo.cpp", From 50f3be9f88167dfe613d47943beb9bc81211e81c Mon Sep 17 00:00:00 2001 From: Dominik Fischer Date: Fri, 8 May 2026 09:36:02 +0200 Subject: [PATCH 3/6] Add BUILD file to etl's rim ignore list Change-Id: I4d67064e8878b9b531e2cee883e9042f7bb8232c --- .gitignore | 2 +- libs/3rdparty/etl/.riminfo | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index f401c6f036f..384f9204cda 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,4 @@ bazel-* bazel-bin bazel-openbsw bazel-out -bazel-testlogs \ No newline at end of file +bazel-testlogs diff --git a/libs/3rdparty/etl/.riminfo b/libs/3rdparty/etl/.riminfo index e8d37fda30c..51dc3cc2c7e 100644 --- a/libs/3rdparty/etl/.riminfo +++ b/libs/3rdparty/etl/.riminfo @@ -1,4 +1,4 @@ -72acaf0dd0fd518cebe8b8bbd71fafabc8a2c960 +97ed5eb3a8102ca4315ba91ed279501d5371871a RIM Info file. You're welcome to read but don't write it. Instead, use RIM commands to do the things you want to do. @@ -7,7 +7,7 @@ BEWARE: Any manual modification will invalidate the file! remote_url : https://github.com/ETLCPP/etl.git revision_sha1 : 912e22f238b707edc4d47d830f61f922cea79d70 target_revision: 20.47.1 -ignores : +ignores : BUILD checksum : 63cd7d58048e3958637b86cc2a0b501643643132 subdir : From b14ee53b8ec8174df632eddf53d60546144f6f43 Mon Sep 17 00:00:00 2001 From: Dominik Fischer Date: Fri, 8 May 2026 14:40:03 +0200 Subject: [PATCH 4/6] Remove artifact analysis documentation and results Change-Id: I5ee35aa720feeee2796ae41b213177d1e4f194f9 --- bazel_migration/README.md | 19 +--- bazel_migration/artifact_comparison__util.md | 86 ------------------- bazel_migration/artifact_comparison_method.md | 80 ----------------- 3 files changed, 3 insertions(+), 182 deletions(-) delete mode 100644 bazel_migration/artifact_comparison__util.md delete mode 100644 bazel_migration/artifact_comparison_method.md diff --git a/bazel_migration/README.md b/bazel_migration/README.md index 19bc0c7bd5e..b75c6795e4b 100644 --- a/bazel_migration/README.md +++ b/bazel_migration/README.md @@ -16,6 +16,7 @@ Open: - Consider if toolchain should be made fully hermetic - Migration of all libs and executables - Migration of unit test configs +- Toolchain / build artifact verification ``` OpenBSW Bazel migration @@ -71,20 +72,6 @@ Examples: bazel build --config=s32k148 --//libs/3rdparty/etl:etl_profile=//custom/path:my_profile //libs/3rdparty/etl:etl ``` -## Toolchain verification -This directory contains build artifact comparisons for the the [s32k148 POC Bazel toolchain](../bazel/toolchain/BUILD) based on the following example: -- `libs/bsw/util` library and its dependencies: - - `libs/3rdparty/etl` - - `libs/bsw/platform` +## Toolchain Verification -### Analysis scope - -The following properties were compared between the CMake (`s32k148-freertos-gcc / RelWithDebInfo`) and Bazel (`s32k148_relwithdebinfo`) builds: - -1. **File size** -2. **Translation units**: Comparison of compiled source files -3. **Symbol table**: Comparison of full symbol table after filtering out debug level information (`wm4.*` GCC debug path markers, `$d`/`$t` ARM section markers). - -### Files -- [`artifact_comparison_method.md`](artifact_comparison_method.md): Commands used to perform the analysis -- [`artifact_comparison__util.md`](artifact_comparison__util.md): Comparison results for `libs/bsw/util` \ No newline at end of file +Basic toolchain verification and build artifact analysis have been performed for the example target `//libs/bsw/util:util` and its dependencies (`//libs/3rdparty/etl:etl`, `//libs/bsw/platform:platform`). The Bazel build (config `s32k148_relwithdebinfo`) output was compared against the CMake reference build (`s32k148-freertos-gcc / RelWithDebInfo` configuration), and the resulting artifacts were found to be functionally equivalent. A more detailed comparison and validation needs to be performed in a separate effort at a later point of time. \ No newline at end of file diff --git a/bazel_migration/artifact_comparison__util.md b/bazel_migration/artifact_comparison__util.md deleted file mode 100644 index 6b0a87e75c9..00000000000 --- a/bazel_migration/artifact_comparison__util.md +++ /dev/null @@ -1,86 +0,0 @@ -# Artifact Comparison: `util` (libs/bsw/util) - -| Artifact | Path | Config | -|---|---|---| -| CMake | `build/s32k148-freertos-gcc/libs/bsw/util/RelWithDebInfo/libutil.a` | s32k148-freertos-gcc / RelWithDebInfo | -| Bazel | `bazel-bin/libs/bsw/util/libutil.a` | s32k148-relwithdebinfo | - ---- - -## Size - -| Build | Size (bytes) | -|---|---| -| CMake | 5005278 | -| Bazel | 4992636 | - ---- - -## Translation Units - -**PASS** — 36 translation units present in both archives. Object file extension differs (`.cpp.obj` CMake vs `.o` Bazel). - -
-Object file list (36 entries) - -| CMake | Bazel | -|---|---| -| assert.cpp.obj | assert.o | -| AttributedString.cpp.obj | AttributedString.o | -| BuddyMemoryManager.cpp.obj | BuddyMemoryManager.o | -| ByteBufferOutputStream.cpp.obj | ByteBufferOutputStream.o | -| CommandContext.cpp.obj | CommandContext.o | -| ComponentInfo.cpp.obj | ComponentInfo.o | -| ConstString.cpp.obj | ConstString.o | -| GroupCommand.cpp.obj | GroupCommand.o | -| HelpCommand.cpp.obj | HelpCommand.o | -| LevelInfo.cpp.obj | LevelInfo.o | -| Logger.cpp.obj | Logger.o | -| LookupTable_0x07.cpp.obj | LookupTable_0x07.o | -| LookupTable_0x1021.cpp.obj | LookupTable_0x1021.o | -| LookupTable_0x1D.cpp.obj | LookupTable_0x1D.o | -| LookupTable_0x2F.cpp.obj | LookupTable_0x2F.o | -| LookupTable_0x31.cpp.obj | LookupTable_0x31.o | -| LookupTable_0x4C11DB7.cpp.obj | LookupTable_0x4C11DB7.o | -| LookupTable_0xCF.cpp.obj | LookupTable_0xCF.o | -| LookupTable_0xF4ACFB13.cpp.obj | LookupTable_0xF4ACFB13.o | -| NormalizeLfOutputStream.cpp.obj | NormalizeLfOutputStream.o | -| NullOutputStream.cpp.obj | NullOutputStream.o | -| ParentCommand.cpp.obj | ParentCommand.o | -| PrintfArgumentReader.cpp.obj | PrintfArgumentReader.o | -| PrintfFormatScanner.cpp.obj | PrintfFormatScanner.o | -| PrintfFormatter.cpp.obj | PrintfFormatter.o | -| SharedOutputStream.cpp.obj | SharedOutputStream.o | -| SharedStringWriter.cpp.obj | SharedStringWriter.o | -| SimpleCommand.cpp.obj | SimpleCommand.o | -| StdinStream.cpp.obj | StdinStream.o | -| StdoutStream.cpp.obj | StdoutStream.o | -| StringBufferOutputStream.cpp.obj | StringBufferOutputStream.o | -| StringWriter.cpp.obj | StringWriter.o | -| TaggedOutputHelper.cpp.obj | TaggedOutputHelper.o | -| TaggedOutputStream.cpp.obj | TaggedOutputStream.o | -| TaggedSharedOutputStream.cpp.obj | TaggedSharedOutputStream.o | -| Vt100AttributedStringFormatter.cpp.obj | Vt100AttributedStringFormatter.o | - -
- ---- - -## Symbol Comparison - -**PASS** - -| Metric | CMake | Bazel | -|---|---|---| -| Strong defined symbols (T/B/D/R/C) | 229 | 229 | -| Strong defined symbols exclusive to one build (T/B/D/R/C) | 0 | 0 | - -
-Non-functional symbol differences (excluded from functional check) - -| Symbol type | Present in | Count | Category | -|---|---|---|---| -| n | CMake | 36 | Debug symbols | -| n | Bazel | 36 | Debug symbols | - -
\ No newline at end of file diff --git a/bazel_migration/artifact_comparison_method.md b/bazel_migration/artifact_comparison_method.md deleted file mode 100644 index ea3ee1923f8..00000000000 --- a/bazel_migration/artifact_comparison_method.md +++ /dev/null @@ -1,80 +0,0 @@ -# Artifact comparison method - -## 1. Build - -```bash -cmake --build --preset s32k148-freertos-gcc --config RelWithDebInfo --target -bazel build --config=s32k148_relwithdebinfo //: -``` - -Set env vars for convenience: - -```bash -CMAKE_ARTIFACT=build/s32k148-freertos-gcc//RelWithDebInfo/lib.a -BAZEL_ARTIFACT=bazel-bin//lib.a -``` - ---- - -## 2. Size - -```bash -wc -c $CMAKE_ARTIFACT $BAZEL_ARTIFACT -``` - ---- - -## 3. Translation Units - -List the object files in each archive and compare stem names (object extensions differ between CMake and Bazel): - -```bash -diff -s --label cmake --label bazel \ - <(ar t $CMAKE_ARTIFACT | sed 's/\..*$//' | sort) \ - <(ar t $BAZEL_ARTIFACT | sed 's/\..*$//' | sort) -``` - ---- - -## 4. Symbol Comparison - -Assumption: Strong defined symbols (type `T`/`B`/`D`/`R`/`C`) represent the functional part of the artifact. Differences in other symbol types should be non-functional (debug symbols, local symbols, weak symbols, absolute symbols, ARM mapping symbols) and do not need to match. - -Extract the full symbol table (type + demangled name) for each artifact: -```bash -nm --demangle $CMAKE_ARTIFACT | awk 'NF >= 3 { print $2, $3 }' | sort > /tmp/cmake_symbols_raw.txt -nm --demangle $BAZEL_ARTIFACT | awk 'NF >= 3 { print $2, $3 }' | sort > /tmp/bazel_symbols_raw.txt -``` - -Filter for strong defined symbols and check for exclusive entries in either artifact: -```bash -grep '^[TBDRC] ' /tmp/cmake_symbols_raw.txt | sort > /tmp/cmake_symbols_strong.txt -grep '^[TBDRC] ' /tmp/bazel_symbols_raw.txt | sort > /tmp/bazel_symbols_strong.txt - -echo "cmake only:"; comm -23 /tmp/cmake_symbols_strong.txt /tmp/bazel_symbols_strong.txt -echo "bazel only:"; comm -13 /tmp/cmake_symbols_strong.txt /tmp/bazel_symbols_strong.txt -``` - -For non-functional differences, invert the filter and print the actual differing entries for each artifact: -```bash -grep -v '^[TBDRC] ' /tmp/cmake_symbols_raw.txt | sort > /tmp/cmake_symbols_nonfunc.txt -grep -v '^[TBDRC] ' /tmp/bazel_symbols_raw.txt | sort > /tmp/bazel_symbols_nonfunc.txt - -echo "cmake-only non-functional:"; comm -23 /tmp/cmake_symbols_nonfunc.txt /tmp/bazel_symbols_nonfunc.txt -echo "bazel-only non-functional:"; comm -13 /tmp/cmake_symbols_nonfunc.txt /tmp/bazel_symbols_nonfunc.txt -``` - -Optional: summarize those differences by type character: -```bash -echo "cmake-only non-functional counts:"; comm -23 /tmp/cmake_symbols_nonfunc.txt /tmp/bazel_symbols_nonfunc.txt | awk '{print $1}' | sort | uniq -c | sort -rn -echo "bazel-only non-functional counts:"; comm -13 /tmp/cmake_symbols_nonfunc.txt /tmp/bazel_symbols_nonfunc.txt | awk '{print $1}' | sort | uniq -c | sort -rn -``` - -Assumption: Non-functional symbols for `arm-none-eabi-gcc` include: -| Type | Meaning | -|---|---| -| `n` | Debug symbols — includes `wm4.*` GCC build-path markers | -| `t`/`d`/`b`/`r` | Local (file-scope) text/data/bss/rodata | -| `a` | Absolute symbols and file-name markers | -| `w`/`v` | Weak symbols and COMDAT guards (template instantiations, vtables) | -| `$t`/`$d`/`$a`/`$x` | ARM mapping symbols (section-type markers) | From 4dbedc8e844229eb1984f2eb5862a46c2bea1ba6 Mon Sep 17 00:00:00 2001 From: Dominik Fischer Date: Fri, 8 May 2026 15:20:08 +0200 Subject: [PATCH 5/6] Minor improvements - Rename BUILD files to BUILD.bazel - Remove redundant .gitignore - Add end of file newline Change-Id: Ib9b93b1affbb13fe1024a7a6045f2476091ba700 --- bazel/.gitignore | 8 -------- bazel/config/executable_config/{BUILD => BUILD.bazel} | 0 bazel/platform/{BUILD => BUILD.bazel} | 0 bazel/toolchain/{BUILD => BUILD.bazel} | 0 bazel_migration/README.md | 2 +- .../referenceApp/etl_profile/{BUILD => BUILD.bazel} | 0 executables/unitTest/etl_profile/{BUILD => BUILD.bazel} | 0 libs/bsw/platform/{BUILD => BUILD.bazel} | 0 libs/bsw/util/{BUILD => BUILD.bazel} | 0 9 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 bazel/.gitignore rename bazel/config/executable_config/{BUILD => BUILD.bazel} (100%) rename bazel/platform/{BUILD => BUILD.bazel} (100%) rename bazel/toolchain/{BUILD => BUILD.bazel} (100%) rename executables/referenceApp/etl_profile/{BUILD => BUILD.bazel} (100%) rename executables/unitTest/etl_profile/{BUILD => BUILD.bazel} (100%) rename libs/bsw/platform/{BUILD => BUILD.bazel} (100%) rename libs/bsw/util/{BUILD => BUILD.bazel} (100%) diff --git a/bazel/.gitignore b/bazel/.gitignore deleted file mode 100644 index 4fe6d2a4382..00000000000 --- a/bazel/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ - -bazel-bin -bazel-out -bazel-testlogs -bazel-* -.bazel-cache -.bazelrc.local -.bazelrc.user diff --git a/bazel/config/executable_config/BUILD b/bazel/config/executable_config/BUILD.bazel similarity index 100% rename from bazel/config/executable_config/BUILD rename to bazel/config/executable_config/BUILD.bazel diff --git a/bazel/platform/BUILD b/bazel/platform/BUILD.bazel similarity index 100% rename from bazel/platform/BUILD rename to bazel/platform/BUILD.bazel diff --git a/bazel/toolchain/BUILD b/bazel/toolchain/BUILD.bazel similarity index 100% rename from bazel/toolchain/BUILD rename to bazel/toolchain/BUILD.bazel diff --git a/bazel_migration/README.md b/bazel_migration/README.md index b75c6795e4b..1a528b951f2 100644 --- a/bazel_migration/README.md +++ b/bazel_migration/README.md @@ -74,4 +74,4 @@ bazel build --config=s32k148 --//libs/3rdparty/etl:etl_profile=//custom/path:my_ ## Toolchain Verification -Basic toolchain verification and build artifact analysis have been performed for the example target `//libs/bsw/util:util` and its dependencies (`//libs/3rdparty/etl:etl`, `//libs/bsw/platform:platform`). The Bazel build (config `s32k148_relwithdebinfo`) output was compared against the CMake reference build (`s32k148-freertos-gcc / RelWithDebInfo` configuration), and the resulting artifacts were found to be functionally equivalent. A more detailed comparison and validation needs to be performed in a separate effort at a later point of time. \ No newline at end of file +Basic toolchain verification and build artifact analysis have been performed for the example target `//libs/bsw/util:util` and its dependencies (`//libs/3rdparty/etl:etl`, `//libs/bsw/platform:platform`). The Bazel build (config `s32k148_relwithdebinfo`) output was compared against the CMake reference build (`s32k148-freertos-gcc / RelWithDebInfo` configuration), and the resulting artifacts were found to be functionally equivalent. A more detailed comparison and validation needs to be performed in a separate effort at a later point of time. diff --git a/executables/referenceApp/etl_profile/BUILD b/executables/referenceApp/etl_profile/BUILD.bazel similarity index 100% rename from executables/referenceApp/etl_profile/BUILD rename to executables/referenceApp/etl_profile/BUILD.bazel diff --git a/executables/unitTest/etl_profile/BUILD b/executables/unitTest/etl_profile/BUILD.bazel similarity index 100% rename from executables/unitTest/etl_profile/BUILD rename to executables/unitTest/etl_profile/BUILD.bazel diff --git a/libs/bsw/platform/BUILD b/libs/bsw/platform/BUILD.bazel similarity index 100% rename from libs/bsw/platform/BUILD rename to libs/bsw/platform/BUILD.bazel diff --git a/libs/bsw/util/BUILD b/libs/bsw/util/BUILD.bazel similarity index 100% rename from libs/bsw/util/BUILD rename to libs/bsw/util/BUILD.bazel From 9417724284b07d3d289d18d63e2f49ae3c1d7108 Mon Sep 17 00:00:00 2001 From: Dominik Fischer Date: Fri, 8 May 2026 17:16:44 +0200 Subject: [PATCH 6/6] Create cache dir with correct write permissions /home/build/.cache was created as root during image build, making it unwritable by the runtime UID injected via DOCKER_UID Change-Id: I34081b4e016a90baa46627774e04b47f17b01637 --- docker/development/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/development/Dockerfile b/docker/development/Dockerfile index 4a2faaa48b0..52e6bbaf83e 100644 --- a/docker/development/Dockerfile +++ b/docker/development/Dockerfile @@ -98,6 +98,7 @@ RUN --mount=type=bind,source=files/requirements.lock,target=/tmp/requirements.lo RUN useradd build RUN install -d /home/build --mode 0777 --owner build --group build +RUN install -d /home/build/.cache --mode 0777 --owner build --group build COPY --chown=build:build --chmod=0666 files/.bashrc /home/build/.bashrc COPY --chown=build:build --chmod=0666 files/.bash_profile /home/build/.bash_profile