blob: 7b6e46a53c06129877c44b31e20ce50be924b124 [file] [edit]
load("@bazel_lib//lib:write_source_files.bzl", "write_source_file")
load("@package_metadata//licenses/rules:license.bzl", "license")
load("@package_metadata//licenses/rules:license_kind.bzl", "license_kind")
load("@package_metadata//rules:package_metadata.bzl", "package_metadata")
load("@rules_foreign_cc//foreign_cc:configure.bzl", "configure_make")
load("@stardust_build_package_metadata_mirror_url//:mirror_url.bzl", "mirror_url")
load("//stardust-build/toolchains:sccache_cc_tool.bzl", "sccache_wrapper_script")
load(":ffbuild/templates.bzl", "ffmepg_configure_args")
load(":license.bzl", "concat_package_licenses")
package(
default_package_metadata = [":package_metadata"],
)
package_metadata(
name = "package_metadata",
attributes = [
":license",
":mirror_url",
],
purl = "pkg:github/FFmpeg/FFmpeg@n7.0.3",
)
license_kind(
name = "license_kind",
full_name = "FFmpeg Composite License",
identifier = " AND ".join([
"Apache-2.0",
"BSD-1-Clause",
"BSD-2-Clause",
"BSD-3-Clause",
"BSL-1.0",
"IJG",
"ISC",
"LGPL-2.0",
"LGPL-2.1",
"MIT",
"Zlib",
]),
)
license(
name = "license",
kind = ":license_kind",
text = ":LICENSE.txt",
)
mirror_url(
name = "mirror_url",
url = "https://third-party-mirror.googlesource.com/play-games/ffmpeg",
)
concat_package_licenses(
name = "concat_licenses",
)
write_source_file(
name = "write_license",
in_file = ":concat_licenses",
out_file = "LICENSE.txt",
)
filegroup(
name = "all_srcs",
srcs = glob(
include = ["**"],
exclude = ["BUILD"],
),
)
sccache_wrapper_script(
name = "sccache_cc",
cc_path = "$(CC)",
package_metadata = [":package_metadata"],
toolchains = [":ffmepg_configure_args"],
)
sccache_wrapper_script(
name = "sccache_host_cc",
cc_path = "$(HOST_CC)",
package_metadata = [":package_metadata"],
toolchains = [":ffmepg_configure_args"],
)
ffmepg_configure_args(name = "ffmepg_configure_args")
# The ffmpeg configure script doesn't respect the following envs: CC, LD, AR, NM, PKG_CONFIG so we
# have to manually set them via the arguments, but the configure script does respect the following
# envs: CFLAGS, LDFLAGS, so we don't have to manually set them.
_TOOLCHAIN_OPTIONS = [
"--ar=$$EXT_BUILD_ROOT$$/$(AR)",
# Use the compiler driver for linkage.
"--ld=$$EXT_BUILD_ROOT$$/$(CC)",
"--nm=$$EXT_BUILD_ROOT$$/$(NM)",
"--strip=$$EXT_BUILD_ROOT$$/$(STRIP)",
] + select({
"//stardust-build/toolchains:sccache_enabled": [
"--cc=$$EXT_BUILD_ROOT$$/$(execpath :sccache_cc)",
"--host-cc=$$EXT_BUILD_ROOT$$/$(execpath :sccache_host_cc)",
],
"//conditions:default": [
"--cc=$$EXT_BUILD_ROOT$$/$(CC)",
"--host-cc=$$EXT_BUILD_ROOT$$/$(HOST_CC)",
],
})
configure_make(
name = "ffmpeg",
configure_options =
# Compile FFmpeg without "--enable-gpl" and without "--enable-nonfree" for LGPL compliance.
# Also compile without "--enable-version3", so that FFmpeg is compliant with LGPLv2.1.
select(
{"@platforms//os:android": ["--target-os=android"]},
no_match_error = "Unsupported target OS",
) + select(
{
"@platforms//cpu:arm64": ["--arch=aarch64"],
"@platforms//cpu:x86_64": [
"--arch=x86_64",
"--disable-x86asm",
],
},
no_match_error = "Unsupported CPU arch",
) + _TOOLCHAIN_OPTIONS + [
"--enable-cross-compile",
"--pkg_config=$$PKG_CONFIG",
"--disable-static",
"--enable-shared",
"--disable-doc",
"--disable-programs",
"--disable-indevs",
"--disable-outdevs",
"--enable-indev=lavfi",
"--enable-jni",
"--enable-mediacodec",
"--enable-libfreetype",
"--enable-libxml2",
"--enable-libopus",
"--enable-libvorbis",
"--enable-vulkan",
"--enable-zlib",
"--disable-decoders",
"--enable-decoder=aac_mediacodec",
"--enable-decoder=amrnb_mediacodec",
"--enable-decoder=amrwb_mediacodec",
"--enable-decoder=av1_mediacodec",
"--enable-decoder=h264_mediacodec",
"--enable-decoder=hevc_mediacodec",
"--enable-decoder=mp3_mediacodec",
"--enable-decoder=mpeg2_mediacodec",
"--enable-decoder=mpeg4_mediacodec",
"--enable-decoder=vp8_mediacodec",
"--enable-decoder=vp9_mediacodec",
"--disable-encoders",
"--disable-filter=codecview",
] + select({
"//stardust-build/config:dbg_mode": [],
"//conditions:default": [
"--disable-debug",
],
}),
data = select({
"//stardust-build/toolchains:sccache_enabled": [
# The sccache wrapper scripts must be listed in data instead of build_data, so that
# $(CC) resolves to the target toolchain, i.e., Android NDK toolchain, instead of the
# build machine toolchain Linux C/C++ toolchain.
":sccache_cc",
":sccache_host_cc",
],
"//conditions:default": [],
}),
lib_source = ":all_srcs",
out_shared_libs = [
"libavcodec.so",
"libavdevice.so",
"libavfilter.so",
"libavformat.so",
"libavutil.so",
"libswresample.so",
"libswscale.so",
],
resource_size = "enormous",
toolchains = [":ffmepg_configure_args"],
visibility = ["//visibility:public"],
deps = [
"//third_party/Vulkan-Headers",
"//third_party/freetype",
"//third_party/libvorbis",
"//third_party/libxml2",
"//third_party/opus",
],
)