Skip to content

Commit

Permalink
Fix Terra on macOS Movaje (#435)
Browse files Browse the repository at this point in the history
This commit enables Terra to build and pass all tests on macOS Mojave
without the installing the header package suggested in #365 (which
does not exist in macOS Catalina anyway).

Caveats:

  * It requires CMake. Make fails somewhere in the step where we run a
    Lua script to unpack the .a files.

  * It requires passing -DCMAKE_C_COMPILER=$(which CC), because
    apparently CMake tries to auto-detect the XCode installation, and
    LuaJIT can't build with that compiler.

  * It still requires setting INCLUDE_PATH="$(xcrun --sdk macosx
    --show-sdk-path)/usr/include". This may indicate we're still
    not getting all of the Clang initialization right.

  * It includes a workaround for LuaJIT/LuaJIT#575, which at the
    moment means we bump the deployment target to 10.7. Shouldn't
    matter for most users but if you want to use a LuaJIT 2.1 build
    from Git, this is now required.
  • Loading branch information
elliottslaughter committed Apr 22, 2020
1 parent 372b54b commit 2866e3e
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 20 deletions.
30 changes: 20 additions & 10 deletions .travis.yml
@@ -1,10 +1,8 @@
language: cpp
sudo: required
dist: xenial
osx_image: xcode10.1 # macOS 10.13
os:
- linux
- osx
compiler:
- gcc
- clang
Expand Down Expand Up @@ -39,20 +37,32 @@ jobs:
env: DOCKER_BUILD=ubuntu-18.04
- os: linux
env: DOCKER_BUILD=ubuntu-19.10
exclude:
# Various macOS tests seem to be broken.

# macOS tests
- os: osx
compiler: gcc
osx_image: xcode10.1 # macOS 10.13
compiler: clang
env: LLVM_CONFIG=llvm-config-3.5 CLANG=clang-3.5
- os: osx
env: LLVM_CONFIG=llvm-config-5.0 CLANG=clang-5.0 USE_CMAKE=1
osx_image: xcode10.1 # macOS 10.13
compiler: clang
env: LLVM_CONFIG=llvm-config-3.8 CLANG=clang-3.8
- os: osx
env: LLVM_CONFIG=llvm-config-6.0 CLANG=clang-6.0 USE_CMAKE=1 STATIC_LLVM=0 STATIC_LUAJIT=0
osx_image: xcode11.3 # macOS 10.14
compiler: clang
env: LLVM_CONFIG=llvm-config-6.0 CLANG=clang-6.0 USE_CMAKE=1
- os: osx
env: LLVM_CONFIG=llvm-config-8 CLANG=clang-8
osx_image: xcode11.3 # macOS 10.14
compiler: clang
env: LLVM_CONFIG=llvm-config-7 CLANG=clang-7 USE_CMAKE=1
- os: osx
env: LLVM_CONFIG=llvm-config-9 CLANG=clang-9
osx_image: xcode11.3 # macOS 10.14
compiler: clang
env: LLVM_CONFIG=llvm-config-8 CLANG=clang-8 USE_CMAKE=1
- os: osx
env: LLVM_CONFIG=llvm-config-9 CLANG=clang-9 USE_CMAKE=1 STATIC_LLVM=0 STATIC_LUAJIT=0
osx_image: xcode11.3 # macOS 10.14
compiler: clang
env: LLVM_CONFIG=llvm-config-9 CLANG=clang-9 USE_CMAKE=1

script:
- ./travis.sh
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -209,7 +209,8 @@ endif
build/lib/libluajit-5.1.a: build/$(LUAJIT_TAR)
(cd build; tar -xf $(LUAJIT_TAR))
# MACOSX_DEPLOYMENT_TARGET is a workaround for https://github.com/LuaJIT/LuaJIT/issues/484
(cd $(LUAJIT_DIR); $(MAKE) install PREFIX=$(realpath build) CC=$(CC) STATIC_CC="$(CC) -fPIC" MACOSX_DEPLOYMENT_TARGET=10.6)
# see also https://github.com/LuaJIT/LuaJIT/issues/575
(cd $(LUAJIT_DIR); $(MAKE) install PREFIX=$(realpath build) CC=$(CC) STATIC_CC="$(CC) -fPIC" MACOSX_DEPLOYMENT_TARGET=10.7)

