-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fcitx bazel build #68
base: fcitx
Are you sure you want to change the base?
Conversation
* add build_fcitx_bazel * This is a fix to enable fcitx-mozc to be built with bazel.
c7627b4
to
2b0ed29
Compare
* add build_fcitx_bazel * This is a fix to enable fcitx-mozc to be built with bazel.
2b0ed29
to
ed6d04e
Compare
you definitely break the build by remove @fcitx |
I certainly thought so too, but in my environment, when In the github workflow, fcitx-mozc is built with bazel on arch, manjaro, ubuntu, and debian. If I remove I suspect that the fcitx-related files shown by pkg-config are not recognized as |
No, the pkg-config should just work. I even used a non standard prefix to test. |
Of course, pkg-config is working. Bazel should have the library information for fcitx-mozc to link against. So I suspect it's being handled differently.
|
when remove
|
<fcitx/ime.h> referenced by unix/fcitx/fcitx_key_translator.h cannot be found, but is resolved by -I/usr/include. |
.cache/bazel/_bazel_phoepsilonix/a422ec5eb6e7740277eb4ee8963a4986/external/_main~_repo_rules~fcitx/BUILD.bazel
|
It seems that the absolute path here is the problem. Can this be avoided by setting pkg-config or the BUILD file?
|
This may not be possible without modifying bazel/pkg_config_repository.bzl. def _pkg_config_repository_impl(repo_ctx):
includes = _exec_pkg_config(repo_ctx, "--cflags-only-I")
includes = [item[len("-I/"):] for item in includes]
_symlinks(repo_ctx, includes)
data = {
# In bzlmod, repo_ctx.attr.name has a prefix like "_main~_repo_rules~ibus".
# Note also that Bazel 8.0+ uses "+" instead of "~".
# https://github.com/bazelbuild/bazel/issues/23127
"name": repo_ctx.attr.name.replace("~", "+").split("+")[-1],
"hdrs": _make_strlist([item + "/**" for item in includes]),
"copts": _make_strlist(_exec_pkg_config(repo_ctx, "--cflags-only-other")),
"includes": _make_strlist(includes),
"linkopts": _make_strlist(_exec_pkg_config(repo_ctx, "--libs-only-l")),
}
build_file_data = BUILD_TEMPLATE.format(**data) |
Here are some workarounds I can think of. Workaround 1 cat /usr/lib/pkgconfig/fcitx.pc
Workaround 2 diff --git a/src/MODULE.bazel b/src/MODULE.bazel
index df10ba2..7ce536f 100644
--- a/src/MODULE.bazel
+++ b/src/MODULE.bazel
@@ -128,7 +128,11 @@ pkg_config_repository(
)
# Fcitx
-pkg_config_repository(
+pkg_config_repository_fcitx = use_repo_rule(
+ "@//bazel:pkg_config_repository_fcitx.bzl",
+ "pkg_config_repository",
+)
+pkg_config_repository_fcitx(
name = "fcitx",
packages = ["fcitx"],
)
diff --git a/src/bazel/pkg_config_repository_fcitx.bzl b/src/bazel/pkg_config_repository_fcitx.bzl
new file mode 100644
index 0000000..693e8ae
--- /dev/null
+++ b/src/bazel/pkg_config_repository_fcitx.bzl
@@ -0,0 +1,142 @@
+# 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.
+
+"""Repository rule for Linux libraries configured by `pkg-config`.
+
+Note, this rule supports only necessary functionaries of pkg-config for Mozc.
+Generated `BUILD.bazel` is available at `bazel-src/external/<repository_name>`.
+
+## Example of usage
+```:WORKSPACE.bazel
+pkg_config_repository(
+ name = "ibus",
+ packages = ["glib-2.0", "gobject-2.0", "ibus-1.0"],
+)
+```
+
+```:BUILD.bazel
+cc_library(
+ name = "ibus_client",
+ deps = [
+ "@ibus//:ibus",
+ ...
+ ],
+ ...
+)
+```
+"""
+
+BUILD_TEMPLATE = """
+package(
+ default_visibility = ["//visibility:public"],
+)
+
+cc_library(
+ name = "{name}",
+ hdrs = glob([
+ {hdrs}
+ ]),
+ copts = [
+ {copts}
+ ],
+ includes = [
+ {includes}
+ ],
+ linkopts = [
+ {linkopts}
+ ],
+)
+"""
+
+EXPORTS_FILES_TEMPLATE = """
+exports_files(glob(["libexec/*"]))
+"""
+
+def _exec_pkg_config(repo_ctx, flag):
+ binary = repo_ctx.which("pkg-config")
+ if not binary:
+ # Using print is not recommended, but this will be a clue to debug build errors in
+ # the case of pkg-config is not found.
+ print("pkg-config is not found") # buildifier: disable=print
+ return []
+ result = repo_ctx.execute([binary, flag] + repo_ctx.attr.packages)
+ items = result.stdout.strip().split(" ")
+ uniq_items = sorted({key: None for key in items}.keys())
+ return uniq_items
+
+def _make_strlist(list):
+ return "\"" + "\",\n \"".join(list) + "\""
+
+def _symlinks(repo_ctx, paths):
+ for path in paths:
+ if repo_ctx.path(path).exists:
+ continue
+ repo_ctx.symlink("/" + path, path)
+
+def ensure_fcitx_include(packages, includes):
+ if packages == ["fcitx"]:
+ if not includes:
+ return ['-I/usr/include/fcitx', '-I/usr/include']
+ elif not includes[0]:
+ return ['-I/usr/include/fcitx', '-I/usr/include'] + includes[1:]
+ return includes
+
+def _pkg_config_repository_impl(repo_ctx):
+ includes = _exec_pkg_config(repo_ctx, "--cflags-only-I")
+ if repo_ctx.attr.packages == ["fcitx"]:
+ includes = ensure_fcitx_include(repo_ctx.attr.packages, includes)
+ includes = [item[len("-I/"):] for item in includes]
+ _symlinks(repo_ctx, includes)
+ data = {
+ # In bzlmod, repo_ctx.attr.name has a prefix like "_main~_repo_rules~ibus".
+ # Note also that Bazel 8.0+ uses "+" instead of "~".
+ # https://github.com/bazelbuild/bazel/issues/23127
+ "name": repo_ctx.attr.name.replace("~", "+").split("+")[-1],
+ "hdrs": _make_strlist([item + "/**" for item in includes]),
+ "copts": _make_strlist(_exec_pkg_config(repo_ctx, "--cflags-only-other")),
+ "includes": _make_strlist(includes),
+ "linkopts": _make_strlist(_exec_pkg_config(repo_ctx, "--libs-only-l")),
+ }
+ build_file_data = BUILD_TEMPLATE.format(**data)
+
+ libexecdir = _exec_pkg_config(repo_ctx, "--variable=libexecdir")
+ if len(libexecdir) == 1:
+ repo_ctx.symlink(libexecdir[0], "libexec")
+ build_file_data += EXPORTS_FILES_TEMPLATE
+
+ repo_ctx.file("BUILD.bazel", build_file_data)
+
+pkg_config_repository = repository_rule(
+ implementation = _pkg_config_repository_impl,
+ configure = True,
+ local = True,
+ attrs = {
+ "packages": attr.string_list(),
+ },
+) Workaround 3 diff --git a/src/bazel/pkg_config_repository.bzl b/src/bazel/pkg_config_repository.bzl
index 8d46e01..693e8ae 100644
--- a/src/bazel/pkg_config_repository.bzl
+++ b/src/bazel/pkg_config_repository.bzl
@@ -99,8 +99,18 @@ def _symlinks(repo_ctx, paths):
continue
repo_ctx.symlink("/" + path, path)
+def ensure_fcitx_include(packages, includes):
+ if packages == ["fcitx"]:
+ if not includes:
+ return ['-I/usr/include/fcitx', '-I/usr/include']
+ elif not includes[0]:
+ return ['-I/usr/include/fcitx', '-I/usr/include'] + includes[1:]
+ return includes
+
def _pkg_config_repository_impl(repo_ctx):
includes = _exec_pkg_config(repo_ctx, "--cflags-only-I")
+ if repo_ctx.attr.packages == ["fcitx"]:
+ includes = ensure_fcitx_include(repo_ctx.attr.packages, includes)
includes = [item[len("-I/"):] for item in includes]
_symlinks(repo_ctx, includes)
data = { |
It seems we can make Bazel recognize |
* add build_fcitx_bazel * This is a fix to enable fcitx-mozc to be built with bazel.
ed6d04e
to
213a6ee
Compare
* add build_fcitx_bazel * This is a fix to enable fcitx-mozc to be built with bazel.
213a6ee
to
1888619
Compare
If google#1095 is approved for merging, this (#68) will no longer be necessary. |
Ok, it seems that its some issue with /usr/include So we can try something else for fcitx anyway. fcitx5 is not affected since it has an additonal layer of directory |
we can go back to the old way (non pkg-config) to define fcitx repo, if that's the easiest solution |
Description
This is a fix to enable fcitx-mozc to be built with bazel.