Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fabric.properties

# Bazel CI
bazelci.py
MODULE.bazel.lock

#####
# Bazel: https://github.com/github/gitignore/blob/master/community/Bazel.gitignore
Expand Down
13 changes: 13 additions & 0 deletions examples/third_party/.bazelrc
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 additions & 0 deletions examples/third_party/BUILD.sysroot.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
45 changes: 45 additions & 0 deletions examples/third_party/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -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",
)
16 changes: 16 additions & 0 deletions examples/third_party/ffmpeg/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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__"],
)
128 changes: 128 additions & 0 deletions examples/third_party/ffmpeg/BUILD.ffmpeg.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
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 = [
"-j16",
],
build_data = [
"@yasm//:yasm_bin",
],
configure_options = [
#"--ar=$$EXT_BUILD_ROOT/$(AR)",
"--cc=$$EXT_BUILD_ROOT/$(CC)",
"--host-cc=$$EXT_BUILD_ROOT/$(CC)",
"--cxx=$$EXT_BUILD_ROOT/$(CC)",
#"--ld=$$EXT_BUILD_ROOT/$(CC)",
#"--host-ld=$$EXT_BUILD_ROOT/$(CC)",
#"--ld=$$EXT_BUILD_ROOT/$(LD)",
#"--host-ld=$$EXT_BUILD_ROOT/$(LD)",
# TODO get CFLAGS from toolchain
"--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",
],
)
44 changes: 44 additions & 0 deletions examples/third_party/ffmpeg/BUILD.libaom.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
58 changes: 58 additions & 0 deletions examples/third_party/ffmpeg/BUILD.libdav1d.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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 = {
# TODO toolchains_llvm also set other env vars: CC= CXX= LD= AR= CCAS= RANLIB= STRIP= CPPFLAGS= CFLAGS= CXXFLAGS= LDFLAGS=
#"CC": "$(CC)",
#"CXX": "$(CC)",
#"AR": "$$EXT_BUILD_ROOT/external/toolchains_llvm~~llvm~llvm_toolchain/bin/llvm-ar",
#"STRIP": "$$EXT_BUILD_ROOT/external/toolchains_llvm~~llvm~llvm_toolchain/bin/llvm-strip",
#"AR": "$$EXT_BUILD_ROOT/$$(dirname $(LD))/llvm-ar",
#"STRIP": "$$EXT_BUILD_ROOT/$$(dirname $(LD))/llvm-strip",
# TODO try -Dc_link_args=-L/path/to/lib insteadhg update
#"LIBRARY_PATH": "$$EXT_BUILD_ROOT/external/_main~repositories_ext~com_googleapis_storage_chrome_linux_amd64_sysroot/usr/lib/x86_64-linux-gnu",
"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",
],
)
Loading