Skip to content

Commit

Permalink
Merge branch 'google:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
TanukiMa authored Jan 22, 2025
2 parents 6fa3a35 + be17aff commit f5b9bbf
Show file tree
Hide file tree
Showing 5 changed files with 361 additions and 293 deletions.
12 changes: 0 additions & 12 deletions src/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,6 @@ test:macos_env --test_tag_filters=-nomac
build:windows_env --build_tag_filters=-nowin
test:windows_env --test_tag_filters=-nowin

# Bazel does not register cc toolchains for Windows by default.
# We need to explicitly specify them to be compatible with the new behavior
# introduced by --incompatible_enable_cc_toolchain_resolution
# https://github.com/google/mozc/issues/1112
# https://bazel.build/extending/toolchains#registering-building-toolchains
build:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-arm64_windows
build:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-x64_windows
build:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-x64_x86_windows
test:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-arm64_windows
test:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-x64_windows
test:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-x64_x86_windows

# Android specific options
build:android_env --copt "-DOS_ANDROID"
build:android_env --build_tag_filters=-noandroid
Expand Down
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
18 changes: 18 additions & 0 deletions src/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# MODULE.bazel is the new dependency configuration system (Bzlmod), but not used yet by default.
# To use Bzlmod, you need to specify --enable_bzlmod to the Bazel command or modify .bazelrc.
module(name = "mozc")

# abseil-cpp with patches for Bazel 8.0.0 is used instead of the local Abseil in third_party/.
# Otherwise, `bazel fetch` will fail with the error: "cc_configure_extension no longer available".
Expand Down Expand Up @@ -66,12 +67,29 @@ bazel_dep(
)

# Apple Support for Bazel (1.16.0 2024-07-10)
## this must come above 'rules_cc'
## https://github.com/bazelbuild/apple_support/blob/d87e8b07f3345e750834dbb6ce38c7c7d3b8b44b/README.md#bazel-7-setup
bazel_dep(
name = "apple_support",
version = "1.16.0",
repo_name = "build_bazel_apple_support",
)

# rules_cc: 0.0.17 2024-11-19
# https://github.com/bazelbuild/rules_cc/
bazel_dep(
name = "rules_cc",
version = "0.0.17",
)

cc_configure = use_extension(
"@rules_cc//cc:extensions.bzl",
"cc_configure_extension",
)
use_repo(cc_configure, "local_config_cc")

register_toolchains("@local_config_cc//:all")

# Android NDK rules (0.1.2 2024-07-23)
# https://github.com/bazelbuild/rules_android_ndk
bazel_dep(
Expand Down
83 changes: 72 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.append("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,45 @@ 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%",
])

# '/CETCOMPAT' is available only on x86/x64 architectures.
if cpu in ["@platforms//cpu:x86_32", "@platforms//cpu:x86_64"]:
modified_linkopts.append("/CETCOMPAT")

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 +372,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 +391,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 +452,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
Loading

0 comments on commit f5b9bbf

Please sign in to comment.