Skip to content

Commit 0ee055c

Browse files
committed
Use classic linker w/ Xcode 15.0
See crystal-lang/crystal#13846 Unclear right now on if this is Crystal issue, LLVM issue, or something else
1 parent 2e62f37 commit 0ee055c

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

Makefile

+12-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ SHELL := bash
55
.DELETE_ON_ERROR:
66
.SUFFIXES:
77

8+
CRFLAGS ?=
89
CRYSTAL ?= $(shell which crystal)
910
SHARDS ?= $(shell which shards)
1011
MESON ?= $(shell which meson)
@@ -35,6 +36,15 @@ MESON_FLAGS ?= \
3536
$(if $(RELEASE),--buildtype=release --strip,--buildtype=debug) \
3637
$(if $(STATIC),--default-library=static,--default-library=shared)
3738

39+
ifeq ($(shell command -v xcodebuild > /dev/null && echo true),true)
40+
XCODE_VERSION := $(shell xcodebuild -version | awk '/Xcode/ {print $$2}' | tr -d '')
41+
42+
# Use legacy linker with xcode 15 for now
43+
ifeq ($(XCODE_VERSION),15.0)
44+
override CRFLAGS += --link-flags=-Wl,-ld_classic
45+
endif
46+
endif
47+
3848
# Add cross-files if target and host are different
3949
ifeq ($(shell [[ "$(TARGET_OS)" != "$(HOST_OS)" || "$(TARGET_ARCH)" != "$(HOST_ARCH)" || ! -z "$(TARGET_CABI)" ]] && echo true),true)
4050
override MESON_FLAGS += --cross-file=$(TARGET_CROSS_FILE)
@@ -99,7 +109,7 @@ format:
99109
$(CRYSTAL) tool format
100110

101111
lint: deps
102-
$(CRYSTAL) bin/ameba.cr
112+
$(CRYSTAL) run $(CRFLAGS) bin/ameba.cr
103113

104114
.PHONY: clean
105115
clean:
@@ -111,7 +121,7 @@ clean:
111121
.PHONY: spec
112122
spec: deps $(SOURCES)
113123
$(CRYSTAL) tool format --check
114-
$(CRYSTAL) spec -Dmt_no_expectations --error-trace
124+
$(CRYSTAL) spec $(CRFLAGS) -Dmt_no_expectations --error-trace
115125

116126
.PHONY: check-libraries
117127
check-libraries: bin/mstrap

meson.build

+15-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ project('mstrap',
99
]
1010
)
1111

12+
cc = meson.get_compiler('c')
1213
target_arch = host_machine.cpu_family()
1314
target_system = host_machine.system()
1415
target_triple = target_arch + '-unknown-' + target_system
@@ -17,6 +18,7 @@ buildtype = get_option('buildtype')
1718
is_darwin = target_system == 'darwin'
1819
is_static = get_option('default_library') == 'static'
1920
is_static_libc = false
21+
needs_macos_classic_linker = false
2022

2123
if target_system == 'linux'
2224
target_cabi = meson.get_external_property('target_triple_suffix', 'gnu')
@@ -34,9 +36,17 @@ elif target_system == 'darwin'
3436
target_triple = macos_arch + '-apple-macos' + macos_abi
3537
add_global_arguments('-target', target_triple, language : 'c', native : false)
3638
add_global_link_arguments('-target', target_triple, language : 'c', native : false)
39+
40+
# Use legacy linker with xcode 15+
41+
xcode_version_output = run_command(find_program('xcodebuild'), '-version', check : true).stdout()
42+
xcode_version = xcode_version_output.split('\n').get(0, '').replace('Xcode', '').strip()
43+
44+
if xcode_version.version_compare('>=15.0') and cc.has_link_argument('-Wl,-ld_classic')
45+
needs_macos_classic_linker = true
46+
add_global_link_arguments('-Wl,-ld_classic', language : 'c')
47+
endif
3748
endif
3849

39-
cc = meson.get_compiler('c')
4050
crystal = find_program(get_option('crystal'), required : true)
4151
shards = find_program(get_option('shards'), required : true)
4252

@@ -157,6 +167,10 @@ if is_static_libc
157167
crystal_build_flags += ['--static']
158168
endif
159169

170+
if needs_macos_classic_linker
171+
crystal_build_flags += ['--link-flags=-Wl,-ld_classic']
172+
endif
173+
160174
mstrap_build_cmd = [crystal, 'build'] + crystal_build_flags + ['-o', 'mstrap', '@INPUT@']
161175

162176
mstrap_o = custom_target(

0 commit comments

Comments
 (0)