Skip to content

Commit

Permalink
Set MacOS platform version in one place (#4471)
Browse files Browse the repository at this point in the history
This PR specifies the MacOS platform version (currently "13.0.0") in only one place, and uses CMake variables and C/C++ defines to set it appropriately.
  • Loading branch information
chalcolith authored Oct 31, 2023
1 parent 97680c4 commit ffc2dc0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ if(NOT MSVC)
endif()
endif()

set(PONY_OSX_PLATFORM 13.0.0)

# LLVM component setup
if(NOT PONY_CROSS_LIBPONYRT)
set(LLVM_COMPONENTS
Expand Down Expand Up @@ -225,6 +227,7 @@ add_compile_definitions(
$<$<CONFIG:Release>:PONY_VERSION_STR="${PONYC_VERSION} [release]\\nCompiled with: LLVM ${LLVM_VERSION} -- ${CMAKE_C_COMPILER_ID}-${CMAKE_C_COMPILER_VERSION}-${_compiler_arch}">
$<$<CONFIG:RelWithDebInfo>:PONY_VERSION_STR="${PONYC_VERSION} [relwithdebinfo]\\nCompiled with: LLVM ${LLVM_VERSION} -- ${CMAKE_C_COMPILER_ID}-${CMAKE_C_COMPILER_VERSION}-${_compiler_arch}">
$<$<CONFIG:MinSizeRel>:PONY_VERSION_STR="${PONYC_VERSION} [minsizerel]\\nCompiled with: LLVM ${LLVM_VERSION} -- ${CMAKE_C_COMPILER_ID}-${CMAKE_C_COMPILER_VERSION}-${_compiler_arch}">
PONY_OSX_PLATFORM=${PONY_OSX_PLATFORM}
)

include(CheckIPOSupported)
Expand Down
2 changes: 1 addition & 1 deletion src/libponyc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ target_include_directories(libponyc
)

if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_OSX_DEPLOYMENT_TARGET 13.0.0)
set(CMAKE_OSX_DEPLOYMENT_TARGET ${PONY_OSX_PLATFORM})
endif()

if (MSVC)
Expand Down
9 changes: 7 additions & 2 deletions src/libponyc/codegen/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include <llvm-c/Support.h>
#include <string.h>

#define STR(x) STR2(x)
#define STR2(x) #x

struct compile_local_t
{
const char* name;
Expand Down Expand Up @@ -819,9 +822,11 @@ bool codegen_pass_init(pass_opt_t* opt)
triple = LLVMCreateMessage(opt->triple);
} else {
#if defined(PLATFORM_IS_MACOSX) && defined(PLATFORM_IS_ARM)
triple = LLVMCreateMessage("arm64-apple-macosx13.0.0");
triple = LLVMCreateMessage("arm64-apple-macosx"
STR(PONY_OSX_PLATFORM));
#elif defined(PLATFORM_IS_MACOSX) && !defined(PLATFORM_IS_ARM)
triple = LLVMCreateMessage("x86_64-apple-macosx13.0.0");
triple = LLVMCreateMessage("x86_64-apple-macosx"
STR(PONY_OSX_PLATFORM));
#else
triple = LLVMGetDefaultTargetTriple();
#endif
Expand Down
5 changes: 4 additions & 1 deletion src/libponyc/codegen/genexe.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
# include <unistd.h>
#endif

#define STR(x) STR2(x)
#define STR2(x) #x

static LLVMValueRef create_main(compile_t* c, reach_type_t* t,
LLVMValueRef ctx)
{
Expand Down Expand Up @@ -295,7 +298,7 @@ static bool link_exe(compile_t* c, ast_t* program,
snprintf(ld_cmd, ld_len,
"%s -execute -arch %.*s "
"-o %s %s %s %s "
"-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -lSystem %s -platform_version macos '13.0.0' '0.0.0'",
"-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -lSystem %s -platform_version macos '" STR(PONY_OSX_PLATFORM) "' '0.0.0'",
linker, (int)arch_len, c->opt->triple, file_exe, file_o,
lib_args, ponyrt, sanitizer_arg
);
Expand Down
2 changes: 1 addition & 1 deletion src/libponyrt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ find_file(_llc_command
)

if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_OSX_DEPLOYMENT_TARGET 13.0.0)
set(CMAKE_OSX_DEPLOYMENT_TARGET ${PONY_OSX_PLATFORM})
endif()

add_library(libponyrt STATIC
Expand Down

0 comments on commit ffc2dc0

Please sign in to comment.