-
Notifications
You must be signed in to change notification settings - Fork 2k
luajit: fix building for iOS and Android #26577
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
base: master
Are you sure you want to change the base?
Changes from all commits
5ac8985
66e46ce
7511d4b
f80d3b9
264d262
c51d6f1
d8570b6
37e458b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -41,6 +42,15 @@ 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_build(self): | ||
if 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 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") | ||
|
@@ -59,7 +69,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): | ||
|
@@ -83,18 +97,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
+107
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 It should really be something like cc = AutotoolsToolchain(self).vars()["CC"]
args.append(f"CC={cc}") Similarly, There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
diff --git a/Makefile b/Makefile | ||
index d789e9f374..c41b3345dd 100644 | ||
--- a/Makefile | ||
+++ b/Makefile | ||
@@ -97,7 +97,7 @@ else | ||
endif | ||
TARGET_SYS?= $(HOST_SYS) | ||
|
||
-ifeq (Darwin,$(TARGET_SYS)) | ||
+ifneq (,$(filter $(TARGET_SYS),Darwin iOS)) | ||
INSTALL_SONAME= $(INSTALL_DYLIBNAME) | ||
INSTALL_SOSHORT1= $(INSTALL_DYLIBSHORT1) | ||
INSTALL_SOSHORT2= $(INSTALL_DYLIBSHORT2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to my understanding this should also go to
validate_build
, please let me know if I should adjust it in this PR