Trying to compile the go-webp
package using Bazel. This involves compiling libwebp
from sources.
Here’s how I’m retrieving libwebp
‘s sources:
# WORKSPACE
git_repository(
name = "libwebp",
remote = "https://chromium.googlesource.com/webm/libwebp",
commit = "9ce982fdf21764ef7b273f91d6d72721656c3e03",
build_file = "//:bazel/libwebp/BUILD.bazel",
)
# //:bazel/libwebp/BUILD.bazel
filegroup(
name = "srcs",
srcs = glob(
["**/*"],
# https://github.com/bazelbuild/rules_foreign_cc/issues/1034#issuecomment-2009876928
exclude = ["bazel*/**"],
),
visibility = ["//visibility:public"],
)
Then, here’s how I’m (apparently successfully) compiling it:
# //:external/libwebp/BUILD.bazel
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")
configure_make(
name = "libwebp",
autogen = True,
configure_in_place = True,
configure_options = [],
env = select({
"@platforms//os:macos": {
"AR": "/usr/bin/ar",
},
"//conditions:default": {},
}),
lib_source = "@libwebp//:srcs",
visibility = ["//visibility:public"],
)
Finally, the go-webp
Go repository:
go_repository(
name = "com_github_kolesa_team_go_webp",
importpath = "github.com/kolesa-team/go-webp",
patches = ["//:bazel/com_github_kolesa_team_go_webp/build.patch"], # keep
sum = "h1:wQvU4PLG/X7RS0vAeyhiivhLRoxfLVRlDq4I3frdxIQ=",
version = "v1.0.4",
)
Where the patch contains:
--- encoder/BUILD.bazel
+++ encoder/BUILD.bazel
@@ -7,7 +7,7 @@
"options.go",
],
cgo = True,
- clinkopts = ["-lwebp"],
+ cdeps = ["@asset-tracker//external/libwebp"],
importpath = "github.com/kolesa-team/go-webp/encoder",
visibility = ["//visibility:public"],
)
Trying to build a service that depends on go-webp
results in linker not finding some symbols from the webp
library:
ld: warning: ignoring duplicate libraries: '-lc++', '-lm'
Undefined symbols for architecture arm64:
"_SharpYuvConvert", referenced from:
_PreprocessARGB in libwebp.a[87](libwebpencode_la-picture_csp_enc.o)
"_SharpYuvGetConversionMatrix", referenced from:
_PreprocessARGB in libwebp.a[87](libwebpencode_la-picture_csp_enc.o)
"_SharpYuvInit", referenced from:
_ImportYUVAFromRGBA in libwebp.a[87](libwebpencode_la-picture_csp_enc.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
link: error running subcommand external/go_sdk/pkg/tool/darwin_arm64/link: exit status 2
Some info about my system:
Darwin 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:14:38 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6020 arm64
bazel 7.2.1
Had a really hard time figuring out the configure_make
build on macOS for the webp
library and now I am not sure where I have gone wrong about it.
Now, the question(s): How would I go about debugging this? Is there any known issue that I might have missed in my research?
Disclaimer: I initially thought this would belong on someone’s GitHub Issues page, but honestly I’m not sure on which repository this would even belong.