Skip to content

Commit 53a2937

Browse files
committed
fix(carpntr,hammer): on apple silicon force target to be aarch64-macos-gnu instead of native
1 parent 697a002 commit 53a2937

File tree

5 files changed

+30254
-30097
lines changed

5 files changed

+30254
-30097
lines changed

compiler/carpntr/build/program_code.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ void yy__building_build_objects_sequential(struct yy__building_BObject**);
105105
void yy__building_build_objects(struct yy__building_BObject**);
106106
void yy__building_cleanup_buildables(struct yy__building_BObject**);
107107
bool yy__building_keep_ray_objects(yk__sds, bool);
108+
bool yy__building_is_arm64_cpu();
108109
yk__sds* yy__building_create_args(struct yy__configuration_Config*, yk__sds, yk__sds, yk__sds, yk__sds*);
109110
void yy__building_print_target_eq(yk__sds, bool);
110111
int32_t yy__building_build_target(struct yy__configuration_Config*, yk__sds, yk__sds, yk__sds, yk__sds*, bool);
@@ -1245,6 +1246,16 @@ bool yy__building_keep_ray_objects(yk__sds yy__building_element, bool yy__buildi
12451246
yk__sdsfree(yy__building_element);
12461247
return t__25;
12471248
}
1249+
bool yy__building_is_arm64_cpu()
1250+
{
1251+
1252+
#if defined(__arm64__) || defined(__aarch64__) || defined(__arm64)
1253+
return true;
1254+
#else
1255+
return false;
1256+
#endif
1257+
;
1258+
}
12481259
yk__sds* yy__building_create_args(struct yy__configuration_Config* yy__building_c, yk__sds yy__building_code_path, yk__sds yy__building_build_path, yk__sds yy__building_target, yk__sds* yy__building_raylib_args)
12491260
{
12501261
bool yy__building_native = (yk__sdslen(yy__building_target) == INT32_C(0));
@@ -1412,6 +1423,11 @@ yk__sds* yy__building_create_args(struct yy__configuration_Config* yy__building_
14121423
yk__arrput(yy__building_args, yk__sdsnewlen("-target", 7));
14131424
yk__arrput(yy__building_args, yk__sdsnewlen("wasm32-wasi-musl", 16));
14141425
}
1426+
if ((yy__building_native && yy__building_is_arm64_cpu()) && yy__building_is_target_macos(yk__sdsdup(yy__building_target)))
1427+
{
1428+
yk__arrput(yy__building_args, yk__sdsnewlen("-target", 7));
1429+
yk__arrput(yy__building_args, yk__sdsnewlen("aarch64-macos-gnu", 17));
1430+
}
14151431
yy__building_length = yk__arrlen(yy__building_c->yy__configuration_c_code->yy__configuration_runtime_feature_c_code);
14161432
yy__building_x = INT32_C(0);
14171433
while (true)

compiler/carpntr/building.yaka

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,17 @@ def keep_ray_objects(element: str, negate: bool) -> bool:
231231
return not obj
232232
return obj
233233

234+
@native
235+
def is_arm64_cpu() -> bool:
236+
# way to detect if we are running m1/m2/etc macos
237+
ccode """
238+
#if defined(__arm64__) || defined(__aarch64__) || defined(__arm64)
239+
return true;
240+
#else
241+
return false;
242+
#endif
243+
"""
244+
234245
def create_args(c: carp.Config, code_path: str, build_path: str, target: str, raylib_args: Array[str]) -> Array[str]:
235246
# Create arguments for compilation on to a string array
236247
# This string array need to be deleted
@@ -291,6 +302,10 @@ def create_args(c: carp.Config, code_path: str, build_path: str, target: str, ra
291302
if target == "wasm4":
292303
arrput(args, "-target")
293304
arrput(args, "wasm32-wasi-musl")
305+
# m1/m2/etc must not build for native, instead build for "aarch64-macos-gnu"
306+
if native and is_arm64_cpu() and is_target_macos(target):
307+
arrput(args, "-target")
308+
arrput(args, "aarch64-macos-gnu")
294309
# runtime c codes
295310
length = len(c.c_code.runtime_feature_c_code)
296311
x = 0

compiler/hammer/main.yaka

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ def is_target_macos(target_to_check: str) -> bool:
9595
return os.is_macos()
9696
return strings.contains(target_to_check, "macos")
9797

98+
@native
99+
def is_arm64_cpu() -> bool:
100+
# way to detect if we are running m1/m2/etc macos
101+
ccode """
102+
#if defined(__arm64__) || defined(__aarch64__) || defined(__arm64)
103+
return true;
104+
#else
105+
return false;
106+
#endif
107+
"""
108+
98109
def is_target_windows(target_to_check: str) -> bool:
99110
# Check if given target is windows, if target == native, check if we are running windows
100111
native: bool = target_to_check == "native"
@@ -120,6 +131,10 @@ def get_base_args(c: conf.HammerConfig, target: str, cpp: bool) -> Array[str]:
120131
if not (target == "native"):
121132
arrput(args, "-target")
122133
arrput(args, target)
134+
# m1/m2/etc must not build for native, instead build for "aarch64-macos-gnu"
135+
if target == "native" and is_arm64_cpu() and is_target_macos(target):
136+
arrput(args, "-target")
137+
arrput(args, "aarch64-macos-gnu")
123138
args = sarr.extend(args, c.args_c_or_cpp)
124139
if cpp:
125140
args = sarr.extend(args, c.args_cpp)

0 commit comments

Comments
 (0)