Skip to content

Commit

Permalink
Set MacOS platform version in one place
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 committed Oct 30, 2023
1 parent 97680c4 commit 8bd01f8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
2 changes: 2 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
3 changes: 2 additions & 1 deletion src/libponyc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ 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})
target_compile_definitions(libponyc PUBLIC PONY_OSX_PLATFORM=${PONY_OSX_PLATFORM})
endif()

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

#define STRINGIFY(x) #x

struct compile_local_t
{
const char* name;
Expand Down Expand Up @@ -819,9 +821,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"
STRINGIFY(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"
STRINGIFY(PONY_OSX_PLATFORM));
#else
triple = LLVMGetDefaultTargetTriple();
#endif
Expand Down
4 changes: 3 additions & 1 deletion src/libponyc/codegen/genexe.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# include <unistd.h>
#endif

#define STRINGIFY(x) #x

static LLVMValueRef create_main(compile_t* c, reach_type_t* t,
LLVMValueRef ctx)
{
Expand Down Expand Up @@ -295,7 +297,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 '" STRINGIFY(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 8bd01f8

Please sign in to comment.