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

luajit: fix building for iOS and Android #26577

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions recipes/luajit/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ patches:
- patch_file: "patches/2.1.0-beta3-0001-remove-mac-deploy.patch"
patch_type: "conan"
patch_description: "Do not enforce default value for MACOSX_DEPLOYMENT_TARGET"
- patch_file: "patches/2.1.0-beta3-fix-so-symlinks-with-missing-ldconfig.diff"
patch_description: "Fix POSIX install with missing or incompatible ldconfig"
patch_source: "https://github.com/LuaJIT/LuaJIT/commit/18c9cf7d3788a8f7408df45df92fc4ae3bcc0d80"
patch_type: "bugfix"
66 changes: 57 additions & 9 deletions recipes/luajit/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from conan.tools.microsoft import is_msvc, MSBuildToolchain, VCVars, unix_path
from conan.tools.layout import basic_layout
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.apple import is_apple_os
from conan.tools.apple import XCRun, to_apple_arch
from conan.tools.build import cross_building
from conan.tools.env import VirtualBuildEnv
from conan.errors import ConanInvalidConfiguration
import os

Expand Down Expand Up @@ -41,11 +42,18 @@ def configure(self):
def layout(self):
basic_layout(self, src_folder="src")

@property
def _is_host_32bit(self):
return self.settings.arch in ["armv7", "x86"]

def validate(self):
if self.settings.os == "Macos" and self.settings.arch == "armv8" and cross_building(self):
raise ConanInvalidConfiguration(f"{self.ref} can not be cross-built to Mac M1. Please, try any version >=2.1")
elif Version(self.version) <= "2.1.0-beta1" and self.settings.os == "Macos" and self.settings.arch == "armv8":
raise ConanInvalidConfiguration(f"{self.ref} is not supported by Mac M1. Please, try any version >=2.1")
elif self._is_host_32bit and self.settings_build.os == "Macos":
# well, technically it should work on macOS <= 10.14
raise ConanInvalidConfiguration(f"{self.ref} cannot be cross-built to a 32-bit platform on macOS, see https://github.com/LuaJIT/LuaJIT/issues/664")

def source(self):
filename = f"LuaJIT-{self.version}.tar.gz"
Expand All @@ -59,7 +67,11 @@ def generate(self):
tc.generate()
else:
tc = AutotoolsToolchain(self)
tc.generate()
env = tc.environment()
if self.settings.os == "iOS" or self.settings.os == "Android":
env.define("CFLAGS", "")
env.define("LDFLAGS", "")
tc.generate(env)

def _patch_sources(self):
if not is_msvc(self):
Expand All @@ -83,18 +95,54 @@ def _patch_sources(self):
replace_in_file(self, makefile,
'TARGET_O= $(LUAJIT_A)',
'TARGET_O= $(LUAJIT_SO)')
if "clang" in str(self.settings.compiler):
replace_in_file(self, makefile, 'CC= $(DEFAULT_CC)', 'CC= clang')

@property
def _macosx_deployment_target(self):
return self.settings.get_safe("os.version")
def _apple_deployment_target(self, default=None):
return self.settings.get_safe("os.version", default=default)

@property
def _make_arguments(self):
args = [f"PREFIX={unix_path(self, self.package_folder)}"]
if is_apple_os(self) and self._macosx_deployment_target:
args.append(f"MACOSX_DEPLOYMENT_TARGET={self._macosx_deployment_target}")
if "clang" in str(self.settings.compiler):
args.append("DEFAULT_CC=clang")
Comment on lines +105 to +106
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect and basically reproduces the existing sloppy handling of CC in the recipe. It hackily replaces the default CC=gcc with clang, but it ignores the exact compiler executable set in the Conan profile and won't work for any other compilers in general.

It should really be something like

cc = AutotoolsToolchain(self).vars()["CC"]
args.append(f"CC={cc}")

Similarly, HOST_CC needs to be set to the CC_FOR_BUILD value from the toolchain vars. Something like conan-io/conan#17602 would be very welcome here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what iOS build docs suggest to do. So should I add this variable only for iOS then and revert the general compiler adjustment?


# upstream doesn't read CPPFLAGS, inject them manually
cppflags = AutotoolsToolchain(self).environment().vars(self).get("CPPFLAGS")
args.append(f"TARGET_CFLAGS='{cppflags}'")

if self.settings.os == "Macos" and self._apple_deployment_target():
args.append(f"MACOSX_DEPLOYMENT_TARGET={self._apple_deployment_target()}")
elif self.settings.os == "iOS":
xcrun = XCRun(self)
target_flag = f"{to_apple_arch(self)}-apple-ios{self._apple_deployment_target(default='')}"
args.extend([
f"CROSS={os.path.dirname(xcrun.cxx)}/",
f"""TARGET_FLAGS='-isysroot "{xcrun.sdk_path}" -target {target_flag}'""",
"TARGET_SYS=iOS",
])
elif self.settings.os == "Android":
buildenv_vars = VirtualBuildEnv(self).vars()
compiler_path = buildenv_vars.get("CC")
triplet_prefix = f"{buildenv_vars.get('CHOST')}-"
args.extend([
f"CROSS={os.path.join(buildenv_vars.get('NDK_ROOT'), 'bin', triplet_prefix)}",
f"DYNAMIC_CC='{compiler_path} -fPIC'",
f"STATIC_CC={compiler_path}",
f"TARGET_AR='{buildenv_vars.get('AR')} rcus'",
f"TARGET_LD={compiler_path}",
f"TARGET_STRIP={buildenv_vars.get('STRIP')}",
])
if self._is_host_32bit:
args.append("HOST_CC='gcc -m32'")
if self.settings_build.os != "Linux":
args.append("TARGET_SYS=Linux")
if self.settings_build.os == "Macos":
# must look for headers in macOS SDK, having NDK clang in PATH breaks this default behavior
xcrun_build = XCRun(self, sdk='macosx')
isysroot_flag = f"""'-isysroot "{xcrun_build.sdk_path}"'"""
args.extend([
f"HOST_CFLAGS={isysroot_flag}",
f"HOST_LDFLAGS={isysroot_flag}",
])
return args

@property
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/Makefile b/Makefile
index 07bc70faf4..bff53f2867 100644
--- a/Makefile
+++ b/Makefile
@@ -75,7 +75,7 @@ SYMLINK= ln -sf
INSTALL_X= install -m 0755
INSTALL_F= install -m 0644
UNINSTALL= $(RM)
-LDCONFIG= ldconfig -n
+LDCONFIG= ldconfig -n 2>/dev/null
SED_PC= sed -e "s|^prefix=.*|prefix=$(PREFIX)|" \
-e "s|^multilib=.*|multilib=$(MULTILIB)|"

@@ -121,7 +121,7 @@ install: $(INSTALL_DEP)
$(RM) $(INSTALL_DYN) $(INSTALL_SHORT1) $(INSTALL_SHORT2)
cd src && test -f $(FILE_SO) && \
$(INSTALL_X) $(FILE_SO) $(INSTALL_DYN) && \
- $(LDCONFIG) $(INSTALL_LIB) && \
+ ( $(LDCONFIG) $(INSTALL_LIB) || : ) && \
$(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT1) && \
$(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT2) || :
cd etc && $(INSTALL_F) $(FILE_MAN) $(INSTALL_MAN)