release/include/terra/%.h: $(LUAJIT_INCLUDE)/%.h $(LUAJIT_LIB)
cp $(LUAJIT_INCLUDE)/$*.h $@
Expand Down
3 changes: 2 additions & 1 deletion cmake/Modules/GetLuaJIT.cmake
Expand Up @@ -104,7 +104,8 @@ else()
OUTPUT ${LUAJIT_STATIC_LIBRARY} ${LUAJIT_SHARED_LIBRARY_PATHS} ${LUAJIT_EXECUTABLE} ${LUAJIT_INSTALL_HEADERS}
DEPENDS ${LUAJIT_SOURCE_DIR}
# MACOSX_DEPLOYMENT_TARGET is a workaround for https://github.com/LuaJIT/LuaJIT/issues/484
COMMAND make install "PREFIX=${LUAJIT_INSTALL_PREFIX}" "CC=${CMAKE_C_COMPILER}" "STATIC_CC=${CMAKE_C_COMPILER} -fPIC" MACOSX_DEPLOYMENT_TARGET=10.6
# see also https://github.com/LuaJIT/LuaJIT/issues/575
COMMAND make install "PREFIX=${LUAJIT_INSTALL_PREFIX}" "CC=${CMAKE_C_COMPILER}" "STATIC_CC=${CMAKE_C_COMPILER} -fPIC" MACOSX_DEPLOYMENT_TARGET=10.7
WORKING_DIRECTORY ${LUAJIT_SOURCE_DIR}
VERBATIM
)
Expand Down
2 changes: 1 addition & 1 deletion tests/dynlib.t
@@ -1,7 +1,7 @@
local ffi = require 'ffi'
-- test that the dynamic library for terra was built correctly
-- by compiling a new program that links against it and running it
terralib.includepath = terralib.terrahome.."/include/terra"
terralib.includepath = terralib.includepath .. ";" .. terralib.terrahome .. "/include/terra"
C = terralib.includecstring [[
#include <stdio.h>
#include "terra.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/exportdynamic.t
@@ -1,4 +1,4 @@
terralib.includepath = terralib.terrahome.."/include/terra"
terralib.includepath = terralib.includepath .. ";" .. terralib.terrahome .. "/include/terra"
C = terralib.includecstring [[
#include "lua.h"
#include "lauxlib.h"
Expand Down
7 changes: 6 additions & 1 deletion tests/lib/objc.t
Expand Up @@ -14,13 +14,18 @@ local mangleSelector
--replace methods such as: myobj:methodcall(arg0,arg1)
--with calls to the objc runtime api: objc_msgSend(&obj,sel_registerName("methodcall"),arg0,arg1)

-- Hack: As of macOS 10.15 this type signature has changed, see:
-- https://www.mikeash.com/pyblog/objc_msgsends-new-prototype.html
local objc_msgSend_type = terralib.types.funcpointer(
{&C.objc_object, &C.objc_selector}, &C.objc_object, true)

local struct Wrapper {
data : &C.objc_object
}
Wrapper.metamethods.__methodmissing = macro(function(sel,obj,...)
local arguments = {...}
sel = mangleSelector(sel,#arguments)
return `Wrapper { C.objc_msgSend(obj.data,C.sel_registerName(sel),arguments) }
return `Wrapper { ([objc_msgSend_type](C.objc_msgSend))(obj.data,C.sel_registerName(sel),arguments) }
end)

function mangleSelector(sel,nargs)
Expand Down
2 changes: 1 addition & 1 deletion tests/luaapi.t
@@ -1,4 +1,4 @@
terralib.includepath = terralib.terrahome.."/include/terra"
terralib.includepath = terralib.includepath .. ";" .. terralib.terrahome .. "/include/terra"
C = terralib.includecstring [[
#include "lua.h"
#include "lauxlib.h"
Expand Down
25 changes: 21 additions & 4 deletions travis.sh
Expand Up @@ -142,6 +142,11 @@ if [[ $(uname) = Darwin ]]; then
hdiutil detach /Volumes/CUDAMacOSXInstaller
fi

# workaround for https://github.com/terralang/terra/issues/365
if [[ ! -e /usr/include ]]; then
export INCLUDE_PATH="$(xcrun --sdk macosx --show-sdk-path)/usr/include"
fi

export PATH=$PWD:$PATH
fi

Expand All @@ -167,16 +172,28 @@ if [[ $USE_CMAKE -eq 1 ]]; then
-DTERRA_SLIB_INCLUDE_LUAJIT=OFF
)
fi
if [[ $(uname) = Darwin ]]; then
# Hack: CMake tries to be smart and use XCode's copy of Clang by
# default. This causes LuaJIT to not build on Mojave and later
# (math.h not found) if the header package is not installed.
CMAKE_FLAGS+=(
-DCMAKE_C_COMPILER=$(which $CC)
-DCMAKE_CXX_COMPILER=$(which $CXX)
)
fi

pushd build
cmake .. -DCMAKE_INSTALL_PREFIX=$PWD/../install "${CMAKE_FLAGS[@]}"
make install -j2
ctest -j2 || (test "$(uname)" = "Darwin" && test "$LLVM_CONFIG" = "llvm-config-3.8")
ctest --output-on-failure -j2 || (test "$(uname)" = "Darwin" && test "$LLVM_CONFIG" = "llvm-config-3.8")
popd

pushd tests
../install/bin/terra ./run
popd
# Skip this on macOS because it spews too much on Mojave and newer.
if [[ $(uname) != Darwin ]]; then
pushd tests
../install/bin/terra ./run
popd
fi
else
make LLVM_CONFIG=$(which $LLVM_CONFIG) CLANG=$(which $CLANG) test

Expand Down

0 comments on commit 2866e3e

Please sign in to comment.