Skip to content

Commit

Permalink
Generate PDB file from mozc_win32_cc_prod_binary (google#1109)
Browse files Browse the repository at this point in the history
While 'rules_cc' provides 'generate_pdb_file' feature to generate the
PDB file, its filename is not hard-coded and not configurable. For
instance, if the target name is 'mozc_tip32', then the output pdb file
is always assumed to be 'mozc_tip32.pdb'. To make it
'mozc_tip32.dll.pdb', the target name must be 'mozc_tip32.dll.dll'.

This is why 'intermediate_name' is introduced in
'mozc_win32_cc_prod_binary'.

There must be no observable change in GYP build and non-Windows bazel
builds.

Closes google#1108.

PiperOrigin-RevId: 717739005
  • Loading branch information
yukawa authored Jan 21, 2025
1 parent b878663 commit 51b4cd0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ bzl_library(
"//bazel:run_build_tool_bzl",
"//bazel:stubs.bzl",
"//devtools/build_cleaner/skylark:build_defs_lib",
"@bazel_skylib//rules:select_file",
"@build_bazel_rules_apple//apple:macos",
],
)
Expand Down
78 changes: 67 additions & 11 deletions src/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ See also: https://bazel.build/rules/bzl-style#rules
"""

load("@bazel_skylib//rules:select_file.bzl", "select_file")
load("@build_bazel_rules_apple//apple:macos.bzl", "macos_application", "macos_bundle", "macos_unit_test")
load("@windows_sdk//:windows_sdk_rules.bzl", "windows_resource")
load(
Expand Down Expand Up @@ -207,9 +208,9 @@ register_extension_info(
def _win_executable_transition_impl(
settings, # @unused
attr):
features = []
features = ["generate_pdb_file"]
if attr.static_crt:
features = ["static_link_msvcrt"]
features += ["static_link_msvcrt"]
return {
"//command_line_option:features": features,
"//command_line_option:platforms": [attr.platform],
Expand Down Expand Up @@ -238,10 +239,15 @@ def _mozc_win_build_rule_impl(ctx):
target_file = input_file,
is_executable = True,
)
return [DefaultInfo(
files = depset([output]),
executable = output,
)]
return [
DefaultInfo(
files = depset([output]),
executable = output,
),
OutputGroupInfo(
pdb_file = depset(ctx.files.pdb_file),
),
]

CPU = struct(
ARM64 = "@platforms//cpu:arm64", # aarch64 (64-bit) environment
Expand All @@ -261,6 +267,10 @@ _mozc_win_build_rule = rule(
doc = "the actual Bazel target to be built.",
mandatory = True,
),
"pdb_file": attr.label(
allow_files = True,
mandatory = True,
),
"static_crt": attr.bool(),
"platform": attr.label(),
},
Expand Down Expand Up @@ -306,17 +316,40 @@ def mozc_win32_cc_prod_binary(
visibility: optional. The visibility of the target.
**kwargs: other arguments passed to mozc_cc_binary.
"""
target_name = name + "_cc_binary"
target_name = executable_name_map.get(BRANDING, None)
if target_name == None:
return

intermediate_name = None
if target_name.endswith(".exe"):
# When the targete name is "foobar.exe", then "foobar.exe.dll" will be
# generated.
intermediate_name = target_name
elif target_name.endswith(".dll"):
# When the targete name is "foobar.dll", then "foobar.pdb" will be
# generated. To produce "foobar.dll.pdb", the target name needs to be
# something like "foobar.dll.dll".
intermediate_name = target_name + ".dll"
linkshared = True
else:
return

modified_linkopts = []
modified_linkopts.extend(linkopts)
modified_linkopts.extend([
"/DEBUG:FULL",
"/PDBALTPATH:%_PDB%",
])
mozc_cc_binary(
name = target_name,
name = intermediate_name,
srcs = srcs,
deps = deps,
features = features,
linkopts = linkopts,
linkopts = modified_linkopts,
linkshared = linkshared,
tags = tags,
target_compatible_with = target_compatible_with,
visibility = visibility,
visibility = ["//visibility:private"],
win_def_file = win_def_file,
**kwargs
)
Expand All @@ -334,6 +367,13 @@ def mozc_win32_cc_prod_binary(
if item not in tags:
tags.append(item)

native.filegroup(
name = intermediate_name + "_pdb_file",
srcs = [intermediate_name],
output_group = "pdb_file",
visibility = ["//visibility:private"],
)

platform_name = "_" + name + "_platform"
native.platform(
name = platform_name,
Expand All @@ -346,15 +386,30 @@ def mozc_win32_cc_prod_binary(

_mozc_win_build_rule(
name = name,
pdb_file = intermediate_name + "_pdb_file",
platform = platform_name,
static_crt = static_crt,
tags = tags,
target = target_name,
target = intermediate_name,
target_compatible_with = target_compatible_with,
visibility = visibility,
**kwargs
)

native.filegroup(
name = name + "_pdb_file",
srcs = [name],
output_group = "pdb_file",
visibility = ["//visibility:private"],
)

select_file(
name = name + ".pdb",
srcs = name + "_pdb_file",
subpath = target_name + ".pdb",
visibility = visibility,
)

def mozc_cc_win32_library(
name,
srcs = [],
Expand Down Expand Up @@ -392,6 +447,7 @@ def mozc_cc_win32_library(
name = cc_binary_target_name,
srcs = srcs,
deps = deps,
features = ["-generate_pdb_file"],
win_def_file = win_def_file,
linkshared = 1,
tags = tags,
Expand Down

0 comments on commit 51b4cd0

Please sign in to comment.