[llvm-branch-commits] [libc] [llvm] [libc][bazel] Add targets for startup objects on linux (PR #218995)
Alexey Samsonov via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Aug 27 14:50:33 PDT 2026
================
@@ -0,0 +1,176 @@
+# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+"""LLVM libc starlark rules for building startup objects."""
+
+load("@bazel_skylib//lib:paths.bzl", "paths")
+load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES")
+load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain", "use_cc_toolchain")
+load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
+load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
+load("//libc:libc_build_rules.bzl", "libc_startup_library")
+
+def _get_compilation_outputs(deps):
+ outputs = []
+ for dep in deps:
+ if OutputGroupInfo in dep and "compilation_outputs" in dep[OutputGroupInfo]:
+ outputs.extend(dep[OutputGroupInfo].compilation_outputs.to_list())
+ return outputs
+
+def _extract_object_file_impl(ctx):
+ output = ctx.actions.declare_file(ctx.label.name + ".o")
+ input_objs = _get_compilation_outputs([ctx.attr.dep])
+ if len(input_objs) != 1:
+ fail("Expected exactly one input object, got: {}".format(input_objs))
+
+ input_obj = input_objs[0]
+
+ ctx.actions.symlink(
+ output = output,
+ target_file = input_obj,
+ )
+
+ return [DefaultInfo(files = depset([output]))]
+
+_extract_object_file = rule(
+ implementation = _extract_object_file_impl,
+ attrs = {
+ "dep": attr.label(
+ mandatory = True,
+ providers = [CcInfo],
+ ),
+ },
+)
+
+def libc_startup_object(name, src, visibility = None, **kwargs):
+ """Compiles a C++ source file into a startup object file.
+
+ Args:
+ name: The name of the target.
+ src: The C++ source file to compile.
+ visibility: Visibility of targets created by this macro.
----------------
vonosmas wrote:
Why do we care about visibility here?
https://github.com/llvm/llvm-project/pull/218995
More information about the llvm-branch-commits
mailing list