Skip to content

Commit

Permalink
Fix cc_shared_libary to take into account linkstamps
Browse files Browse the repository at this point in the history
RELNOTES:none
PiperOrigin-RevId: 430726601
  • Loading branch information
oquenchil authored and fmeum committed Feb 24, 2022
1 parent c6a87cb commit 1892334
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/starlark/builtins_bzl/common/cc/cc_helper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def _stringify_linker_input(linker_input):
parts.append(additional_input.path)

for linkstamp in linker_input.linkstamps:
parts.append(linkstamp.file.path)
parts.append(linkstamp.file().path)

return "".join(parts)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ def _cc_shared_library_impl(ctx):
linking_contexts = [linking_context],
user_link_flags = user_link_flags,
additional_inputs = additional_inputs,
grep_includes = ctx.executable._grep_includes,
name = ctx.label.name,
output_type = "dynamic_library",
main_output = main_output,
Expand Down Expand Up @@ -593,6 +594,12 @@ cc_shared_library = rule(
"user_link_flags": attr.string_list(),
"_def_parser": semantics.get_def_parser(),
"_cc_toolchain": attr.label(default = "@" + semantics.get_repo() + "//tools/cpp:current_cc_toolchain"),
"_grep_includes": attr.label(
allow_files = True,
executable = True,
cfg = "exec",
default = Label("@" + semantics.get_repo() + "//tools/cpp:grep-includes"),
),
},
toolchains = ["@" + semantics.get_repo() + "//tools/cpp:toolchain_type"], # copybara-use-repo-external-label
fragments = ["google_cpp", "cpp"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ cc_library(
cc_library(
name = "qux",
srcs = ["qux.cc"],
linkstamp = "l.cc",
hdrs = ["qux.h"],
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2022 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
extern const char my_linkstamp[];

const char my_linkstamp[] = "0";
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _additional_inputs_test_impl(ctx):
actions = analysistest.target_actions(env)

found = False
for arg in actions[3].argv:
for arg in actions[4].argv:
if arg.find("-Wl,--script=") != -1:
asserts.equals(env, "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/additional_script.txt", arg[13:])
found = True
Expand Down
29 changes: 29 additions & 0 deletions tools/cpp/windows_cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ def _impl(ctx):
tools = [tool(path = ctx.attr.msvc_cl_path)],
)

linkstamp_compile_action = action_config(
action_name = ACTION_NAMES.linkstamp_compile,
implies = [
"compiler_input_flags",
"compiler_output_flags",
"default_compile_flags",
"nologo",
"msvc_env",
"parse_showincludes",
"user_compile_flags",
"sysroot",
"unfiltered_compile_flags",
],
tools = [tool(path = ctx.attr.msvc_cl_path)],
)

cpp_compile_action = action_config(
action_name = ACTION_NAMES.cpp_compile,
implies = [
Expand Down Expand Up @@ -255,6 +271,7 @@ def _impl(ctx):
assemble_action,
preprocess_assemble_action,
c_compile_action,
linkstamp_compile_action,
cpp_compile_action,
cpp_link_executable_action,
cpp_link_dynamic_library_action,
Expand Down Expand Up @@ -317,6 +334,7 @@ def _impl(ctx):
ACTION_NAMES.assemble,
ACTION_NAMES.preprocess_assemble,
ACTION_NAMES.c_compile,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_header_parsing,
ACTION_NAMES.cpp_module_compile,
Expand All @@ -343,6 +361,7 @@ def _impl(ctx):
actions = [
ACTION_NAMES.preprocess_assemble,
ACTION_NAMES.c_compile,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_header_parsing,
ACTION_NAMES.cpp_module_compile,
Expand Down Expand Up @@ -471,6 +490,7 @@ def _impl(ctx):
actions = [
ACTION_NAMES.preprocess_assemble,
ACTION_NAMES.c_compile,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_header_parsing,
ACTION_NAMES.cpp_module_compile,
Expand Down Expand Up @@ -629,6 +649,7 @@ def _impl(ctx):
env_set(
actions = [
ACTION_NAMES.c_compile,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_module_compile,
ACTION_NAMES.cpp_module_codegen,
Expand All @@ -650,6 +671,7 @@ def _impl(ctx):
ACTION_NAMES.assemble,
ACTION_NAMES.preprocess_assemble,
ACTION_NAMES.c_compile,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_header_parsing,
ACTION_NAMES.cpp_module_compile,
Expand Down Expand Up @@ -755,6 +777,7 @@ def _impl(ctx):
actions = [
ACTION_NAMES.preprocess_assemble,
ACTION_NAMES.c_compile,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_module_compile,
ACTION_NAMES.cpp_header_parsing,
Expand Down Expand Up @@ -805,6 +828,7 @@ def _impl(ctx):
ACTION_NAMES.assemble,
ACTION_NAMES.preprocess_assemble,
ACTION_NAMES.c_compile,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_header_parsing,
ACTION_NAMES.cpp_module_compile,
Expand Down Expand Up @@ -906,6 +930,7 @@ def _impl(ctx):
actions = [
ACTION_NAMES.preprocess_assemble,
ACTION_NAMES.c_compile,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_header_parsing,
ACTION_NAMES.cpp_module_compile,
Expand Down Expand Up @@ -951,6 +976,7 @@ def _impl(ctx):
flag_set(
actions = [
ACTION_NAMES.c_compile,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_module_compile,
ACTION_NAMES.cpp_module_codegen,
Expand Down Expand Up @@ -992,6 +1018,7 @@ def _impl(ctx):
ACTION_NAMES.assemble,
ACTION_NAMES.preprocess_assemble,
ACTION_NAMES.c_compile,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_header_parsing,
ACTION_NAMES.cpp_module_compile,
Expand Down Expand Up @@ -1028,6 +1055,7 @@ def _impl(ctx):
env_set(
actions = [
ACTION_NAMES.c_compile,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_module_compile,
ACTION_NAMES.cpp_module_codegen,
Expand Down Expand Up @@ -1114,6 +1142,7 @@ def _impl(ctx):
env_set(
actions = [
ACTION_NAMES.c_compile,
ACTION_NAMES.linkstamp_compile,
ACTION_NAMES.cpp_compile,
ACTION_NAMES.cpp_module_compile,
ACTION_NAMES.cpp_module_codegen,
Expand Down

0 comments on commit 1892334

Please sign in to comment.