From 112a8e46238b74a7556ecefe6e207b75386d0d4f Mon Sep 17 00:00:00 2001 From: "Yurii T." Date: Wed, 11 Mar 2026 01:23:35 +0000 Subject: [PATCH 1/6] Add Linux aarch64 libs --- cc/deps/cc_toolchain_deps.bzl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cc/deps/cc_toolchain_deps.bzl b/cc/deps/cc_toolchain_deps.bzl index a3e4c960..127b2d88 100644 --- a/cc/deps/cc_toolchain_deps.bzl +++ b/cc/deps/cc_toolchain_deps.bzl @@ -274,6 +274,28 @@ def cc_toolchain_deps(): mirrored_tar_sha256 = "26a52cc6c658736f822546f220216178ac50d75ac1809bf8608395c8edd7c2c1", build_file = Label("//cc/config:llvm18_linux_aarch64.BUILD"), strip_prefix = "clang+llvm-18.1.8-aarch64-linux-gnu", + remote_file_urls = { + "lib/libz.so.1": ["https://storage.googleapis.com/ml-sysroot-testing/llvm/aarch64-linux/v2/libz.so.1"], + "lib/libz-copyright.txt": ["https://storage.googleapis.com/ml-sysroot-testing/llvm/aarch64-linux/v2/libz-copyright.txt"], + "lib/liblzma.so.5": ["https://storage.googleapis.com/ml-sysroot-testing/llvm/aarch64-linux/v2/liblzma.so.5"], + "lib/liblzma-copying.GPLv2.txt": ["https://storage.googleapis.com/ml-sysroot-testing/llvm/aarch64-linux/v2/liblzma-copying.GPLv2.txt"], + "lib/liblzma-copying.GPLv3.txt": ["https://storage.googleapis.com/ml-sysroot-testing/llvm/aarch64-linux/v2/liblzma-copying.GPLv3.txt"], + "lib/liblzma-copying.LGPLv2.1.txt": ["https://storage.googleapis.com/ml-sysroot-testing/llvm/aarch64-linux/v2/liblzma-copying.LGPLv2.1.txt"], + "lib/liblzma-copying.txt": ["https://storage.googleapis.com/ml-sysroot-testing/llvm/aarch64-linux/v2/liblzma-copying.txt"], + "lib/libxml2.so.2": ["https://storage.googleapis.com/ml-sysroot-testing/llvm/aarch64-linux/v2/libxml2.so.2"], + "lib/libxml2-copyright.txt": ["https://storage.googleapis.com/ml-sysroot-testing/llvm/aarch64-linux/v2/libxml2-copyright.txt"], + }, + remote_file_integrity = { + "lib/libz.so.1": "sha256-rV8Qd2EfXMqm3NRHq71bROnQrI8CR/8dtEGj7VJHAFg=", + "lib/libz-copyright.txt": "sha256-xLXv1S2NZl8XVG5po6j8G5AyOG3JaS2cei2cgBy63+Q=", + "lib/liblzma.so.5": "sha256-xnKtiQ6N5HGZ4/LZwFnXAV4tFdsp3N4m03jnEmsXEtU=", + "lib/liblzma-copying.GPLv2.txt": "sha256-qxX9UmvY3Rip5368E5ZWv00z6X/HI4zRG/YOK5uGZsY=", + "lib/liblzma-copying.GPLv3.txt": "sha256-jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM=", + "lib/liblzma-copying.LGPLv2.1.txt": "sha256-4jf6VmaAMOkoVR3dYPBd9f6Vf3XquHS70Bfghe1yLnw=", + "lib/liblzma-copying.txt": "sha256-SDmAFuIPkWdsEeUNUGbSZor9o8Fhp13P1HMR9S8iDxQ=", + "lib/libxml2.so.2": "sha256-9ckknFripHulRXSH/sHWYkczPD/oRFjbVrapESa8n+I=", + "lib/libxml2-copyright.txt": "sha256-XUhziEqJASKkubIK1WrG99odeWpb/PBKQnlwrJYhdiY=", + }, ) if "llvm20_linux_aarch64" not in native.existing_rules(): From 7e315f6b2480d23c7ed93555a1e53ed534519645 Mon Sep 17 00:00:00 2001 From: "Yurii T." Date: Tue, 19 May 2026 22:57:57 +0000 Subject: [PATCH 2/6] Update Linux aarch64 configuration --- cc/impls/linux_x86_64_linux_aarch64/BUILD | 90 ++++++++++++----------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/cc/impls/linux_x86_64_linux_aarch64/BUILD b/cc/impls/linux_x86_64_linux_aarch64/BUILD index fa2dd9f1..eff4587a 100644 --- a/cc/impls/linux_x86_64_linux_aarch64/BUILD +++ b/cc/impls/linux_x86_64_linux_aarch64/BUILD @@ -17,8 +17,9 @@ # Tools: Linux x86_64, Sysroot: Linux aarch64 # ============================================================================== -load("@rules_cc//cc:defs.bzl", "cc_toolchain") - +load("//cc/sanitizers:features.bzl", + "cc_toolchain_import_asan_feature", + "cc_toolchain_import_tsan_feature") load("//third_party/rules_cc_toolchain:toolchain_config.bzl", "cc_toolchain_config") load("//third_party/rules_cc_toolchain/features:cc_toolchain_import.bzl", "cc_toolchain_import") load("//third_party/rules_cc_toolchain/features:features.bzl", "cc_toolchain_import_feature") @@ -83,7 +84,7 @@ filegroup( filegroup( name = "compiler", srcs = [ - ":all", + ":imports", ":wrappers", "@llvm_linux_x86_64//:clang", "@llvm_linux_x86_64//:clang++", @@ -134,51 +135,52 @@ filegroup( ], ) +FEATURES_ESSENTIAL = [ + "//third_party/rules_cc_toolchain/features:hermetic_libraries", # Hermetic libraries feature required before import + ":imports_feature", + + # Toolchain configuration + "//third_party/rules_cc_toolchain/features:warnings", + "//third_party/rules_cc_toolchain/features:errors", + "//third_party/rules_cc_toolchain/features:reproducible", + "//third_party/rules_cc_toolchain/features:language", + "//third_party/rules_cc_toolchain/features:use_lld", + "//cc/features:sysroot_linux_aarch64", + ":startup_libs_feature", + "//third_party/rules_cc_toolchain/features:coverage", + #"//cc/features:clang19", # TODO: Add a selection mechanism based on the Clang version + + # PIC / PIE flags + "//third_party/rules_cc_toolchain/features:supports_pic", + "//third_party/rules_cc_toolchain/features:position_independent_code", + "//third_party/rules_cc_toolchain/features:position_independent_executable", + + # Optimization flags + "//third_party/rules_cc_toolchain/features:garbage_collect_symbols", + "//cc/features:constants_merge", + "//cc/features:dbg", + "//cc/features:fastbuild", + "//cc/features:opt", + "//cc/features:detect_issues", + "//cc/features:detect_issues_ext", + + # C++ standard flags + "//third_party/rules_cc_toolchain/features:c++11", + "//third_party/rules_cc_toolchain/features:c++14", + "//third_party/rules_cc_toolchain/features:c++17", + + # Other flags + "//cc/features:allow_shlib_undefined", + "//cc/features:supports_dynamic_linker", + "//cc/features:supports_start_end_lib_feature", +] + cc_toolchain_config( name = "config", archiver = "@llvm_linux_x86_64//:ar", c_compiler = "@llvm_linux_x86_64//:clang", cc_compiler = "@llvm_linux_x86_64//:clang++", - compiler_features = [ - # Hermetic libraries feature required before import. - "//third_party/rules_cc_toolchain/features:hermetic_libraries", - ":imports_feature", - - # Toolchain configuration - "//third_party/rules_cc_toolchain/features:warnings", - "//third_party/rules_cc_toolchain/features:errors", - "//third_party/rules_cc_toolchain/features:reproducible", - "//third_party/rules_cc_toolchain/features:language", - "//third_party/rules_cc_toolchain/features:use_lld", - "//cc/features:sysroot_linux_aarch64", - ":startup_libs_feature", - "//third_party/rules_cc_toolchain/features:coverage", - #"//cc/features:clang19", # TODO: Add a selection mechanism based on the Clang version - - # PIC / PIE flags - "//third_party/rules_cc_toolchain/features:supports_pic", - "//third_party/rules_cc_toolchain/features:position_independent_code", - "//third_party/rules_cc_toolchain/features:position_independent_executable", - - # Optimization flags - "//third_party/rules_cc_toolchain/features:garbage_collect_symbols", - "//cc/features:constants_merge", - "//cc/features:dbg", - "//cc/features:fastbuild", - "//cc/features:opt", - "//cc/features:detect_issues", - "//cc/features:detect_issues_ext", - - # C++ standard configuration - "//third_party/rules_cc_toolchain/features:c++11", - "//third_party/rules_cc_toolchain/features:c++14", - "//third_party/rules_cc_toolchain/features:c++17", - - # - "//cc/features:allow_shlib_undefined", - "//cc/features:supports_dynamic_linker", - "//cc/features:supports_start_end_lib_feature", - ], + compiler_features = FEATURES_ESSENTIAL, linker = "@llvm_linux_x86_64//:ld", strip_tool = "@llvm_linux_x86_64//:strip", target_cpu = "aarch64", @@ -196,5 +198,5 @@ cc_toolchain( strip_files = ":strip", supports_param_files = 1, toolchain_config = ":config", - toolchain_identifier = "toolchain_id_linux_x86_64_linux_aarch64", + toolchain_identifier = "toolchain_id_linux_x86_64_linux_aarch64_id", ) From 7a47c711908d6a083f015fd6180a9dc76dabb3f9 Mon Sep 17 00:00:00 2001 From: "Yurii T." Date: Wed, 20 May 2026 21:37:11 +0000 Subject: [PATCH 3/6] Create BUILD file for all needed architectures --- cc/impls/linux_x86_64_linux_aarch64/BUILD | 1 + cc/llvms/llvm.bzl | 16 ---------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/cc/impls/linux_x86_64_linux_aarch64/BUILD b/cc/impls/linux_x86_64_linux_aarch64/BUILD index eff4587a..89d9a27e 100644 --- a/cc/impls/linux_x86_64_linux_aarch64/BUILD +++ b/cc/impls/linux_x86_64_linux_aarch64/BUILD @@ -59,6 +59,7 @@ cc_toolchain_import( "@sysroot_linux_aarch64//:sys_incs", "@sysroot_linux_aarch64//:sys_libs", "@sysroot_linux_aarch64//:std_libs", + "@llvm_linux_aarch64//:libclang_rt", ], visibility = ["//visibility:public"], ) diff --git a/cc/llvms/llvm.bzl b/cc/llvms/llvm.bzl index d6becf77..ccfabbbb 100644 --- a/cc/llvms/llvm.bzl +++ b/cc/llvms/llvm.bzl @@ -21,17 +21,6 @@ load( _LLVM_VERSION = "LLVM_VERSION" _STATIC_LIBCXX = "STATIC_LIBCXX" -def _get_platform_arch(ctx): - """Gets current platform architecture""" - if ctx.os.arch == "amd64": - return "x86_64" - else: - return ctx.os.arch - -def _is_compatible_arch(ctx): - """Checks if LLVM compatible with current platform""" - return ctx.attr.name.endswith(_get_platform_arch(ctx)) - def _get_llvm_version_flag(ctx): """Returns LLVM version put as environment variable""" return get_host_environ(ctx, _LLVM_VERSION) @@ -62,11 +51,6 @@ def _create_version_file(ctx, major_version): ) def _llvm_impl(ctx): - if not _is_compatible_arch(ctx): - _create_version_file(ctx, "") - ctx.file("BUILD", "") - return - ver = _get_llvm_version(ctx) llvm_label = _get_llvm_label(ctx, ver) if not llvm_label: From 2485ba4bc7dcd6d1a4a1b504dc93e905a0e8ddc3 Mon Sep 17 00:00:00 2001 From: "Yurii T." Date: Thu, 21 May 2026 00:53:39 +0000 Subject: [PATCH 4/6] Add libc++ static linking and more tests for cross compilation --- .../cpu_linux_x86_64_linux_aarch64_build.yaml | 76 +++++++++++++++++++ cc/impls/linux_x86_64_linux_aarch64/BUILD | 26 ++++++- 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cpu_linux_x86_64_linux_aarch64_build.yaml b/.github/workflows/cpu_linux_x86_64_linux_aarch64_build.yaml index 31eeddb6..5df2f13f 100644 --- a/.github/workflows/cpu_linux_x86_64_linux_aarch64_build.yaml +++ b/.github/workflows/cpu_linux_x86_64_linux_aarch64_build.yaml @@ -60,9 +60,85 @@ jobs: --platforms=//common:linux_aarch64 \ //cc/tests/cpu:all + - name: "Clang 18, Glibc 2.27, libc++ static linking | Testing..." + run: | + bazel build --color=yes \ + --platforms=//common:linux_aarch64 \ + --@rules_ml_toolchain//common:stdlib=libc++ \ + --@rules_ml_toolchain//common:static_libcxx=true \ + //cc/tests/cpu:all + - name: "Bzlmod. Clang 18, Glibc 2.27 | Testing..." run: | bazel build --color=yes \ --platforms=//common:linux_aarch64 \ --config=bzlmod \ //cc/tests/cpu:all + + - name: "Bzlmod. Clang 18, Glibc 2.27, libc++ static linking | Testing..." + run: | + bazel build --color=yes \ + --platforms=//common:linux_aarch64 \ + --@rules_ml_toolchain//common:stdlib=libc++ \ + --@rules_ml_toolchain//common:static_libcxx=true \ + --config=bzlmod \ + //cc/tests/cpu:all + + - name: "Clang 21, Glibc 2.31 | Testing..." + run: | + bazel build --color=yes \ + --platforms=//common:linux_aarch64 \ + --repo_env=LLVM_VERSION=21 \ + --repo_env=SYSROOT_DIST=linux_glibc_2_31 \ + //cc/tests/cpu:all + + - name: "Bzlmod. Clang 21, Glibc 2.31 | Testing..." + run: | + bazel build --color=yes \ + --platforms=//common:linux_aarch64 \ + --repo_env=LLVM_VERSION=21 \ + --repo_env=SYSROOT_DIST=linux_glibc_2_31 \ + --config=bzlmod \ + //cc/tests/cpu:all + + # TODO: Replace `build` to `test` and run //cc/tests/cpu:all when GitHub runners will be updated to Ubuntu 24 + - name: "Bzlmod. Clang 22, Glibc 2.31 | Testing..." + run: | + bazel build --color=yes \ + --platforms=//common:linux_aarch64 \ + --repo_env=LLVM_VERSION=22 \ + --repo_env=SYSROOT_DIST=linux_glibc_2_31 \ + --config=bzlmod \ + //cc/tests/cpu:all + + - name: "Clang 21, Glibc 2.31, libc++ static linking | Testing..." + run: | + bazel build --color=yes \ + --platforms=//common:linux_aarch64 \ + --repo_env=LLVM_VERSION=21 \ + --repo_env=SYSROOT_DIST=linux_glibc_2_31 \ + --@rules_ml_toolchain//common:stdlib=libc++ \ + --@rules_ml_toolchain//common:static_libcxx=true \ + //cc/tests/cpu:all + + # TODO: Replace `build` to `test` and run //cc/tests/cpu:all when GitHub runners will be updated to Ubuntu 24 + - name: "Clang 22, Glibc 2.31, libc++ static linking | Testing..." + run: | + bazel build --color=yes \ + --platforms=//common:linux_aarch64 \ + --repo_env=LLVM_VERSION=22 \ + --repo_env=SYSROOT_DIST=linux_glibc_2_31 \ + --@rules_ml_toolchain//common:stdlib=libc++ \ + --@rules_ml_toolchain//common:static_libcxx=true \ + //cc/tests/cpu:all + + - name: "Bzlmod. Clang 22, Glibc 2.31, libc++ static linking | Testing..." + run: | + bazel build --color=yes \ + --platforms=//common:linux_aarch64 \ + --repo_env=LLVM_VERSION=22 \ + --repo_env=SYSROOT_DIST=linux_glibc_2_31 \ + --@rules_ml_toolchain//common:stdlib=libc++ \ + --@rules_ml_toolchain//common:static_libcxx=true \ + --config=bzlmod \ + //cc/tests/cpu:all diff --git a/cc/impls/linux_x86_64_linux_aarch64/BUILD b/cc/impls/linux_x86_64_linux_aarch64/BUILD index 89d9a27e..a770c6f2 100644 --- a/cc/impls/linux_x86_64_linux_aarch64/BUILD +++ b/cc/impls/linux_x86_64_linux_aarch64/BUILD @@ -17,6 +17,7 @@ # Tools: Linux x86_64, Sysroot: Linux aarch64 # ============================================================================== +load("//cc/config:constants.bzl", "LIBCXX_FLAGS") load("//cc/sanitizers:features.bzl", "cc_toolchain_import_asan_feature", "cc_toolchain_import_tsan_feature") @@ -50,15 +51,32 @@ cc_toolchain_import_feature( toolchain_import = ":startup_libs", ) +alias( + name = "std_incs", + actual = select({ + "//common:is_stdlib_libcxx": "@llvm_linux_aarch64//:std_incs" , + "//conditions:default": "@sysroot_linux_aarch64//:std_incs", + }) +) + +alias( + name = "std_libs", + actual = select({ + "//common:is_stdlib_libcxx": "@llvm_linux_aarch64//:std_libs" , + "//conditions:default": "@sysroot_linux_aarch64//:std_libs", + }) +) + # buildifier: leave-alone cc_toolchain_import( name = "imports", deps = [ - "@sysroot_linux_aarch64//:std_incs", + ":std_incs", "@llvm_linux_x86_64//:compiler_incs", "@sysroot_linux_aarch64//:sys_incs", "@sysroot_linux_aarch64//:sys_libs", - "@sysroot_linux_aarch64//:std_libs", + ":std_libs", + "@sysroot_linux_aarch64//:openmp", "@llvm_linux_aarch64//:libclang_rt", ], visibility = ["//visibility:public"], @@ -68,6 +86,10 @@ cc_toolchain_import_feature( name = "imports_feature", enabled = True, toolchain_import = ":imports", + static_link_flags = select({ + "//common:is_static_libcxx": LIBCXX_FLAGS, + "//conditions:default": [], + }), ) # buildifier: leave-alone From 41d85439bf461136e65748df2cbf466f1d0d82d7 Mon Sep 17 00:00:00 2001 From: "Yurii T." Date: Thu, 21 May 2026 01:22:29 +0000 Subject: [PATCH 5/6] Remove unused TSAN / ASAN support --- cc/impls/linux_x86_64_linux_aarch64/BUILD | 3 --- 1 file changed, 3 deletions(-) diff --git a/cc/impls/linux_x86_64_linux_aarch64/BUILD b/cc/impls/linux_x86_64_linux_aarch64/BUILD index a770c6f2..eac2bbc1 100644 --- a/cc/impls/linux_x86_64_linux_aarch64/BUILD +++ b/cc/impls/linux_x86_64_linux_aarch64/BUILD @@ -18,9 +18,6 @@ # ============================================================================== load("//cc/config:constants.bzl", "LIBCXX_FLAGS") -load("//cc/sanitizers:features.bzl", - "cc_toolchain_import_asan_feature", - "cc_toolchain_import_tsan_feature") load("//third_party/rules_cc_toolchain:toolchain_config.bzl", "cc_toolchain_config") load("//third_party/rules_cc_toolchain/features:cc_toolchain_import.bzl", "cc_toolchain_import") load("//third_party/rules_cc_toolchain/features:features.bzl", "cc_toolchain_import_feature") From 58986ce82fb11b5aa7f201da120601f0d2a26adc Mon Sep 17 00:00:00 2001 From: "Yurii T." Date: Thu, 21 May 2026 21:14:59 +0000 Subject: [PATCH 6/6] Update README.md file --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 19c12752..4fd99078 100644 --- a/README.md +++ b/README.md @@ -135,16 +135,15 @@ When the executor and the target are the same, a non-hermetic GPU build can stil For details, look at the `.bazelrc` file, specifically the `cuda_clang_local` configuration. - #### Build for Linux aarch64 `bazel build //cc/tests/cpu/... --platforms=//common:linux_aarch64` - +