Skip to content

Commit

Permalink
Ship XQuartz libraries (#5346)
Browse files Browse the repository at this point in the history
  • Loading branch information
boutinb authored Dec 12, 2023
1 parent 8dfb344 commit f7fbf2b
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 14 deletions.
5 changes: 3 additions & 2 deletions Engine/otoolstuff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void _moduleLibraryFixer(const std::string & moduleLibraryPath, bool engineCall,
auto otoolLines = stringUtils::splitString(otoolOut, '\n');

std::string libName = path.stem().string() + path.extension().string();

for(size_t i = 1; i < otoolLines.size(); i++)
{
std::string line = otoolLines[i];
Expand All @@ -113,7 +113,8 @@ void _moduleLibraryFixer(const std::string & moduleLibraryPath, bool engineCall,
{"/usr/local/lib/libjrmath", framework_resources + "opt/jags/lib/libjrmath"},
{"/usr/local/lib", framework_resources + "opt/local/lib"},
{"/opt/gfortran/lib/gcc/x86_64-apple-darwin20.0/12.2.0", framework_resources + "lib"},
{"/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0", framework_resources + "opt/R/arm64/gfortran/lib"},
{"/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0", framework_resources + "opt/R/arm64/gfortran/lib"},
{"/opt/X11/lib", framework_resources + "opt/X11/lib"},
};

// Known fix library id's and paths
Expand Down
98 changes: 98 additions & 0 deletions Tools/CMake/Patch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,94 @@ else()
# Later on, after we are sure that everything works as expected, we can
# make it nicer.

if((FILE MATCHES "R_X11.so")
OR (FILE MATCHES "R_de.so")
OR (FILE MATCHES "opt/X11")
OR (FILE MATCHES "grDevices"))
execute_process(
# COMMAND_ECHO STDOUT
ERROR_QUIET OUTPUT_QUIET
WORKING_DIRECTORY ${PATH}
COMMAND
install_name_tool -change "/opt/X11/lib/libSM.6.dylib"
"${FRAMEWORK_RESOURCES}/opt/X11/lib/libSM.6.dylib"
"${FILE}")

execute_process(
# COMMAND_ECHO STDOUT
ERROR_QUIET OUTPUT_QUIET
WORKING_DIRECTORY ${PATH}
COMMAND
install_name_tool -change "/opt/X11/lib/libICE.6.dylib"
"${FRAMEWORK_RESOURCES}/opt/X11/lib/libICE.6.dylib"
"${FILE}")

execute_process(
# COMMAND_ECHO STDOUT
ERROR_QUIET OUTPUT_QUIET
WORKING_DIRECTORY ${PATH}
COMMAND
install_name_tool -change "/opt/X11/lib/libX11.6.dylib"
"${FRAMEWORK_RESOURCES}/opt/X11/lib/libX11.6.dylib"
"${FILE}")

execute_process(
# COMMAND_ECHO STDOUT
ERROR_QUIET OUTPUT_QUIET
WORKING_DIRECTORY ${PATH}
COMMAND
install_name_tool -change "/opt/X11/lib/libXext.6.dylib"
"${FRAMEWORK_RESOURCES}/opt/X11/lib/libXext.6.dylib"
"${FILE}")

execute_process(
# COMMAND_ECHO STDOUT
ERROR_QUIET OUTPUT_QUIET
WORKING_DIRECTORY ${PATH}
COMMAND
install_name_tool -change "/opt/X11/lib/libXrender.1.dylib"
"${FRAMEWORK_RESOURCES}/opt/X11/lib/libXrender.1.dylib"
"${FILE}")

execute_process(
# COMMAND_ECHO STDOUT
ERROR_QUIET OUTPUT_QUIET
WORKING_DIRECTORY ${PATH}
COMMAND
install_name_tool -change "/opt/X11/lib/libXt.6.dylib"
"${FRAMEWORK_RESOURCES}/opt/X11/lib/libXt.6.dylib"
"${FILE}")

execute_process(
# COMMAND_ECHO STDOUT
ERROR_QUIET OUTPUT_QUIET
WORKING_DIRECTORY ${PATH}
COMMAND
install_name_tool -change "/opt/X11/lib/libXmu.6.dylib"
"${FRAMEWORK_RESOURCES}/opt/X11/lib/libXmu.6.dylib"
"${FILE}")

execute_process(
# COMMAND_ECHO STDOUT
ERROR_QUIET OUTPUT_QUIET
WORKING_DIRECTORY ${PATH}
COMMAND
install_name_tool -change "/opt/X11/lib/libXau.6.dylib"
"${FRAMEWORK_RESOURCES}/opt/X11/lib/libXau.6.dylib"
"${FILE}")

execute_process(
# COMMAND_ECHO STDOUT
ERROR_QUIET OUTPUT_QUIET
WORKING_DIRECTORY ${PATH}
COMMAND
install_name_tool -change "/opt/X11/lib/libxcb.1.dylib"
"${FRAMEWORK_RESOURCES}/opt/X11/lib/libxcb.1.dylib"
"${FILE}")

endif()


if((FILE MATCHES "prophet.so")
OR (FILE MATCHES "metaBMA.so")
OR (FILE MATCHES "rstanarm.so")
Expand Down Expand Up @@ -132,6 +220,7 @@ else()
NEW_ID
${FILE})


elseif(FILE MATCHES "/opt/R/arm64/gfortran/lib/")

string(
Expand Down Expand Up @@ -185,6 +274,15 @@ else()
NEW_ID
${FILE})

elseif(FILE MATCHES "/opt/X11/")

string(
REPLACE
"${R_HOME_PATH}/opt/X11/"
"${FRAMEWORK_RESOURCES}/opt/X11/"
NEW_ID
${FILE})

elseif(FILE MATCHES "/opt/jags/")

string(
Expand Down
71 changes: 59 additions & 12 deletions Tools/CMake/R.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,30 @@
#

set(JASP_STATIC_IS_DOWN_AGAIN OFF CACHE BOOL "Turn ON to try to get R from CRAN instead")
set(STATIC_DEVELOPMENT_REPOSITORY "https://static.jasp-stats.org/development/")

if(APPLE)
set(XQUARTZ_VERSION "2.8.5")
endif()

if(NOT JASP_STATIC_IS_DOWN_AGAIN)
set(R_BINARY_REPOSITORY "https://static.jasp-stats.org/development/")
set(R_BINARY_REPOSITORY "${STATIC_DEVELOPMENT_REPOSITORY}")
set(XQUARTZ_REPOSITORY "${STATIC_DEVELOPMENT_REPOSITORY}")
set(GFORTRAN_REPOSITORY "${STATIC_DEVELOPMENT_REPOSITORY}")
else()
if(APPLE)
if(CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
set(R_BINARY_REPOSITORY "https://cran.r-project.org/bin/macosx/big-sur-arm64/base/")
else()
set(R_BINARY_REPOSITORY "https://cran.r-project.org/bin/macosx/big-sur-x86_64/base/")
endif()
elseif(WINDOWS)
set(R_BINARY_REPOSITORY "https://cran.r-project.org/bin/macosx/windows/base/")
endif()
# TODO: GFORTRAN_REPOSITORY should be set somewhere else...
set(GFORTRAN_REPOSITORY "${STATIC_DEVELOPMENT_REPOSITORY}")

if(APPLE)
if(CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
set(R_BINARY_REPOSITORY "https://cran.r-project.org/bin/macosx/big-sur-arm64/base/")
else()
set(R_BINARY_REPOSITORY "https://cran.r-project.org/bin/macosx/big-sur-x86_64/base/")
endif()
set(XQUARTZ_REPOSITORY "https://github.com/XQuartz/XQuartz/releases/download/XQuartz-${XQUARTZ_VERSION}/")
elseif(WINDOWS)
set(R_BINARY_REPOSITORY "https://cran.r-project.org/bin/macosx/windows/base/")
endif()
endif()


Expand Down Expand Up @@ -183,6 +194,8 @@ if(APPLE)
if(INSTALL_R_FRAMEWORK AND (NOT EXISTS
${CMAKE_BINARY_DIR}/Frameworks/R.framework))

set(XQUARTZ_URL "${XQUARTZ_REPOSITORY}XQuartz-${XQUARTZ_VERSION}.pkg")

if(CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")

set(R_VERSION_NAME "R-${R_VERSION}-${CMAKE_OSX_ARCHITECTURES}")
Expand Down Expand Up @@ -260,7 +273,7 @@ if(APPLE)

fetchcontent_declare(
gfortran_tar_gz
URL "https://static.jasp-stats.org/development/gfortran-12.0.1-20220312-is-darwin20-arm64.tar.xz"
URL "${GFORTRAN_REPOSITORY}gfortran-12.0.1-20220312-is-darwin20-arm64.tar.xz"
URL_HASH
SHA256=a2ab8be30a7d92a24f53e1509c8c0804f8502f0bc35469750e3f1e233d1c64b8
DOWNLOAD_NO_EXTRACT ON
Expand Down Expand Up @@ -302,7 +315,7 @@ if(APPLE)
# @todo, it's probably a good idea to unpack this and provide a tar.gz like the other version
fetchcontent_declare(
gfortran_dmg
URL "https://static.jasp-stats.org/development/gfortran-8.2-Mojave.dmg"
URL "${GFORTRAN_REPOSITORY}gfortran-8.2-Mojave.dmg"
URL_HASH
SHA256=81d379231ba5671a5ef1b7832531f53be5a1c651701a61d87e1d877c4f06d369
DOWNLOAD_NO_EXTRACT ON
Expand Down Expand Up @@ -359,6 +372,40 @@ if(APPLE)
message(CHECK_FAIL "failed.")
endif()

fetchcontent_declare(
xquartz_pkg
URL ${XQUARTZ_URL}
URL_HASH
SHA256=e89538a134738dfa71d5b80f8e4658cb812e0803115a760629380b851b608782
DOWNLOAD_NO_EXTRACT ON
DOWNLOAD_NAME XQuartz.pkg)

message(CHECK_START "Downloading XQuartz.pkg")

fetchcontent_makeavailable(xquartz_pkg)

if(xquartz_pkg_POPULATED)
message(CHECK_START "Unpacking XQuartz.pkg")
execute_process(WORKING_DIRECTORY ${xquartz_pkg_SOURCE_DIR}
COMMAND xar -xf XQuartz.pkg)
message(CHECK_PASS "done.")

message(CHECK_START "Unpacking XQuartzComponent.pkg/Payload")
execute_process(WORKING_DIRECTORY ${xquartz_pkg_SOURCE_DIR}
COMMAND tar -xf XQuartzComponent.pkg/Payload)
message(CHECK_PASS "done.")

set(XQUARTZ_LIB ${CMAKE_BINARY_DIR}/Frameworks/R.framework/Resources/opt/X11/lib)
make_directory(${XQUARTZ_LIB})
execute_process(
WORKING_DIRECTORY ${xquartz_pkg_SOURCE_DIR}
COMMAND sh -c "cp -pf opt/X11/lib/{libSM.6.dylib,libICE.6.dylib,libX11.6.dylib,libXext.6.dylib,libXrender.1.dylib,libXt.6.dylib,libXmu.6.dylib,libxcb.1.dylib,libXau.6.dylib} ${XQUARTZ_LIB}")

message(CHECK_PASS "done.")
else()
message(CHECK_FAIL "failed.")
endif()

message(CHECK_START "Locating the 'gfortran'")

find_program(
Expand Down

0 comments on commit f7fbf2b

Please sign in to comment.