Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fcitx
Browse files Browse the repository at this point in the history
  • Loading branch information
Fcitx Bot committed Jun 26, 2024
2 parents 0d3346f + ff64988 commit bb75314
Show file tree
Hide file tree
Showing 30 changed files with 272 additions and 371 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,57 @@ jobs:
path: src/out_win/Release/Mozc64.msi
if-no-files-found: warn

build_bazel:
# https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md
runs-on: windows-2022
timeout-minutes: 120

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Set up pip
shell: cmd
working-directory: .\src
run: |
python -m pip install six requests
- name: Try to restore update_deps cache
uses: actions/cache@v4
with:
path: src/third_party_cache
key: update_deps-${{ runner.os }}-${{ hashFiles('src/build_tools/update_deps.py') }}

- name: Install Dependencies
shell: cmd
working-directory: .\src
# This command uses src/third_party_cache as the download cache.
run: |
python build_tools/update_deps.py
- name: Biuld Qt
shell: cmd
working-directory: .\src
run: |
python build_tools/build_qt.py --release --confirm_license
# This is needed only for GitHub Actions where free disk space is quite limited.
- name: Delete Qt src to save disk space
shell: cmd
working-directory: .\src
run: |
rmdir third_party\qt_src /s /q
- name: build artifacts
shell: cmd
working-directory: .\src
env:
ANDROID_NDK_HOME: ""
run: |
bazel --bazelrc=windows.bazelrc build //server:mozc_server --config oss_windows --verbose_failures --cpu=x64_windows
test:
# https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md
runs-on: windows-2022
Expand Down
12 changes: 12 additions & 0 deletions src/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ common:prod_android --config=compiler_gcc_like
common:macos --config=compiler_gcc_like
common:oss_macos --config=compiler_gcc_like
common:prod_macos --config=compiler_gcc_like
common:windows --config=compiler_msvc_like
common:oss_windows --config=compiler_msvc_like
common:prod_windows --config=compiler_msvc_like

# Make sure we set -std=c++20 that may affect ABI across all the compilation targets.
# https://github.com/abseil/abseil-cpp/blob/master/FAQ.md#what-is-abi-and-why-dont-you-recommend-using-a-pre-compiled-version-of-abseil
Expand All @@ -18,6 +21,7 @@ build:compiler_gcc_like --copt "-funsigned-char" --host_copt "-funsigned-char"
build:compiler_gcc_like --copt "-Wno-sign-compare" --host_copt "-Wno-sign-compare"
build:compiler_gcc_like --copt "-Wno-char-subscripts" --host_copt "-Wno-char-subscripts"
build:compiler_msvc_like --cxxopt "/std:c++20" --host_cxxopt "/std:c++20"
build:compiler_msvc_like --cxxopt "/Zc:__cplusplus" --host_cxxopt "/Zc:__cplusplus"
build:compiler_msvc_like --copt "/J" --host_copt "/J"
build:compiler_msvc_like --copt "/utf-8" --host_copt "/utf-8"
build:compiler_msvc_like --cxxopt "/J" --host_cxxopt "/J"
Expand Down Expand Up @@ -46,6 +50,14 @@ build:windows --define TARGET=oss_windows --build_tag_filters=-nowin
build:oss_windows --define TARGET=oss_windows --build_tag_filters=-nowin
build:prod_windows --define TARGET=prod_windows --build_tag_filters=-nowin

# A temporary workaround to make "mozc_win_build_rule" work.
# Note that "incompatible_enable_cc_toolchain_resolution" is now enabled by
# default. See https://github.com/bazelbuild/bazel/issues/7260
# TODO: Re-enable "incompatible_enable_cc_toolchain_resolution"
build:windows --noincompatible_enable_cc_toolchain_resolution
build:oss_macos --noincompatible_enable_cc_toolchain_resolution
build:prod_macos --noincompatible_enable_cc_toolchain_resolution

# Android / OSS Android (same configurations)
build:android --define TARGET=oss_android --copt "-DOS_ANDROID"
build:android --android_crosstool_top=@androidndk//:toolchain
Expand Down
89 changes: 88 additions & 1 deletion src/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ See also: https://bazel.build/rules/bzl-style#rules
"""

load("@build_bazel_rules_apple//apple:macos.bzl", "macos_application", "macos_bundle", "macos_unit_test")
load("//:config.bzl", "BRANDING", "MACOS_BUNDLE_ID_PREFIX", "MACOS_MIN_OS_VER")
load(
"//:config.bzl",
"BAZEL_TOOLS_PREFIX",
"BRANDING",
"MACOS_BUNDLE_ID_PREFIX",
"MACOS_MIN_OS_VER",
)
load("//bazel:run_build_tool.bzl", "mozc_run_build_tool")
load("//bazel:stubs.bzl", "pytype_strict_binary", "pytype_strict_library", "register_extension_info")

Expand Down Expand Up @@ -434,6 +440,87 @@ def mozc_macos_bundle(name, bundle_name, infoplists, strings = [], bundle_id = N
**kwargs
)

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
)

# A custom rule to reference the given build target with the given build configurations.
#
# For instance, the following rule 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
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(
default = False,
),
"cpu": attr.string(
default = "x64_windows",
),
},
)

def _get_value(args):
for arg in args:
if arg != None:
Expand Down
28 changes: 1 addition & 27 deletions src/converter/candidate_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,6 @@ bool IsSameNodeStructure(const absl::Span<const Node *const> lnodes,
return true;
}

bool IsStrictModeEnabled(const ConversionRequest &request) {
return request.request().mixed_conversion() &&
!request.request()
.decoder_experiment_params()
.enable_realtime_conversion_v2();
}

// Returns true if there is a number node that does not follow the
bool IsNoisyNumberCandidate(const dictionary::PosMatcher &pos_matcher,
const absl::Span<const Node *const> nodes) {
Expand Down Expand Up @@ -342,8 +335,6 @@ CandidateFilter::ResultType CandidateFilter::FilterCandidateInternal(
return result;
}

const bool is_strict_mode = IsStrictModeEnabled(request);

// In general, the cost of constrained node tends to be overestimated.
// If the top candidate has constrained node, we skip the main body
// of CandidateFilter, meaning that the node is not treated as the top
Expand Down Expand Up @@ -516,12 +507,7 @@ CandidateFilter::ResultType CandidateFilter::FilterCandidateInternal(
top_non_content_value == non_content_value) {
MOZC_VLOG(1) << "don't filter if non-content value are the same: "
<< candidate->value;
if (!is_strict_mode || top_nodes.size() == nodes.size()) {
// In strict mode, also checks the nodes size.
// i.e. do not allow the candidate, "め+移転+も" for the top candidate,
// "名店も"
return CandidateFilter::GOOD_CANDIDATE;
}
return CandidateFilter::GOOD_CANDIDATE;
}

// Check Katakana transliterations
Expand Down Expand Up @@ -651,18 +637,6 @@ CandidateFilter::ResultType CandidateFilter::FilterCandidateInternal(
return CandidateFilter::BAD_CANDIDATE;
}
}

if (is_strict_mode) {
// Filter candidates:
// 1) which have the different Pos structure with the top candidate, and
// 2) which have atypical Pos structure
if (!IsSameNodeStructure(top_nodes, nodes) &&
!IsTypicalNodeStructure(*pos_matcher_, nodes)) {
MOZC_CANDIDATE_LOG(candidate, "is_strict_mode");
return CandidateFilter::BAD_CANDIDATE;
}
}

return CandidateFilter::GOOD_CANDIDATE;
}

Expand Down
Loading

0 comments on commit bb75314

Please sign in to comment.