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

libx264: Fix Android build #24587

Merged
merged 2 commits into from
Jul 15, 2024
Merged
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
3 changes: 3 additions & 0 deletions recipes/libx264/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"cci.20240224":
url: "https://code.videolan.org/videolan/x264/-/archive/7241d020118bb09cc0ad119d7bc9f630a1caad10/x264-7241d020118bb09cc0ad119d7bc9f630a1caad10.tar.bz2"
sha256: "5417c167a69cc19db044c227163f9b9b1dface9fca361a3e83d5417f8e304dd6"
"cci.20220602":
url: "https://code.videolan.org/videolan/x264/-/archive/baee400fa9ced6f5481a728138fed6e867b0ff7f/x264-baee400fa9ced6f5481a728138fed6e867b0ff7f.tar.bz2"
sha256: "ce6623b8b289765daee04a297c2fd1a293cb2565a1749c76d66c8d72c7ddc1ab"
Expand Down
38 changes: 21 additions & 17 deletions recipes/libx264/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,29 @@ def generate(self):

if cross_building(self):
if self.settings.os == "Android":
# the as of ndk does not work well for building libx264
env = Environment()
buildenv_vars = VirtualBuildEnv(self).vars()
ndk_root = self.conf.get("tools.android:ndk_path", buildenv_vars.get("NDK_ROOT"))

# INFO: Conan package android-ndk does not expose toolchain path. Looks fragile but follows always same for Android NDK
build_os = {"Linux": "linux", "Macos": "darwin", "Windows": "windows"}.get(str(self._settings_build.os))
toolchain = os.path.join(ndk_root, "toolchains", "llvm", "prebuilt", f"{build_os}-{self._settings_build.arch}")

sysroot = self.conf.get("tools.build:sysroot", buildenv_vars.get("SYSROOT", f"{toolchain}/sysroot"))
# INFO: x264 will look for strings appended to the cross prefix
cross_prefix = os.path.join(toolchain, "bin", "llvm-")

compilers_from_conf = self.conf.get("tools.build:compiler_executables", default={}, check_type=dict)
buildenv_vars = VirtualBuildEnv(self).vars()
cc = compilers_from_conf.get("c", buildenv_vars.get("CC", "clang-cl"))
env.define("AS", cc)

ndk_root = self.conf.get("tools.android:ndk_path")

arch = {
"armv7": "arm",
"armv8": "aarch64",
"x86": "i686",
"x86_64": "x86_64",
}.get(str(self.settings.arch))
abi = "androideabi" if self.settings.arch == "armv7" else "android"
args["--cross-prefix"] = f"{ndk_root}/bin/{arch}-linux-{abi}-"
env.vars(self).save_script("conanbuild_android")

args["--build"] = None # --build is not recognized
args["--cross-prefix"] = cross_prefix
args["--sysroot"] = sysroot

# the as of ndk does not work well for building libx264
env = Environment()
cc_as = compilers_from_conf.get("c", buildenv_vars.get("AS", "clang"))
env.define("AS", cc_as)
env_vars = env.vars(self, scope="build")
env_vars.save_script("conanbuild_android")

if is_msvc(self):
env = Environment()
Expand Down
2 changes: 2 additions & 0 deletions recipes/libx264/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"cci.20240224":
folder: all
"cci.20220602":
folder: all
"20191217":
Expand Down
Loading