From d54e5740ed94a78f8723de3289fac333a668e54d Mon Sep 17 00:00:00 2001 From: maleo Date: Wed, 16 Oct 2024 17:58:49 +0000 Subject: [PATCH 1/3] Configure AR and STRIP tools for meson --- foreign_cc/meson.bzl | 4 ++++ foreign_cc/private/cc_toolchain_util.bzl | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/foreign_cc/meson.bzl b/foreign_cc/meson.bzl index 9d4179ab2..08fd668cb 100644 --- a/foreign_cc/meson.bzl +++ b/foreign_cc/meson.bzl @@ -79,6 +79,10 @@ def _create_meson_script(configureParameters): script.append("##export_var## CC {}".format(_absolutize(ctx.workspace_name, tools.cc))) if " " not in tools.cxx: script.append("##export_var## CXX {}".format(_absolutize(ctx.workspace_name, tools.cxx))) + if " " not in tools.cxx_linker_static: + script.append("##export_var## AR {}".format(_absolutize(ctx.workspace_name, tools.cxx_linker_static))) + if " " not in tools.cxx: + script.append("##export_var## STRIP {}".format(_absolutize(ctx.workspace_name, tools.strip))) # set flags same as foreign_cc/private/cc_toolchain_util.bzl # cannot use get_flags_info() because bazel adds additional flags that diff --git a/foreign_cc/private/cc_toolchain_util.bzl b/foreign_cc/private/cc_toolchain_util.bzl index 3b15578e0..fb2f6dc76 100644 --- a/foreign_cc/private/cc_toolchain_util.bzl +++ b/foreign_cc/private/cc_toolchain_util.bzl @@ -22,6 +22,7 @@ CxxToolsInfo = provider( cxx_linker_static = "C++ linker to link static library", cxx_linker_executable = "C++ linker to link executable", ld = "linker", + strip = "Binary symbol stripper" ), ) @@ -218,6 +219,10 @@ def get_tools_info(ctx): action_name = ACTION_NAMES.cpp_link_executable, ), ld = cc_toolchain.ld_executable, + strip = cc_common.get_tool_for_action( + feature_configuration = feature_configuration, + action_name = ACTION_NAMES.strip, + ), ) def get_flags_info(ctx, link_output_file = None): From 49261e55c726c981514554265b251dab848ee4ad Mon Sep 17 00:00:00 2001 From: maleo Date: Wed, 16 Oct 2024 18:00:09 +0000 Subject: [PATCH 2/3] Improve flags handling for meson This aligns this to what other tools are doing. This is required to fix --sysroot flag even without cross compiling for example when using in combination with a hermetic toolchain. --- foreign_cc/meson.bzl | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/foreign_cc/meson.bzl b/foreign_cc/meson.bzl index 08fd668cb..0552ae6a6 100644 --- a/foreign_cc/meson.bzl +++ b/foreign_cc/meson.bzl @@ -2,9 +2,12 @@ load("//foreign_cc:utils.bzl", "full_label") load("//foreign_cc/built_tools:meson_build.bzl", "meson_tool") +load( + "//foreign_cc/built_tools/private:built_tools_framework.bzl", + "absolutize", +) load( "//foreign_cc/private:cc_toolchain_util.bzl", - "absolutize_path_in_str", "get_flags_info", "get_tools_info", ) @@ -68,6 +71,7 @@ def _create_meson_script(configureParameters): inputs = configureParameters.inputs tools = get_tools_info(ctx) + flags = get_flags_info(ctx) script = pkgconfig_script(inputs.ext_build_dirs) # CFLAGS and CXXFLAGS are also set in foreign_cc/private/cmake_script.bzl, so that meson @@ -84,20 +88,15 @@ def _create_meson_script(configureParameters): if " " not in tools.cxx: script.append("##export_var## STRIP {}".format(_absolutize(ctx.workspace_name, tools.strip))) - # set flags same as foreign_cc/private/cc_toolchain_util.bzl - # cannot use get_flags_info() because bazel adds additional flags that - # aren't compatible with compiler or linker above - copts = (ctx.fragments.cpp.copts + ctx.fragments.cpp.conlyopts + getattr(ctx.attr, "copts", [])) or [] - cxxopts = (ctx.fragments.cpp.copts + ctx.fragments.cpp.cxxopts + getattr(ctx.attr, "copts", [])) or [] - + copts = flags.cc + cxxopts = flags.cxx if copts: - script.append("##export_var## CFLAGS \"{} ${{CFLAGS:-}}\"".format(" ".join(copts).replace("\"", "'"))) + script.append("##export_var## CFLAGS \"{} ${{CFLAGS:-}}\"".format(_join_flags_list(ctx.workspace_name, copts).replace("\"", "'"))) if cxxopts: - script.append("##export_var## CXXFLAGS \"{} ${{CXXFLAGS:-}}\"".format(" ".join(cxxopts).replace("\"", "'"))) + script.append("##export_var## CXXFLAGS \"{} ${{CXXFLAGS:-}}\"".format(_join_flags_list(ctx.workspace_name, cxxopts).replace("\"", "'"))) - flags = get_flags_info(ctx) if flags.cxx_linker_executable: - script.append("##export_var## LDFLAGS \"{} ${{LDFLAGS:-}}\"".format(" ".join(flags.cxx_linker_executable).replace("\"", "'"))) + script.append("##export_var## LDFLAGS \"{} ${{LDFLAGS:-}}\"".format(_join_flags_list(ctx.workspace_name, flags.cxx_linker_executable).replace("\"", "'"))) script.append("##export_var## CMAKE {}".format(attrs.cmake_path)) script.append("##export_var## NINJA {}".format(attrs.ninja_path)) @@ -249,4 +248,7 @@ def _absolutize(workspace_name, text, force = False): if text.strip(" ").startswith("C:") or text.strip(" ").startswith("c:"): return "\"{}\"".format(text) - return absolutize_path_in_str(workspace_name, "$EXT_BUILD_ROOT/", text, force) + return absolutize(workspace_name, text, force) + +def _join_flags_list(workspace_name, flags): + return " ".join([_absolutize(workspace_name, flag) for flag in flags]) From 52caf529a6243d4b152f68d7f85af1afb68bfdba Mon Sep 17 00:00:00 2001 From: maleo Date: Tue, 1 Oct 2024 16:08:25 +0000 Subject: [PATCH 3/3] Add ffmpeg example --- examples/third_party/.bazelrc | 13 ++ examples/third_party/BUILD.sysroot.bazel | 46 +++++++ examples/third_party/MODULE.bazel | 45 +++++++ examples/third_party/ffmpeg/BUILD.bazel | 16 +++ .../third_party/ffmpeg/BUILD.ffmpeg.bazel | 122 ++++++++++++++++++ .../third_party/ffmpeg/BUILD.libaom.bazel | 44 +++++++ .../third_party/ffmpeg/BUILD.libdav1d.bazel | 49 +++++++ .../third_party/ffmpeg/BUILD.libsvtav1.bazel | 46 +++++++ .../third_party/ffmpeg/BUILD.libvpx.bazel | 47 +++++++ .../third_party/ffmpeg/BUILD.libyuv.bazel | 36 ++++++ examples/third_party/ffmpeg/BUILD.yasm.bazel | 50 +++++++ .../ffmpeg/ffmpeg_repositories.bzl | 71 ++++++++++ .../openssl/openssl_repositories.bzl | 22 ++-- examples/third_party/repositories.bzl | 21 ++- 14 files changed, 616 insertions(+), 12 deletions(-) create mode 100644 examples/third_party/.bazelrc create mode 100644 examples/third_party/BUILD.sysroot.bazel create mode 100644 examples/third_party/MODULE.bazel create mode 100644 examples/third_party/ffmpeg/BUILD.bazel create mode 100644 examples/third_party/ffmpeg/BUILD.ffmpeg.bazel create mode 100644 examples/third_party/ffmpeg/BUILD.libaom.bazel create mode 100644 examples/third_party/ffmpeg/BUILD.libdav1d.bazel create mode 100644 examples/third_party/ffmpeg/BUILD.libsvtav1.bazel create mode 100644 examples/third_party/ffmpeg/BUILD.libvpx.bazel create mode 100644 examples/third_party/ffmpeg/BUILD.libyuv.bazel create mode 100644 examples/third_party/ffmpeg/BUILD.yasm.bazel create mode 100644 examples/third_party/ffmpeg/ffmpeg_repositories.bzl diff --git a/examples/third_party/.bazelrc b/examples/third_party/.bazelrc new file mode 100644 index 000000000..2e6ab1b8b --- /dev/null +++ b/examples/third_party/.bazelrc @@ -0,0 +1,13 @@ +# Enable Bzlmod for every Bazel command +common --enable_bzlmod + +# Always use the pre-configured toolchain. +build --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 +build --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 + +# Use a static value for `PATH` and does not inherit `LD_LIBRARY_PATH`. Doesn't let environment +# variables like `PATH` sneak into the build, which can cause massive cache misses when they change. +# Use `--action_env=ENV_VARIABLE` if you want to inherit specific environment variables from the +# client, but note that doing so can prevent cross-user caching if a shared cache is used. +# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_strict_action_env +build --incompatible_strict_action_env diff --git a/examples/third_party/BUILD.sysroot.bazel b/examples/third_party/BUILD.sysroot.bazel new file mode 100644 index 000000000..78e3ad4dc --- /dev/null +++ b/examples/third_party/BUILD.sysroot.bazel @@ -0,0 +1,46 @@ +filegroup( + name = "all_files", + srcs = glob([ + "lib/x86_64-linux-gnu/ld*", + "lib/x86_64-linux-gnu/libc*", + "lib/x86_64-linux-gnu/libdl*", + "lib/x86_64-linux-gnu/libgcc*", + "lib/x86_64-linux-gnu/libm*", + "lib/x86_64-linux-gnu/libpthread*", + "lib/x86_64-linux-gnu/librt*", + "lib/x86_64-linux-gnu/libutil*", + "lib64/**", + "usr/include/*.h", + "usr/include/arpa/**", + "usr/include/asm-generic/**", + "usr/include/linux/**", + "usr/include/net/**", + "usr/include/netinet/**", + "usr/include/rpc/**", + "usr/include/sys/**", + "usr/include/x86_64-linux-gnu/**", + "usr/lib/gcc/**", + "usr/lib/x86_64-linux-gnu/*crt*.o", + "usr/lib/x86_64-linux-gnu/libc_nonshared.a", + "usr/lib/x86_64-linux-gnu/libc.a", + "usr/lib/x86_64-linux-gnu/libc.so", + "usr/lib/x86_64-linux-gnu/libdl*", + "usr/lib/x86_64-linux-gnu/libm*", + "usr/lib/x86_64-linux-gnu/libpthread*", + "usr/lib/x86_64-linux-gnu/libresolv.so", + "usr/lib/x86_64-linux-gnu/librt*", + "usr/lib/x86_64-linux-gnu/libutil*", + ], + exclude = [ + # The sysroot contains libstdc++, but we use libc++ from our toolchain + # repo. Exclude these files so we don't pull them into the sandbox + # unnecessarily. When upgrading, make sure the newest libstdc++ is + # excluded. + "usr/include/c++/**", + "usr/include/x86_64-linux-gnu/c++/**", + "usr/lib/gcc/x86_64-linux-gnu/6/libstdc++*", + "usr/lib/gcc/x86_64-linux-gnu/10/libstdc++*", + ], + ), + visibility = ["//visibility:public"], +) diff --git a/examples/third_party/MODULE.bazel b/examples/third_party/MODULE.bazel new file mode 100644 index 000000000..1cc3a3ee9 --- /dev/null +++ b/examples/third_party/MODULE.bazel @@ -0,0 +1,45 @@ +bazel_dep(name = "rules_foreign_cc") +local_path_override( + module_name = "rules_foreign_cc", + path = "../..", +) + +bazel_dep(name = "nasm", version = "2.14.02") +bazel_dep(name = "platforms", version = "0.0.9") +bazel_dep(name = "rules_cc", version = "0.0.9") +bazel_dep(name = "rules_python", version = "0.23.1") +bazel_dep(name = "rules_license", version = "0.0.8") + +non_module_deps = use_extension("//:repositories.bzl", "repositories_ext") +use_repo( + non_module_deps, + "com_googleapis_storage_chrome_linux_amd64_sysroot", + "ffmpeg", + "libaom", + "libdav1d", + "libsvtav1", + "libvpx", + "libyuv", + "yasm", +) + +# C++ toolchain +bazel_dep(name = "toolchains_llvm", version = "1.2.0") +llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm", dev_dependency = True) +llvm.toolchain(llvm_version = "19.1.0") +llvm.sysroot( + label = "@com_googleapis_storage_chrome_linux_amd64_sysroot//:all_files", + targets = ["linux-x86_64"], +) +use_repo(llvm, "llvm_toolchain") +register_toolchains("@llvm_toolchain//:all", dev_dependency = True) + + +# Python toolchain +python = use_extension("@rules_python//python/extensions:python.bzl", "python") +python.toolchain( + configure_coverage_tool = True, + # Only set when you have mulitple toolchain versions. + is_default = True, + python_version = "3.10", +) diff --git a/examples/third_party/ffmpeg/BUILD.bazel b/examples/third_party/ffmpeg/BUILD.bazel new file mode 100644 index 000000000..5b7d0edab --- /dev/null +++ b/examples/third_party/ffmpeg/BUILD.bazel @@ -0,0 +1,16 @@ +load("@bazel_skylib//rules:build_test.bzl", "build_test") + +exports_files( + [ + "BUILD.ffmpeg.bazel", + ], + visibility = ["//visibility:public"], +) + +build_test( + name = "ffmpeg_build_test", + targets = [ + "@ffmpeg//:ffmpeg", + ], + visibility = ["//:__pkg__"], +) diff --git a/examples/third_party/ffmpeg/BUILD.ffmpeg.bazel b/examples/third_party/ffmpeg/BUILD.ffmpeg.bazel new file mode 100644 index 000000000..90bf1cf5a --- /dev/null +++ b/examples/third_party/ffmpeg/BUILD.ffmpeg.bazel @@ -0,0 +1,122 @@ +load("@rules_license//rules:license.bzl", "license") +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package( + default_applicable_licenses = [":license"], + default_visibility = ["//visibility:public"], +) + +exports_files(["LICENSE"]) + +license( + name = "license", + package_name = "ffmpeg", + license_kinds = [ + "@rules_license//licenses/spdx:LGPL-3.0-or-later", + ], + license_text = "LICENSE", + package_url = "https://github.com/FFmpeg/FFmpeg", +) + +LGPL_LIBRARIES = [ + "libavcodec", + "libavdevice", + "libavfilter", + "libavformat", + "libavutil", + "libswresample", + "libswscale", +] + +LGPL_LIBRARY_VERSIONS = { + "libavcodec": [ + "libavcodec.so", + "libavcodec.so.61", + "libavcodec.so.61.3.100", + ], + "libavdevice": [ + "libavdevice.so", + "libavdevice.so.61", + "libavdevice.so.61.1.100", + ], + "libavfilter": [ + "libavfilter.so", + "libavfilter.so.10", + "libavfilter.so.10.1.100", + ], + "libavformat": [ + "libavformat.so", + "libavformat.so.61", + "libavformat.so.61.1.100", + ], + "libavutil": [ + "libavutil.so", + "libavutil.so.59", + "libavutil.so.59.8.100", + ], + "libswresample": [ + "libswresample.so", + "libswresample.so.5", + "libswresample.so.5.1.100", + ], + "libswscale": [ + "libswscale.so", + "libswscale.so.8", + "libswscale.so.8.1.100", + ], +} + +filegroup( + name = "all_srcs", + srcs = glob(["**"]), +) + +config_setting( + name = "opt_mode", + values = { + "compilation_mode": "opt", + }, +) + +# NOTE FFmpeg's configure script is not autoconf-based: https://trac.ffmpeg.org/ticket/9310 +# NOTE Bazel always uses the C++ compiler: https://github.com/bazelbuild/bazel/issues/4644 +configure_make( + name = "ffmpeg", + args = [ + "-j4", + ], + build_data = [ + "@yasm//:yasm_bin", + ], + configure_options = [ + "--cc=$$EXT_BUILD_ROOT/$(CC)", + "--host-cc=$$EXT_BUILD_ROOT/$(CC)", + "--cxx=$$EXT_BUILD_ROOT/$(CC)", + "--host-cflags=\"--sysroot=$$EXT_BUILD_ROOT/external/_main~repositories_ext~com_googleapis_storage_chrome_linux_amd64_sysroot/\"", + "--extra-cflags=\"--sysroot=$$EXT_BUILD_ROOT/external/_main~repositories_ext~com_googleapis_storage_chrome_linux_amd64_sysroot/\"", + "--pkg-config-flags=\"--static\"", + "--enable-pic", # TODO base on global config setting? + "--disable-stripping", # TODO define hermetic executable via --strip= + "--enable-shared", + "--disable-static", + "--x86asmexe=$$EXT_BUILD_ROOT/$(execpath @yasm//:yasm_bin)", + "--enable-version3", + "--enable-libaom", + "--enable-libsvtav1", + "--enable-libvpx", + "--enable-libdav1d", + "--disable-programs", + "--disable-doc", + ] + select({ + ":opt_mode": ["--disable-debug"], + "//conditions:default": [], + }), + lib_source = ":all_srcs", + out_shared_libs = [so for lib in LGPL_LIBRARIES for so in LGPL_LIBRARY_VERSIONS[lib]], + deps = [ + "@libaom", + "@libsvtav1", + "@libvpx", + "@libdav1d", + ], +) diff --git a/examples/third_party/ffmpeg/BUILD.libaom.bazel b/examples/third_party/ffmpeg/BUILD.libaom.bazel new file mode 100644 index 000000000..636309d65 --- /dev/null +++ b/examples/third_party/ffmpeg/BUILD.libaom.bazel @@ -0,0 +1,44 @@ +load("@rules_license//rules:license.bzl", "license") +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") + +package( + default_applicable_licenses = [":license"], + default_visibility = ["//visibility:public"], +) + +exports_files(["LICENSE"]) + +license( + name = "license", + package_name = "libaom", + license_kinds = [ + "@rules_license//licenses/spdx:BSD-3-Clause", + ], + license_text = "LICENSE", + package_url = "https://aomedia.googlesource.com/aom", +) + +filegroup( + name = "all_srcs", + srcs = glob(["**"]), +) + +cmake( + name = "libaom", + build_data = [ + "@yasm//:yasm_bin", + ], + cache_entries = { + "BUILD_SHARED_LIBS": "OFF", + "ENABLE_EXAMPLES": "OFF", + "ENABLE_TOOLS": "OFF", + "ENABLE_TESTS": "OFF", + }, + env = { + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_BUILD_PARALLEL_LEVEL": "4", + "PATH": "$$PATH:$$(dirname $(execpath @yasm//:yasm_bin))", + }, + lib_source = ":all_srcs", + out_static_libs = ["libaom.a"], +) diff --git a/examples/third_party/ffmpeg/BUILD.libdav1d.bazel b/examples/third_party/ffmpeg/BUILD.libdav1d.bazel new file mode 100644 index 000000000..20aaa10e3 --- /dev/null +++ b/examples/third_party/ffmpeg/BUILD.libdav1d.bazel @@ -0,0 +1,49 @@ +load("@rules_license//rules:license.bzl", "license") +load("@rules_foreign_cc//foreign_cc:defs.bzl", "meson") + +package( + default_applicable_licenses = [":license"], + default_visibility = ["//visibility:public"], +) + +exports_files(["LICENSE"]) + +license( + name = "license", + package_name = "libdav1d", + license_kinds = [ + "@rules_license//licenses/spdx:BSD-3-Clause-Clear", + ], + license_text = "LICENSE", + package_url = "https://code.videolan.org/videolan/dav1d", +) + +filegroup( + name = "all_srcs", + srcs = glob(["**"]), +) + +meson( + name = "libdav1d", + build_data = [ + "@nasm", + ], + build_args = [ + "-j4", + ], + lib_source = ":all_srcs", + options = { + "enable_tools": "false", + "enable_tests": "false", + }, + env = { + "PATH": "$$PATH:$$(dirname $(execpath @nasm))", + }, + out_lib_dir = "lib64", + #out_shared_libs = ["libdav1d.so", "libdav1d.so.7", "libdav1d.so.7.0.0"], + out_static_libs = ["libdav1d.a"], + setup_args = [ + "--buildtype=release", + "--default-library=static", + ], +) diff --git a/examples/third_party/ffmpeg/BUILD.libsvtav1.bazel b/examples/third_party/ffmpeg/BUILD.libsvtav1.bazel new file mode 100644 index 000000000..167d2262c --- /dev/null +++ b/examples/third_party/ffmpeg/BUILD.libsvtav1.bazel @@ -0,0 +1,46 @@ +load("@rules_license//rules:license.bzl", "license") +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") + +package( + default_applicable_licenses = [":license"], + default_visibility = ["//visibility:public"], +) + +exports_files(["LICENSE"]) + +license( + name = "license", + package_name = "libsvtav1", + license_kinds = [ + "@rules_license//licenses/spdx:BSD-3-Clause-Clear", + ], + license_text = "LICENSE", + package_url = "https://gitlab.com/AOMediaCodec/SVT-AV1", +) + +filegroup( + name = "all_srcs", + srcs = glob(["**"]), +) + +cmake( + name = "libsvtav1", + build_data = [ + "@yasm//:yasm_bin", + ], + cache_entries = { + "BUILD_SHARED_LIBS": "OFF", + "BUILD_DEC": "OFF", + "BUILD_APPS": "ON", + "BUILD_TESTING": "OFF", + "ENABLE_AVX512": "ON", + }, + env = { + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_BUILD_PARALLEL_LEVEL": "4", + "PATH": "$$PATH:$$(dirname $(execpath @yasm//:yasm_bin))", + }, + lib_source = ":all_srcs", + out_binaries = ["SvtAv1EncApp"], + out_static_libs = ["libSvtAv1Enc.a"], +) diff --git a/examples/third_party/ffmpeg/BUILD.libvpx.bazel b/examples/third_party/ffmpeg/BUILD.libvpx.bazel new file mode 100644 index 000000000..74f3663a1 --- /dev/null +++ b/examples/third_party/ffmpeg/BUILD.libvpx.bazel @@ -0,0 +1,47 @@ +load("@rules_license//rules:license.bzl", "license") +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package( + default_applicable_licenses = [":license"], + default_visibility = ["//visibility:public"], +) + +exports_files(["LICENSE"]) + +license( + name = "license", + package_name = "libvpx", + license_kinds = [ + "@rules_license//licenses/spdx:BSD-3-Clause", + ], + license_text = "LICENSE", + package_url = "https://chromium.googlesource.com/libvpx/libvpx", +) + +filegroup( + name = "all_srcs", + srcs = glob(["**"]), +) + +configure_make( + name = "libvpx", + build_data = [ + "@yasm//:yasm_bin", + ], + configure_options = [ + "--disable-shared", + "--enable-static", + "--enable-pic", + "--disable-examples", + "--disable-tools", + "--disable-docs", + "--disable-unit-tests", + "--enable-vp9-highbitdepth", + "--as=yasm", + ], + env = { + "PATH": "$$PATH:$$(dirname $(execpath @yasm//:yasm_bin))", + }, + lib_source = ":all_srcs", + out_static_libs = ["libvpx.a"], +) diff --git a/examples/third_party/ffmpeg/BUILD.libyuv.bazel b/examples/third_party/ffmpeg/BUILD.libyuv.bazel new file mode 100644 index 000000000..b0d0d9fe5 --- /dev/null +++ b/examples/third_party/ffmpeg/BUILD.libyuv.bazel @@ -0,0 +1,36 @@ +load("@rules_license//rules:license.bzl", "license") +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") + +package( + default_applicable_licenses = [":license"], + default_visibility = ["//visibility:public"], +) + +exports_files(["LICENSE"]) + +license( + name = "license", + package_name = "libyuv", + license_kinds = [ + "@rules_license//licenses/spdx:BSD-3-Clause", + ], + license_text = "LICENSE", + package_url = "https://chromium.googlesource.com/libyuv/libyuv", +) + +filegroup( + name = "all_srcs", + srcs = glob(["**"]), +) + +cmake( + name = "libyuv", + env = { + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_BUILD_PARALLEL_LEVEL": "4", + }, + lib_source = ":all_srcs", + out_shared_libs = ["libyuv.so"], + out_static_libs = ["libyuv.a"], + deps = ["@libjpeg_turbo//:jpeg"], +) diff --git a/examples/third_party/ffmpeg/BUILD.yasm.bazel b/examples/third_party/ffmpeg/BUILD.yasm.bazel new file mode 100644 index 000000000..24cf7482d --- /dev/null +++ b/examples/third_party/ffmpeg/BUILD.yasm.bazel @@ -0,0 +1,50 @@ +load("@rules_license//rules:license.bzl", "license") +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake", "runnable_binary") + +package( + default_applicable_licenses = [":license"], + default_visibility = ["//visibility:public"], +) + +exports_files(["LICENSE"]) + +license( + name = "license", + package_name = "yasm", + license_kinds = [ + "@rules_license//licenses/spdx:BSD-3-Clause", + ], + license_text = "LICENSE", + package_url = "https://github.com/yasm/yasm", +) + +filegroup( + name = "all_srcs", + srcs = glob(["**"]), +) + +cmake( + name = "make_yasm", + cache_entries = { + "BUILD_SHARED_LIBS": "OFF", + }, + env = { + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_BUILD_PARALLEL_LEVEL": "4", + }, + lib_source = ":all_srcs", + out_binaries = ["yasm"], +) + +runnable_binary( + name = "runnable_yasm", + binary = "yasm", + foreign_cc_target = ":make_yasm", + match_binary_name = True, +) + +filegroup( + name = "yasm_bin", + srcs = [":make_yasm"], + output_group = "yasm", +) diff --git a/examples/third_party/ffmpeg/ffmpeg_repositories.bzl b/examples/third_party/ffmpeg/ffmpeg_repositories.bzl new file mode 100644 index 000000000..006cba8fb --- /dev/null +++ b/examples/third_party/ffmpeg/ffmpeg_repositories.bzl @@ -0,0 +1,71 @@ +"""A module defining the third party dependency ffmpeg""" + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") + +# buildifier: disable=function-docstring +def ffmpeg_repositories(): + maybe( + http_archive, + name = "ffmpeg", + build_file = Label("//ffmpeg:BUILD.ffmpeg.bazel"), + strip_prefix = "FFmpeg-n7.0.2", + urls = ["https://github.com/FFmpeg/FFmpeg/archive/refs/tags/n7.0.2.tar.gz"], + integrity = "sha256-XrRtGNZkoMyt97Ct7gO9O3+nKJPWZ/NsaeICqAfm1TM=", + ) + + YASM_COMMMIT = "121ab150b3577b666c79a79f4a511798d7ad2432" + maybe( + http_archive, + name = "yasm", + build_file = Label("//ffmpeg:BUILD.yasm.bazel"), + strip_prefix = "yasm-%s" % YASM_COMMMIT, + urls = ["https://github.com/yasm/yasm/archive/%s.tar.gz" % YASM_COMMMIT], + integrity = "sha256-PfFT8fuUUTq5LLHaf7g3ejFW93TWi8z070IJRzqqG7Y=", + ) + + LIBYUV_COMMIT = "77f3acade492a41a11a07a55b58a6f8180b898eb" + maybe( + http_archive, + name = "libyuv", + build_file = Label("//ffmpeg:BUILD.libyuv.bazel"), + sha256 = "6c898607e2ec3a38cd88f210bd6eb17f0be9e89274d9b5b1e5a83ed29219d3a8", + strip_prefix = "libyuv-%s" % LIBYUV_COMMIT, + urls = ["https://github.com/lemenkov/libyuv/archive/%s.tar.gz" % LIBYUV_COMMIT], + ) + + maybe( + http_archive, + name = "libvpx", + build_file = Label("//ffmpeg:BUILD.libvpx.bazel"), + sha256 = "901747254d80a7937c933d03bd7c5d41e8e6c883e0665fadcb172542167c7977", + strip_prefix = "libvpx-1.14.1", + urls = ["https://github.com/webmproject/libvpx/archive/refs/tags/v1.14.1.tar.gz"], + ) + + maybe( + http_archive, + name = "libaom", + build_file = Label("//ffmpeg:BUILD.libaom.bazel"), + sha256 = "d1f2bd34b61ff1e58e72946825accd5f5fc23212055bf78161f6fa5b6d93b925", + strip_prefix = "aom-3.10.0", + urls = ["https://github.com/jbeich/aom/archive/refs/tags/v3.10.0.tar.gz"], + ) + + maybe( + http_archive, + name = "libsvtav1", + build_file = Label("//ffmpeg:BUILD.libsvtav1.bazel"), + strip_prefix = "SVT-AV1-v2.2.1", + urls = ["https://gitlab.com/AOMediaCodec/SVT-AV1/-/archive/v2.2.1/SVT-AV1-v2.2.1.tar.gz"], + integrity = "sha256-0CtUaFVC3gI2vOS+G1CRKrpor/mXxDs1DYSlGN8M9OU=", + ) + + maybe( + http_archive, + name = "libdav1d", + build_file = Label("//ffmpeg:BUILD.libdav1d.bazel"), + strip_prefix = "dav1d-1.4.3", + urls = ["https://code.videolan.org/videolan/dav1d/-/archive/1.4.3/dav1d-1.4.3.tar.gz"], + integrity = "sha256-iKAj5Y2VXgiG+vSccpQODpCRSpSKjmDBMmzj4J56YJk=", + ) diff --git a/examples/third_party/openssl/openssl_repositories.bzl b/examples/third_party/openssl/openssl_repositories.bzl index bc63791cd..7ad97f3d7 100644 --- a/examples/third_party/openssl/openssl_repositories.bzl +++ b/examples/third_party/openssl/openssl_repositories.bzl @@ -17,17 +17,17 @@ def openssl_repositories(): ], ) - maybe( - http_archive, - name = "nasm", - build_file = Label("//openssl:BUILD.nasm.bazel"), - sha256 = "f5c93c146f52b4f1664fa3ce6579f961a910e869ab0dae431bd871bdd2584ef2", - strip_prefix = "nasm-2.15.05", - urls = [ - "https://mirror.bazel.build/www.nasm.us/pub/nasm/releasebuilds/2.15.05/win64/nasm-2.15.05-win64.zip", - "https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/win64/nasm-2.15.05-win64.zip", - ], - ) + # maybe( + # http_archive, + # name = "nasm", + # build_file = Label("//openssl:BUILD.nasm.bazel"), + # sha256 = "f5c93c146f52b4f1664fa3ce6579f961a910e869ab0dae431bd871bdd2584ef2", + # strip_prefix = "nasm-2.15.05", + # urls = [ + # "https://mirror.bazel.build/www.nasm.us/pub/nasm/releasebuilds/2.15.05/win64/nasm-2.15.05-win64.zip", + # "https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/win64/nasm-2.15.05-win64.zip", + # ], + # ) maybe( http_archive, diff --git a/examples/third_party/repositories.bzl b/examples/third_party/repositories.bzl index e8ddb08cd..78f1bf482 100644 --- a/examples/third_party/repositories.bzl +++ b/examples/third_party/repositories.bzl @@ -8,6 +8,7 @@ load("//autotools:autotools_repositories.bzl", "autotools_repositories") load("//bison:bison_repositories.bzl", "bison_repositories") load("//cares:cares_repositories.bzl", "cares_repositories") load("//curl:curl_repositories.bzl", "curl_repositories") +load("//ffmpeg:ffmpeg_repositories.bzl", "ffmpeg_repositories") load("//glib:glib_repositories.bzl", "glib_repositories") load("//gn:gn_repositories.bzl", "gn_repositories") load("//gperftools:gperftools_repositories.bzl", "gperftools_repositories") @@ -26,7 +27,7 @@ load("//subversion:subversion_repositories.bzl", "subversion_repositories") load("//zlib:zlib_repositories.bzl", "zlib_repositories") # buildifier: disable=unnamed-macro -def repositories(): +def _repositories_impl(ctx = None): """Load all repositories needed for the targets of rules_foreign_cc_examples_third_party""" apr_repositories() apr_util_repositories() @@ -34,6 +35,7 @@ def repositories(): bison_repositories() cares_repositories() curl_repositories() + ffmpeg_repositories() glib_repositories() gn_repositories() gperftools_repositories() @@ -51,9 +53,26 @@ def repositories(): subversion_repositories() zlib_repositories() + maybe( + http_archive, + name = "com_googleapis_storage_chrome_linux_amd64_sysroot", + build_file = Label("//:BUILD.sysroot.bazel"), + sha256 = "5df5be9357b425cdd70d92d4697d07e7d55d7a923f037c22dc80a78e85842d2c", + urls = [ + # features.h defines GLIBC 2.31. + "https://storage.googleapis.com/chrome-linux-sysroot/toolchain/4f611ec025be98214164d4bf9fbe8843f58533f7/debian_bullseye_amd64_sysroot.tar.xz", + ], + ) + + +def repositories(): + _repositories_impl() + maybe( http_archive, name = "rules_cc", urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.1/rules_cc-0.0.1.tar.gz"], sha256 = "4dccbfd22c0def164c8f47458bd50e0c7148f3d92002cdb459c2a96a68498241", ) + +repositories_ext = module_extension(implementation = _repositories_impl)