From 539dfc062820409e475fedc045e2a1da86d171bf Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Thu, 5 Dec 2024 13:24:26 +0900 Subject: [PATCH] Redesign Win32 build transition rules This reworks my previous commits [1][2][3], which aimed to make it configurable on which executable should be built with what build configurations (e.g. CRT link type, target CPU architecture). One thing we need to further consider is the debug symbol name embedded in each artifact executable [4]. To generate debug symbols one can use 'generate_pdb_file' feature. The issue is that the pdb filename is not configurable in 'rules_cc'. For instance, if the target name is 'mozc_tip32', then 'rules_cc' assumes that the output pdb file is always 'mozc_tip32.pdb'. To make it 'mozc_tip32.dll.pdb', the target name must be 'mozc_tip32.dll.dll'. This is why I had do rework Win32 build transition rules. Implementation note: * The reason why 'mozc_win32_cc_prod_binary' needs to be introduced is because the final executable name needs to be available as an input of 'mozc_cc_binary'. * 'mozc_cc_win32_library' also needs to be reworked so that 'generate_pdb_file' feature will not be applied to it. There must be no observable change in GYP build and non-Windows bazel builds. Closes #1108. [1]: 5efa371c639be5e06bdc797a9deef1dc53048f58 [2]: ff649883e8e9809e016cbb6f135134b2366c0eb2 [3]: ea55af0a4bdb7f785fa55ada6bcc44447707ff96 [4]: 0377ddd0b617c824b93d17e87bab028acc0ef3e7 --- src/BUILD.bazel | 1 + src/build_defs.bzl | 283 ++++++++++++++++++++++++- src/gui/tool/BUILD.bazel | 19 ++ src/renderer/win32/BUILD.bazel | 9 +- src/server/BUILD.bazel | 18 ++ src/win32/broker/BUILD.bazel | 10 +- src/win32/cache_service/BUILD.bazel | 10 +- src/win32/custom_action/BUILD.bazel | 11 +- src/win32/installer/BUILD.bazel | 104 ++------- src/win32/installer/build_installer.py | 3 + src/win32/installer/transition.bzl | 161 -------------- src/win32/tip/BUILD.bazel | 51 +++-- 12 files changed, 411 insertions(+), 269 deletions(-) delete mode 100644 src/win32/installer/transition.bzl diff --git a/src/BUILD.bazel b/src/BUILD.bazel index 45784be18..8a7972405 100644 --- a/src/BUILD.bazel +++ b/src/BUILD.bazel @@ -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", ], ) diff --git a/src/build_defs.bzl b/src/build_defs.bzl index 22055fb44..633892d30 100644 --- a/src/build_defs.bzl +++ b/src/build_defs.bzl @@ -42,10 +42,12 @@ 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( "//:config.bzl", + "BAZEL_TOOLS_PREFIX", "BRANDING", "MACOS_BUNDLE_ID_PREFIX", "MACOS_MIN_OS_VER", @@ -203,6 +205,257 @@ register_extension_info( label_regex_for_dep = "{extension_name}", ) +def _win_executable_transition_impl( + settings, # @unused + attr): + features = ["generate_pdb_file"] + if attr.static_crt: + features.append("static_link_msvcrt") + return { + "//command_line_option:features": features, + "//command_line_option:cpu": attr.cpu, + } + +_win_executable_transition = transition( + implementation = _win_executable_transition_impl, + inputs = [], + outputs = [ + "//command_line_option:features", + "//command_line_option:cpu", + ], +) + +def _mozc_win_build_rule_impl(ctx): + input_file = ctx.file.target + output = ctx.actions.declare_file( + ctx.label.name + ".symlink." + input_file.extension, + ) + if input_file.path == output.path: + fail("input=%s and output=%s are the same." % (input_file.path, output.path)) + + # Create a symlink as we do not need to create an actual copy. + ctx.actions.symlink( + output = output, + target_file = input_file, + is_executable = True, + ) + return [ + DefaultInfo( + files = depset([output]), + executable = output, + ), + OutputGroupInfo( + pdb_file = depset(ctx.files.pdb_file), + ), + ] + +# The follwoing CPU values are mentioned in https://bazel.build/configure/windows#build_cpp +CPU = struct( + ARM64 = "arm64_windows", # aarch64 (64-bit) environment + X64 = "x64_windows", # x86-64 (64-bit) environment + X86 = "x64_x86_windows", # x86 (32-bit) environment +) + +_mozc_win_build_rule = rule( + implementation = _mozc_win_build_rule_impl, + cfg = _win_executable_transition, + attrs = { + "_allowlist_function_transition": attr.label( + default = BAZEL_TOOLS_PREFIX + "//tools/allowlists/function_transition_allowlist", + ), + "target": attr.label( + allow_single_file = [".dll", ".exe"], + doc = "the actual Bazel target to be built.", + mandatory = True, + ), + "pdb_file": attr.label( + allow_files = True, + mandatory = True, + ), + "static_crt": attr.bool(), + "cpu": attr.string(), + }, +) + +def mozc_win32_cc_prod_binary( + name, + executable_name_map = {}, + srcs = [], + deps = [], + linkopts = [], + cpu = CPU.X64, + static_crt = False, + tags = MOZC_TAGS.WIN_ONLY, + win_def_file = None, + target_compatible_with = ["@platforms//os:windows"], + visibility = ["//visibility:public"], + **kwargs): + """A rule to build production binaries for Windows. + + This wraps mozc_cc_binary so that you can specify the target CPU + architecture and CRT linkage type in a declarative manner with also building + a debug symbol file (*.pdb). + + Implicit output targets: + name.pdb: A debug symbol file. + + Args: + name: name of the target. + executable_name_map: a map from the branding name to the executable name. + srcs: .cc files to build the executable. + deps: deps to build the executable. + linkopts: linker options to build the executable. + cpu: optional. The target CPU architecture. + static_crt: optional. True if the target should be built with static CRT. + tags: optional. Tags for both the library and unit test targets. + win_def_file: optional. win32 def file to define exported functions. + target_compatible_with: optional. Defines target platforms. + visibility: optional. The visibility of the target. + **kwargs: other arguments passed to mozc_cc_binary. + """ + mandatory_target_compatible_with = [ + "@platforms//os:windows", + ] + for item in mandatory_target_compatible_with: + if item not in target_compatible_with: + target_compatible_with.append(item) + + mandatory_tags = MOZC_TAGS.WIN_ONLY + for item in mandatory_tags: + if item not in tags: + tags.append(item) + + target_name = executable_name_map.get(BRANDING, None) + if target_name == None: + return + + linkshared = False + 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 = intermediate_name, + srcs = srcs, + deps = deps, + tags = tags, + linkshared = linkshared, + linkopts = modified_linkopts, + target_compatible_with = target_compatible_with, + visibility = ["//visibility:private"], + win_def_file = win_def_file, + **kwargs + ) + + native.filegroup( + name = intermediate_name + "_pdb_file", + srcs = [intermediate_name], + output_group = "pdb_file", + visibility = ["//visibility:private"], + ) + + _mozc_win_build_rule( + name = name, + target = intermediate_name, + pdb_file = intermediate_name + "_pdb_file", + cpu = cpu, + static_crt = static_crt, + target_compatible_with = target_compatible_with, + tags = tags, + 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, + ) + +register_extension_info( + extension = mozc_win32_cc_prod_binary, + label_regex_for_dep = "{extension_name}", +) + +def _win_library_transition_impl( + settings, # @unused + attr): # @unused + return { + "//command_line_option:features": [], + } + +def _mozc_win_library_transition_impl(ctx): + input_file = ctx.file.target + output = ctx.actions.declare_file( + ctx.label.name + "." + input_file.extension, + ) + if input_file.path == output.path: + fail("input=%d and output=%d are the same." % (input_file.path, output.path)) + + # Create a symlink as we do not need to create an actual copy. + ctx.actions.symlink( + output = output, + target_file = input_file, + is_executable = True, + ) + return [ + DefaultInfo( + files = depset([output]), + ), + OutputGroupInfo( + interface_library = depset(ctx.files.interface_library), + ), + ] + +_mozc_cc_win32_library_rule = rule( + implementation = _mozc_win_library_transition_impl, + cfg = transition( + implementation = _win_library_transition_impl, + inputs = [], + outputs = [ + "//command_line_option:features", + ], + ), + attrs = { + "_allowlist_function_transition": attr.label( + default = BAZEL_TOOLS_PREFIX + "//tools/allowlists/function_transition_allowlist", + ), + "target": attr.label( + allow_single_file = [".dll"], + doc = "the actual Bazel target to be built.", + mandatory = True, + ), + "interface_library": attr.label( + allow_files = [".lib"], + mandatory = True, + ), + }, +) + def mozc_cc_win32_library( name, srcs = [], @@ -227,17 +480,25 @@ def mozc_cc_win32_library( **kwargs: other args for cc_library. """ + mandatory_target_compatible_with = [ + "@platforms//os:windows", + ] + for item in mandatory_target_compatible_with: + if item not in target_compatible_with: + target_compatible_with.append(item) + # A DLL name, which actually will not be used in production. # e.g. "input_dll_fake.dll" vs "C:\Windows\System32\input.dll" # The actual DLL name should be specified in the LIBRARY section of # win_def_file. # https://learn.microsoft.com/en-us/cpp/build/reference/library - cc_binary_target_name = name + "_fake.dll" - filegroup_target_name = name + "_lib" + cc_binary_target_intermediate_name = name + "_fake" + cc_binary_target_name = cc_binary_target_intermediate_name + ".dll" + filegroup_target_name = name + "_lib_group" cc_import_taget_name = name + "_import" mozc_cc_binary( - name = cc_binary_target_name, + name = cc_binary_target_intermediate_name, srcs = srcs, deps = deps, win_def_file = win_def_file, @@ -248,6 +509,22 @@ def mozc_cc_win32_library( **kwargs ) + interface_library_name = filegroup_target_name + ".if.lib" + native.filegroup( + name = interface_library_name, + srcs = [":" + cc_binary_target_intermediate_name], + output_group = "interface_library", + tags = tags, + target_compatible_with = target_compatible_with, + visibility = ["//visibility:private"], + ) + + _mozc_cc_win32_library_rule( + name = cc_binary_target_name, + target = cc_binary_target_intermediate_name, + interface_library = interface_library_name, + ) + native.filegroup( name = filegroup_target_name, srcs = [":" + cc_binary_target_name], diff --git a/src/gui/tool/BUILD.bazel b/src/gui/tool/BUILD.bazel index f1fc5c3dc..0ccf15e50 100644 --- a/src/gui/tool/BUILD.bazel +++ b/src/gui/tool/BUILD.bazel @@ -32,6 +32,7 @@ load( "MOZC_TAGS", "mozc_cc_library", "mozc_select", + "mozc_win32_cc_prod_binary", "mozc_win32_resource_from_template", ) load("//:config.bzl", "BRANDING") @@ -132,6 +133,24 @@ mozc_cc_qt_binary( ), ) +mozc_win32_cc_prod_binary( + name = "mozc_tool_win", + cpu = "x64_windows", + executable_name_map = { + "Mozc": "mozc_tool.exe", + "GoogleJapaneseInput": "GoogleIMEJaTool.exe", + }, + static_crt = False, + tags = MOZC_TAGS.WIN_ONLY, + target_compatible_with = ["@platforms//os:windows"], + visibility = ["//:__subpackages__"], + deps = [ + ":mozc_tool_main_lib", + ":mozc_tool_win32_resource", + "@qt_win", + ], +) + mozc_macos_qt_application( name = "mozc_tool_macos", bundle_name = "MozcTool", diff --git a/src/renderer/win32/BUILD.bazel b/src/renderer/win32/BUILD.bazel index eb2a1c875..f27116551 100644 --- a/src/renderer/win32/BUILD.bazel +++ b/src/renderer/win32/BUILD.bazel @@ -35,6 +35,7 @@ load( "mozc_cc_binary", "mozc_cc_library", "mozc_cc_test", + "mozc_win32_cc_prod_binary", "mozc_win32_resource_from_template", ) @@ -44,9 +45,15 @@ package( features = ["gdi"], ) -mozc_cc_binary( +mozc_win32_cc_prod_binary( name = "win32_renderer_main", srcs = ["win32_renderer_main.cc"], + cpu = "x64_windows", + executable_name_map = { + "Mozc": "mozc_renderer.exe", + "GoogleJapaneseInput": "GoogleIMEJaRenderer.exe", + }, + static_crt = False, tags = MOZC_TAGS.WIN_ONLY, target_compatible_with = ["@platforms//os:windows"], visibility = ["//win32/installer:__subpackages__"], # Scheuklappen: keep diff --git a/src/server/BUILD.bazel b/src/server/BUILD.bazel index 2cdd43b19..50cb9acca 100644 --- a/src/server/BUILD.bazel +++ b/src/server/BUILD.bazel @@ -32,10 +32,12 @@ load( "//:build_defs.bzl", + "MOZC_TAGS", "mozc_cc_binary", "mozc_cc_library", "mozc_macos_application", "mozc_select", + "mozc_win32_cc_prod_binary", "mozc_win32_resource_from_template", ) load( @@ -55,6 +57,22 @@ mozc_cc_binary( ), ) +mozc_win32_cc_prod_binary( + name = "mozc_server_win", + cpu = "x64_windows", + executable_name_map = { + "Mozc": "mozc_server.exe", + "GoogleJapaneseInput": "GoogleIMEJaConverter.exe", + }, + static_crt = False, + tags = MOZC_TAGS.WIN_ONLY, + target_compatible_with = ["@platforms//os:windows"], + deps = [ + ":mozc_server_lib", + ":mozc_server_resources", + ], +) + mozc_win32_resource_from_template( name = "mozc_server_resources", src = "mozc_server.rc", diff --git a/src/win32/broker/BUILD.bazel b/src/win32/broker/BUILD.bazel index 88c068420..e8cc03a2a 100644 --- a/src/win32/broker/BUILD.bazel +++ b/src/win32/broker/BUILD.bazel @@ -32,8 +32,8 @@ load( "//:build_defs.bzl", "MOZC_TAGS", - "mozc_cc_binary", "mozc_cc_library", + "mozc_win32_cc_prod_binary", "mozc_win32_resource_from_template", ) @@ -41,9 +41,15 @@ package( default_visibility = ["//visibility:private"], ) -mozc_cc_binary( +mozc_win32_cc_prod_binary( name = "mozc_broker_main", srcs = ["mozc_broker_main.cc"], + cpu = "x64_windows", + executable_name_map = { + "Mozc": "mozc_broker.exe", + "GoogleJapaneseInput": "GoogleIMEJaBroker.exe", + }, + static_crt = False, tags = MOZC_TAGS.WIN_ONLY, target_compatible_with = ["@platforms//os:windows"], visibility = ["//win32/installer:__subpackages__"], # Scheuklappen: keep diff --git a/src/win32/cache_service/BUILD.bazel b/src/win32/cache_service/BUILD.bazel index 602518ffc..1241c0f42 100644 --- a/src/win32/cache_service/BUILD.bazel +++ b/src/win32/cache_service/BUILD.bazel @@ -35,16 +35,22 @@ load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") load( "//:build_defs.bzl", "MOZC_TAGS", - "mozc_cc_binary", "mozc_cc_library", + "mozc_win32_cc_prod_binary", "mozc_win32_resource_from_template", ) package(default_visibility = ["//:__subpackages__"]) -mozc_cc_binary( +mozc_win32_cc_prod_binary( name = "mozc_cache_service", srcs = ["mozc_cache_service.cc"], + cpu = "x64_windows", + executable_name_map = { + "Mozc": "mozc_cache_service.exe", + "GoogleJapaneseInput": "GoogleIMEJaCacheService.exe", + }, + static_crt = False, tags = MOZC_TAGS.WIN_ONLY, target_compatible_with = ["@platforms//os:windows"], deps = [ diff --git a/src/win32/custom_action/BUILD.bazel b/src/win32/custom_action/BUILD.bazel index d3182bb98..b17fbd488 100644 --- a/src/win32/custom_action/BUILD.bazel +++ b/src/win32/custom_action/BUILD.bazel @@ -30,18 +30,23 @@ load( "//:build_defs.bzl", "MOZC_TAGS", - "mozc_cc_binary", + "mozc_win32_cc_prod_binary", "mozc_win32_resource_from_template", ) -mozc_cc_binary( +mozc_win32_cc_prod_binary( name = "custom_action", srcs = [ "custom_action.cc", "custom_action.h", "resource.h", ], - linkshared = True, + cpu = "x64_windows", + executable_name_map = { + "Mozc": "mozc_installer_helper.dll", + "GoogleJapaneseInput": "GoogleIMEJaInstallerHelper.dll", + }, + static_crt = True, tags = MOZC_TAGS.WIN_ONLY, target_compatible_with = ["@platforms//os:windows"], visibility = ["//win32/installer:__subpackages__"], # Scheuklappen: keep diff --git a/src/win32/installer/BUILD.bazel b/src/win32/installer/BUILD.bazel index bb1231555..925f6ada1 100644 --- a/src/win32/installer/BUILD.bazel +++ b/src/win32/installer/BUILD.bazel @@ -29,9 +29,8 @@ # Build rules for the Windows installer. -load("//:build_defs.bzl", "MOZC_TAGS", "mozc_py_binary") +load("//:build_defs.bzl", "mozc_py_binary") load("//:config.bzl", "BRANDING") -load(":transition.bzl", "mozc_win_build_target") package(default_visibility = ["//visibility:private"]) @@ -39,73 +38,6 @@ _TARGET_COMPATIBLE_WITH = [ "@platforms//os:windows", ] -mozc_win_build_target( - name = "mozc_tool", - cpu = "x64_windows", - tags = MOZC_TAGS.WIN_ONLY, - target = "//gui/tool:mozc_tool", - target_compatible_with = _TARGET_COMPATIBLE_WITH, -) - -mozc_win_build_target( - name = "mozc_renderer", - cpu = "x64_windows", - tags = MOZC_TAGS.WIN_ONLY, - target = "//renderer/win32:win32_renderer_main", - target_compatible_with = _TARGET_COMPATIBLE_WITH, -) - -mozc_win_build_target( - name = "mozc_server", - cpu = "x64_windows", - tags = MOZC_TAGS.WIN_ONLY, - target = "//server:mozc_server", - target_compatible_with = _TARGET_COMPATIBLE_WITH, -) - -mozc_win_build_target( - name = "mozc_broker", - cpu = "x64_windows", - tags = MOZC_TAGS.WIN_ONLY, - target = "//win32/broker:mozc_broker_main", - target_compatible_with = _TARGET_COMPATIBLE_WITH, -) - -mozc_win_build_target( - name = "mozc_cache_service", - cpu = "x64_windows", - tags = MOZC_TAGS.WIN_ONLY, - target = "//win32/cache_service:mozc_cache_service", - target_compatible_with = _TARGET_COMPATIBLE_WITH, -) - -mozc_win_build_target( - name = "mozc_tip32", - cpu = "x64_x86_windows", - static_crt = True, - tags = MOZC_TAGS.WIN_ONLY, - target = "//win32/tip:mozc_tip", - target_compatible_with = _TARGET_COMPATIBLE_WITH, -) - -mozc_win_build_target( - name = "mozc_tip64", - cpu = "x64_windows", - static_crt = True, - tags = MOZC_TAGS.WIN_ONLY, - target = "//win32/tip:mozc_tip", - target_compatible_with = _TARGET_COMPATIBLE_WITH, -) - -mozc_win_build_target( - name = "custom_action", - cpu = "x64_windows", - static_crt = True, - tags = MOZC_TAGS.WIN_ONLY, - target = "//win32/custom_action", - target_compatible_with = _TARGET_COMPATIBLE_WITH, -) - mozc_py_binary( name = "build_installer", srcs = ["build_installer.py"], @@ -136,14 +68,15 @@ _MSI_FILE = "Mozc64.msi" if BRANDING == "Mozc" else "GoogleJapaneseInput64.msi" genrule( name = "installer", srcs = [ - ":mozc_tool", - ":mozc_renderer", - ":mozc_server", - ":mozc_broker", - ":mozc_cache_service", - ":mozc_tip32", - ":mozc_tip64", - ":custom_action", + "//gui/tool:mozc_tool_win", + "//renderer/win32:win32_renderer_main", + "//server:mozc_server_win", + "//win32/broker:mozc_broker_main", + "//win32/cache_service:mozc_cache_service", + "//win32/tip:mozc_tip32", + "//win32/tip:mozc_tip64", + "//win32/tip:mozc_tip64.pdb", + "//win32/custom_action", _WXS_FILE, "//base:mozc_version_txt", "//data/images/win:product_icon.ico", @@ -156,14 +89,15 @@ genrule( "$(location :build_installer)", "--output=$@", "--version_file=$(location //base:mozc_version_txt)", - "--mozc_tool=$(location :mozc_tool)", - "--mozc_renderer=$(location :mozc_renderer)", - "--mozc_server=$(location :mozc_server)", - "--mozc_broker=$(location :mozc_broker)", - "--mozc_cache_service=$(location :mozc_cache_service)", - "--mozc_tip32=$(location :mozc_tip32)", - "--mozc_tip64=$(location :mozc_tip64)", - "--custom_action=$(location :custom_action)", + "--mozc_tool=$(location //gui/tool:mozc_tool_win)", + "--mozc_renderer=$(location //renderer/win32:win32_renderer_main)", + "--mozc_server=$(location //server:mozc_server_win)", + "--mozc_broker=$(location //win32/broker:mozc_broker_main)", + "--mozc_cache_service=$(location //win32/cache_service:mozc_cache_service)", + "--mozc_tip32=$(location //win32/tip:mozc_tip32)", + "--mozc_tip64=$(location //win32/tip:mozc_tip64)", + "--mozc_tip64_pdb=$(location //win32/tip:mozc_tip64.pdb)", + "--custom_action=$(location //win32/custom_action)", "--icon_path=$(location //data/images/win:product_icon.ico)", "--credit_file=$(location //data/installer:credits_en.html)", "--qt_core_dll=$(location @qt_win//:bin/Qt6Core.dll)", diff --git a/src/win32/installer/build_installer.py b/src/win32/installer/build_installer.py index 69d51b941..afd28e483 100644 --- a/src/win32/installer/build_installer.py +++ b/src/win32/installer/build_installer.py @@ -89,6 +89,8 @@ def run_wix4(args) -> None: mozc_tip32 = pathlib.Path(args.mozc_tip32).resolve() mozc_tip64 = pathlib.Path(args.mozc_tip64).resolve() mozc_tip64_pdb = mozc_tip64.with_suffix('.pdb') + if args.mozc_tip64_pdb: + mozc_tip64_pdb = pathlib.Path(args.mozc_tip64_pdb).resolve() mozc_broker = pathlib.Path(args.mozc_broker).resolve() mozc_server = pathlib.Path(args.mozc_server).resolve() mozc_cache_service = pathlib.Path(args.mozc_cache_service).resolve() @@ -159,6 +161,7 @@ def main(): parser.add_argument('--mozc_cache_service', type=str) parser.add_argument('--mozc_tip32', type=str) parser.add_argument('--mozc_tip64', type=str) + parser.add_argument('--mozc_tip64_pdb', type=str) parser.add_argument('--custom_action', type=str) parser.add_argument('--icon_path', type=str) parser.add_argument('--credit_file', type=str) diff --git a/src/win32/installer/transition.bzl b/src/win32/installer/transition.bzl deleted file mode 100644 index c4e32e70c..000000000 --- a/src/win32/installer/transition.bzl +++ /dev/null @@ -1,161 +0,0 @@ -# Copyright 2010-2021, Google Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google Inc. nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -"""Define a transition rules for Windows build.""" - -load("//:build_defs.bzl", "MOZC_TAGS") -load("//:config.bzl", "BAZEL_TOOLS_PREFIX") - -def _win_executable_transition_impl( - settings, # @unused - attr): - features = [] - if attr.static_crt: - features = ["static_link_msvcrt"] - return { - "//command_line_option:features": features, - "//command_line_option:cpu": attr.cpu, - } - -_win_executable_transition = transition( - implementation = _win_executable_transition_impl, - inputs = [], - outputs = [ - "//command_line_option:features", - "//command_line_option:cpu", - ], -) - -def _mozc_win_build_rule_impl(ctx): - input_file = ctx.file.target - output = ctx.actions.declare_file( - ctx.label.name + "." + input_file.extension, - ) - if input_file.path == output.path: - fail("input=%d and output=%d are the same." % (input_file.path, output.path)) - - # Create a symlink as we do not need to create an actual copy. - ctx.actions.symlink( - output = output, - target_file = input_file, - is_executable = True, - ) - return [DefaultInfo( - files = depset([output]), - executable = output, - )] - -# The follwoing CPU values are mentioned in https://bazel.build/configure/windows#build_cpp -CPU = struct( - ARM64 = "arm64_windows", # aarch64 (64-bit) environment - X64 = "x64_windows", # x86-64 (64-bit) environment - X86 = "x64_x86_windows", # x86 (32-bit) environment -) - -_mozc_win_build_rule = rule( - implementation = _mozc_win_build_rule_impl, - cfg = _win_executable_transition, - attrs = { - "_allowlist_function_transition": attr.label( - default = BAZEL_TOOLS_PREFIX + "//tools/allowlists/function_transition_allowlist", - ), - "target": attr.label( - allow_single_file = [".dll", ".exe"], - doc = "the actual Bazel target to be built.", - mandatory = True, - ), - "static_crt": attr.bool(), - "cpu": attr.string(), - }, -) - -# Define a transition target with the given build target with the given build configurations. -# -# For instance, the following code creates a target "my_target" with setting "cpu" as "x64_windows" -# and setting "static_link_msvcrt" feature. -# -# mozc_win_build_rule( -# name = "my_target", -# cpu = CPU.X64, -# static_crt = True, -# target = "//bath/to/target:my_target", -# ) -# -# See the following page for the details on transition. -# https://bazel.build/rules/lib/builtins/transition -def mozc_win_build_target( - name, - target, - cpu = CPU.X64, - static_crt = False, - target_compatible_with = [], - tags = [], - **kwargs): - """Define a transition target with the given build target with the given build configurations. - - The following code creates a target "my_target" with setting "cpu" as "x64_windows" and setting - "static_link_msvcrt" feature. - - mozc_win_build_target( - name = "my_target", - cpu = CPU.X64, - static_crt = True, - target = "//bath/to/target:my_target", - ) - - Args: - name: name of the target. - target: the actual Bazel target to be built with the specified configurations. - cpu: CPU type of the target. - static_crt: True if the target should be built with static CRT. - target_compatible_with: optional. Visibility for the unit test target. - tags: optional. Tags for both the library and unit test targets. - **kwargs: other arguments passed to mozc_objc_library. - """ - mandatory_target_compatible_with = [ - "@platforms//os:windows", - ] - for item in mandatory_target_compatible_with: - if item not in target_compatible_with: - target_compatible_with.append(item) - - mandatory_tags = MOZC_TAGS.WIN_ONLY - for item in mandatory_tags: - if item not in tags: - tags.append(item) - - _mozc_win_build_rule( - name = name, - target = target, - cpu = cpu, - static_crt = static_crt, - target_compatible_with = target_compatible_with, - tags = tags, - **kwargs - ) diff --git a/src/win32/tip/BUILD.bazel b/src/win32/tip/BUILD.bazel index 8408fa910..701678e81 100644 --- a/src/win32/tip/BUILD.bazel +++ b/src/win32/tip/BUILD.bazel @@ -32,9 +32,9 @@ load( "//:build_defs.bzl", "MOZC_TAGS", - "mozc_cc_binary", "mozc_cc_library", "mozc_cc_test", + "mozc_win32_cc_prod_binary", "mozc_win32_resource_from_template", ) load( @@ -42,19 +42,10 @@ load( "features_gdi", ) -mozc_cc_binary( - name = "mozc_tip", - srcs = ["mozc_tip_main.cc"], - features = ["generate_pdb_file"], - linkopts = [ - "/DEBUG:FULL", - "/PDBALTPATH:%_PDB%", - ], - linkshared = True, +mozc_cc_library( + name = "mozc_tip_deps", tags = MOZC_TAGS.WIN_ONLY, target_compatible_with = ["@platforms//os:windows"], - visibility = ["//win32/installer:__subpackages__"], # Scheuklappen: keep - win_def_file = "mozc_tip.def", deps = [ ":mozc_tip_resource", ":tip_class_factory", @@ -74,6 +65,42 @@ mozc_cc_binary( ], ) +mozc_win32_cc_prod_binary( + name = "mozc_tip32", + srcs = ["mozc_tip_main.cc"], + cpu = "x64_x86_windows", + executable_name_map = { + "Mozc": "mozc_tip32.dll", + "GoogleJapaneseInput": "GoogleIMEJaTIP32.dll", + }, + static_crt = True, + tags = MOZC_TAGS.WIN_ONLY, + target_compatible_with = ["@platforms//os:windows"], + visibility = ["//win32/installer:__subpackages__"], # Scheuklappen: keep + win_def_file = "mozc_tip.def", + deps = [ + ":mozc_tip_deps", + ], +) + +mozc_win32_cc_prod_binary( + name = "mozc_tip64", + srcs = ["mozc_tip_main.cc"], + cpu = "x64_windows", + executable_name_map = { + "Mozc": "mozc_tip64.dll", + "GoogleJapaneseInput": "GoogleIMEJaTIP64.dll", + }, + static_crt = True, + tags = MOZC_TAGS.WIN_ONLY, + target_compatible_with = ["@platforms//os:windows"], + visibility = ["//win32/installer:__subpackages__"], # Scheuklappen: keep + win_def_file = "mozc_tip.def", + deps = [ + ":mozc_tip_deps", + ], +) + mozc_win32_resource_from_template( name = "mozc_tip_resource", src = "tip_resource.rc",