Skip to content
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

Add ffmpeg example #1295

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Add ffmpeg example #1295

wants to merge 3 commits into from

Conversation

mering
Copy link

@mering mering commented Oct 1, 2024

This does not build with the configured hermetic toolchain.

Instructions

(Optional) Run in container

Create container:

docker run -it --rm -v $(pwd):/work -w /work debian:12

Setup container:

apt update && apt install -y curl libxml2 python3
curl -LSs "https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-amd64" -o "/usr/bin/bazelisk" && chmod +x "/usr/bin/bazelisk" && ln -s "/usr/bin/bazelisk" "/usr/bin/bazel"
useradd --shell /bin/bash --create-home builder
su builder

Build

cd examples/third_party
USE_BAZEL_VERSION=7.x bazelisk build --verbose_failures @ffmpeg

@voxeljorge
Copy link
Contributor

I've also run into this, while trying to build ffmpeg with rules_foreign_cc

I'm able to get a successful build by letting bazel just select the local c compiler but ideally I would like to use a hermetic llvm + sysroot.

@voxeljorge
Copy link
Contributor

my build fails with errors like this:

gcc: error: unrecognized command line option '--target=x86_64-unknown-linux-gnu'
gcc: error: unrecognized command line option '-fcolor-diagnostics'
gcc: error: unrecognized command line option '-Wthread-safety'
gcc: error: unrecognized command line option '-Wself-assign'

in config.log

@voxeljorge
Copy link
Contributor

Seems like this bug is probably related: https://trac.ffmpeg.org/ticket/9310

@voxeljorge
Copy link
Contributor

Adding "--cc=$$EXT_BUILD_ROOT/$(CC)" to configure_options fixed my build. I suspect that might work for this PR as well.

@mering
Copy link
Author

mering commented Oct 14, 2024

Adding "--cc=$$EXT_BUILD_ROOT/$(CC)" to configure_options fixed my build. I suspect that might work for this PR as well.

@voxeljorge We have already been setting the --cc option but I like using the CC environment variable instead of the hard-coded path. I updated my example accordingly.

Unfortunately, the build still doesn't work (see PR description for instructions on how to reproduce the different errors).
The error for building ffmpeg is Host compiler lacks C11 support, even when setting --host-cc=$$EXT_BUILD_ROOT/$(CC).

@voxeljorge
Copy link
Contributor

I found that I had similar errors because not only is configure not using CC, it is also not using CFLAGS or any of the other env vars. I ended up writing a wrapper configure_wrapper which would read the env vars and set --cc, --extral-cflags etc

@mering
Copy link
Author

mering commented Oct 14, 2024

I found that I had similar errors because not only is configure not using CC, it is also not using CFLAGS or any of the other env vars. I ended up writing a wrapper configure_wrapper which would read the env vars and set --cc, --extral-cflags etc

@voxeljorge Could you share your wrapper?

I noticed that my build was missing the --sysroot as CFLAGS. I updated my branch accordingly but the hardcoded paths are ugly. Is this available in some makevar or similar?

libvpx and libdav1d are still not building in my branch. Do these codec libraries build for you?

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.
@mering
Copy link
Author

mering commented Oct 16, 2024

I created two fixes for libdav1d with meson: #1302 #1303

@voxeljorge
Copy link
Contributor

I don't build libvpx or libdav1d at all. The configure wrapper is trivial:

#!/bin/bash

# ffmpeg ignores flags like CC/CXX and CFLAGS: https://trac.ffmpeg.org/ticket/9310
# so we have a wrapper which assigns them correctly
exec "$(dirname "$0")"/configure \
	--cc="$CC" \
	--cxx="$CXX" \
	--extra-cflags="$CFLAGS" \
	--extra-cxxflags="$CXXFLAGS" \
	--extra-ldflags="$LDFLAGS" \
	"$@"

The wrapper can be installed a couple of ways, you could inject it during the repository creation time what I did was copy the sources with something like this:

load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")

copy_to_directory(
    name = "src",
    srcs = [
        "configure_wrapper",
        "@ffmpeg_7_0_sources",
    ],
    include_external_repositories = ["ffmpeg_7_0_sources"],
)

configure_make(
    name = "ffmpeg",
    lib_source = "//third_party/ffmpeg:src",
    configure_command = "src/configure_wrapper",
)

I do have ffmpeg building with a limited set of codecs currently, even with a modern llvm and sysroot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants