Skip to content

Commit

Permalink
Add workaround for Xcode 11.4 issues
Browse files Browse the repository at this point in the history
Based on the Polymake.jl patch, with a few minor tweaks.
Also adds a Travis test against Xcode 11.4 to verify this works.
  • Loading branch information
fingolfin committed May 1, 2020
1 parent 5f8149b commit 5cf4afb
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.jl.mem
/deps/build.log
/deps/build*.jl
/deps/build/
/deps/deps.jl
/deps/src/cmake_install.cmake
/deps/src/CMakeCache.txt
Expand All @@ -11,7 +12,8 @@
/deps/src/lib/
/deps/src/Makefile
/deps/usr/
/docs/build
/deps/xcodetypeinfo/build/
/docs/build/
/local/*
/Manifest.toml
/src/libraryfuncdictionary.jl
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ jobs:
- julia: nightly
fast_finish: true
include:
# test (one of) the oldest macOS configuration still supported by us
# (older ones have trouble compiling CxxWrap)
- os: osx
osx_image: xcode9.2 # latest version available for macOS 10.12 Sierra

# also test with latest macOS image and latest Julia
- julia: 1.4
os: osx
osx_image: xcode11.4

- stage: "Documentation"
name: "HTML"
julia: 1.3
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Singular"
uuid = "bcd08a7b-43d2-5ff7-b6d4-c458787f915c"
version = "0.3.0"
version = "0.3.1"

[deps]
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
Expand Down
41 changes: 38 additions & 3 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ issource_build = "SINGULAR_SOURCE_BUILD" in keys(ENV) && ENV["SINGULAR_SOURCE_BU

const prefixpath = joinpath(@__DIR__, "usr")
const wdir = joinpath(@__DIR__)
const oldwdir = pwd()

const nemodir = realpath(joinpath(dirname(pathof(Nemo)), ".."))
nemovdir = "$nemodir/deps/usr"
Expand Down Expand Up @@ -202,11 +201,46 @@ end

push!(Libdl.DL_LOAD_PATH, joinpath(prefixpath, "lib"))

cd(oldwdir)

@show libcxxwrap_prefix = CxxWrap.prefix_path()
@show julia_exec = joinpath(Sys.BINDIR, "julia")

extra_cppflags = ""

if Sys.isapple()
# Work around a bug in Xcode 11.4 that causes SIGABRT, at least until
# https://github.com/llvm/llvm-project/commit/2464d8135e
# arrives.
#
# We build a jlcxx library that uses std::string which will
# abort with a failed assertion has_julia_type<T> if we are building
# with xcode 11.4 but libcxxwrap-julia was built with an older libc++.
#
# Read the above LLVM commit message for some details; the effect of merged
# vs non-merged type_info is that for the former memory addresses are
# used as hash_code(), for the latter the type_info.name() string is
# hashed.

xcodetypeinfo_build_path = joinpath(@__DIR__, "xcodetypeinfo", "build")
rm(xcodetypeinfo_build_path, recursive = true, force = true)
mkpath(xcodetypeinfo_build_path)
cd(xcodetypeinfo_build_path)
run(`$(CMake.cmake)
-DJulia_EXECUTABLE=$julia_exec
-DCMAKE_PREFIX_PATH=$libcxxwrap_prefix
..`)
run(`$(CMake.cmake) --build .`)
libpath = joinpath(xcodetypeinfo_build_path, "libhello.$(Libdl.dlext)")
res = run(pipeline(Cmd(`$(Base.julia_cmd()) --project
-e "using CxxWrap; @wrapmodule(\"$libpath\", :define_module_hello); @initcxx;"`,
ignorestatus = true),
stdout=devnull,
stderr=devnull))
if res.termsignal == 6
println("Applying Xcode type_info.hash_code() workaround")
global extra_cppflags *= " -DFORCE_XCODE_TYPEINFO_MERGED"
end
end

cmake_src_path = joinpath(@__DIR__, "src")
cmake_build_path = joinpath(@__DIR__, "build")

Expand All @@ -218,6 +252,7 @@ println("Initializing cmake")
run(`$(CMake.cmake)
-DJulia_EXECUTABLE=$julia_exec
-DCMAKE_PREFIX_PATH=$libcxxwrap_prefix
-Dextra_cppflags=$extra_cppflags
-Dsingular_includes=$prefixpath/include
-Dsingular_libdir=$prefixpath/lib
-DCMAKE_INSTALL_LIBDIR=$prefixpath/lib
Expand Down
2 changes: 1 addition & 1 deletion deps/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ message(STATUS "Found JlCxx at ${JlCxx_location}")
include_directories(${singular_includes})
include_directories(${singular_includes}/singular)

SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g" )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g ${extra_cppflags}" )
SET( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${singular_libdir} -Wl,-rpath,${singular_libdir}" )


Expand Down
4 changes: 0 additions & 4 deletions deps/src/coeff_rings.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "jlcxx/jlcxx.hpp"
#include "includes.h"
#include "coeff_rings.h"

#include <iostream>

typedef struct __singular_coeff_ring_struct {
int64_t has_simple_alloc;
int64_t has_simple_Inverse;
Expand Down
2 changes: 2 additions & 0 deletions deps/src/coeff_rings.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef COEFF_RINGS_INCLUDE
#define COEFF_RINGS_INCLUDE

#include "includes.h"

void singular_define_coeff_rings(jlcxx::Module &);

#endif
2 changes: 2 additions & 0 deletions deps/src/includes.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef MAIN_INCLUDE_FILE
#define MAIN_INCLUDE_FILE

#include "xcode_jlcxx_workaround.h"

#include <string>
#include <cstring>
#include <iostream>
Expand Down
1 change: 0 additions & 1 deletion deps/src/singular.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "jlcxx/jlcxx.hpp"
#include "includes.h"
#include "coeffs.h"
#include "rings.h"
Expand Down
2 changes: 2 additions & 0 deletions deps/src/threading.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "xcode_jlcxx_workaround.h"

#include <mutex>

#ifdef THREADSAFE_SINGULAR
Expand Down
29 changes: 29 additions & 0 deletions deps/src/xcode_jlcxx_workaround.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef XCODE_JLCXX_WORKAROUND
#define XCODE_JLCXX_WORKAROUND

// This must be the very first include
#ifdef _LIBCPP_CONFIG
#error This header must be included before any system headers!
#endif

// Work around Xcode 11.4 issue until upstream libc++ fix arrives in Xcode:
// https://github.com/llvm/llvm-project/commit/2464d8135e
//
// First include __config from libc++, then override typeinfo flag
// to force use of address as hash instead of hashing the string.

#if defined(__APPLE__) && defined(FORCE_XCODE_TYPEINFO_MERGED)
#include <__config>
#if defined(_LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT) && \
_LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT == 0
#undef _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT
#define _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT 1
#else
#error Trying to work around Xcode 11.4 bug but libc++ macro not set as expected! \
Please try rebuilding and create an issue if this reappears.
#endif
#endif

#include "jlcxx/jlcxx.hpp"

#endif
12 changes: 12 additions & 0 deletions deps/xcodetypeinfo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
project(xcodetypeinfo)

cmake_minimum_required(VERSION 3.01)

find_package(JlCxx REQUIRED)

get_target_property(JlCxx_location JlCxx::cxxwrap_julia LOCATION)
get_filename_component(JlCxx_location ${JlCxx_location} DIRECTORY)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${JlCxx_location}")

add_library(hello SHARED hello.cpp)
target_link_libraries(hello JlCxx::cxxwrap_julia)
14 changes: 14 additions & 0 deletions deps/xcodetypeinfo/hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <string>
#include <vector>

#include "jlcxx/jlcxx.hpp"

std::string greet(const std::string& str)
{
return "hello, world";
}

JLCXX_MODULE define_module_hello(jlcxx::Module& mod)
{
mod.method("greet", &greet);
}

2 comments on commit 5cf4afb

@fingolfin
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/13966

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.1 -m "<description of version>" 5cf4afbb4bf8f52c354a35a3cd1dca4609539df6
git push origin v0.3.1

Please sign in to comment.