Skip to content

Allow .S files in C++ Starlark cc_common.compile.#13155

Closed
jin wants to merge 1 commit intobazelbuild:masterfrom
jin:cc_starlark_asm_w_preprocessor
Closed

Allow .S files in C++ Starlark cc_common.compile.#13155
jin wants to merge 1 commit intobazelbuild:masterfrom
jin:cc_starlark_asm_w_preprocessor

Conversation

@jin
Copy link
Copy Markdown
Member

@jin jin commented Mar 4, 2021

.S files are (typically handwritten) assembly files that require
preprocessing, compared to their lower-capital .s counterparts that can
be compiled directly into object files.

Native cc_library rules already allow .S files in srcs [1]. However, the
Starlark cc_common.compile srcs argument doesn't accept them. This
change adds .S files to the list of valid srcs for cc_common.compile.

This is required for building AOSP, as there are handwritten source files in
Android's libc with the .S extension [2] that will be compiled through
Starlark C++ rules, e.g. directly into .o files.

[1] https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java;l=280;drc=35de1e352459729f95d552b6ae5af9ce7d00a943
[2] https://cs.android.com/search?q=f:%5C.S$&sq=

.S files are (typically handwritten) assembly files that require
preprocessing, compared to their lower-capital .s counterparts that can
be compiled directly into object files.

Native cc_library rules already allow .S files in srcs [1]. However, the
Starlark cc_common.compile srcs argument doesn't accept them. This
change adds .S files to the list of valid srcs for cc_common.compile.

This is required for building AOSP, as there are handwritten source files in
Android's libc with the .S extension [2] that will be compiled through
Starlark C++ rules, e.g. directly into .o files.

[1]: https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java;l=280;drc=35de1e352459729f95d552b6ae5af9ce7d00a943
[2]: https://cs.android.com/search?q=f:%5C.S$&sq=
@jin jin requested a review from lberki as a code owner March 4, 2021 12:45
@google-cla google-cla Bot added the cla: yes label Mar 4, 2021
@lberki lberki requested review from oquenchil and removed request for lberki March 4, 2021 13:12
@jin jin added the team-Rules-CPP Issues for C++ rules label Mar 4, 2021
@jin
Copy link
Copy Markdown
Member Author

jin commented Mar 4, 2021

@oquenchil Imported this PR, happy to iterate here or in the internal CL.

@bazel-io bazel-io closed this in 4928295 Mar 5, 2021
philwo pushed a commit that referenced this pull request Apr 19, 2021
.S files are (typically handwritten) assembly files that require
preprocessing, compared to their lower-capital .s counterparts that can
be compiled directly into object files.

Native cc_library rules already allow .S files in srcs [1]. However, the
Starlark cc_common.compile srcs argument doesn't accept them. This
change adds .S files to the list of valid srcs for cc_common.compile.

This is required for building AOSP, as there are handwritten source files in
Android's libc with the .S extension [2] that will be compiled through
Starlark C++ rules, e.g. directly into .o files.

[1] https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java;l=280;drc=35de1e352459729f95d552b6ae5af9ce7d00a943
[2] https://cs.android.com/search?q=f:%5C.S$&sq=

Closes #13155.

PiperOrigin-RevId: 361106705
sfX-bot pushed a commit to AXP-OS/platform_build_bazel that referenced this pull request Jun 22, 2025
Instead of doing a full link with cc_library, this CL replaces the
native.cc_library call to an actual rule that calls into cc_common and
runs a compile, not link, on the input files, and returns a DefaultInfo
containing only the objects in compilation outputs.

The previous implementation would have built a static archive, which was
wrong.

This requires bazelbuild/bazel#13155 to be
merged first, since the cc_common.compile API today doesn't accept .S
files as inputs, which are valid assembly files.

$ bazel-dev --bazelrc=build/bazel/linux.bazelrc cquery 'kind(_cc_object, //bionic/libc:all)' --output=starlark --starlark:expr="str(target.label) + ' ' + ' '.join([f.basename for f in target.files.to_list()])"

//bionic/libc:crtbegin_dynamic crtbegin.o crtbrand.o
//bionic/libc:crtbegin_dynamic1 crtbegin.o
//bionic/libc:crtbegin_so crtbegin_so.o crtbrand.o
//bionic/libc:crtbegin_so1 crtbegin_so.o
//bionic/libc:crtbegin_static crtbegin.o crtbrand.o
//bionic/libc:crtbegin_static1 crtbegin.o
//bionic/libc:crtbrand crtbrand.o
//bionic/libc:crtend_android crtend.o
//bionic/libc:crtend_so crtend_so.o
//bionic/libc:libseccomp_gen_syscall_nrs_arm gen_syscall_nrs.o
//bionic/libc:libseccomp_gen_syscall_nrs_arm64 gen_syscall_nrs.o
//bionic/libc:libseccomp_gen_syscall_nrs_x86 gen_syscall_nrs_x86.o
//bionic/libc:libseccomp_gen_syscall_nrs_x86_64 gen_syscall_nrs_x86_64.o

Test: build/bazel/scripts/milestone-2/demo.sh full
Test: go tests
Change-Id: If1944afb66c756a656399972711491ba489410ec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes team-Rules-CPP Issues for C++ rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant