Skip to content

Commit

Permalink
fix(carpntr,hammer): on apple silicon force target to be aarch64-maco…
Browse files Browse the repository at this point in the history
…s-gnu instead of native
  • Loading branch information
JaDogg committed Dec 18, 2023
1 parent 697a002 commit 53a2937
Show file tree
Hide file tree
Showing 5 changed files with 30,254 additions and 30,097 deletions.
16 changes: 16 additions & 0 deletions compiler/carpntr/build/program_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ void yy__building_build_objects_sequential(struct yy__building_BObject**);
void yy__building_build_objects(struct yy__building_BObject**);
void yy__building_cleanup_buildables(struct yy__building_BObject**);
bool yy__building_keep_ray_objects(yk__sds, bool);
bool yy__building_is_arm64_cpu();
yk__sds* yy__building_create_args(struct yy__configuration_Config*, yk__sds, yk__sds, yk__sds, yk__sds*);
void yy__building_print_target_eq(yk__sds, bool);
int32_t yy__building_build_target(struct yy__configuration_Config*, yk__sds, yk__sds, yk__sds, yk__sds*, bool);
Expand Down Expand Up @@ -1245,6 +1246,16 @@ bool yy__building_keep_ray_objects(yk__sds yy__building_element, bool yy__buildi
yk__sdsfree(yy__building_element);
return t__25;
}
bool yy__building_is_arm64_cpu()
{

#if defined(__arm64__) || defined(__aarch64__) || defined(__arm64)
return true;
#else
return false;
#endif
;
}
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)
{
bool yy__building_native = (yk__sdslen(yy__building_target) == INT32_C(0));
Expand Down Expand Up @@ -1412,6 +1423,11 @@ yk__sds* yy__building_create_args(struct yy__configuration_Config* yy__building_
yk__arrput(yy__building_args, yk__sdsnewlen("-target", 7));
yk__arrput(yy__building_args, yk__sdsnewlen("wasm32-wasi-musl", 16));
}
if ((yy__building_native && yy__building_is_arm64_cpu()) && yy__building_is_target_macos(yk__sdsdup(yy__building_target)))
{
yk__arrput(yy__building_args, yk__sdsnewlen("-target", 7));
yk__arrput(yy__building_args, yk__sdsnewlen("aarch64-macos-gnu", 17));
}
yy__building_length = yk__arrlen(yy__building_c->yy__configuration_c_code->yy__configuration_runtime_feature_c_code);
yy__building_x = INT32_C(0);
while (true)
Expand Down
15 changes: 15 additions & 0 deletions compiler/carpntr/building.yaka
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ def keep_ray_objects(element: str, negate: bool) -> bool:
return not obj
return obj

@native
def is_arm64_cpu() -> bool:
# way to detect if we are running m1/m2/etc macos
ccode """
#if defined(__arm64__) || defined(__aarch64__) || defined(__arm64)
return true;
#else
return false;
#endif
"""

def create_args(c: carp.Config, code_path: str, build_path: str, target: str, raylib_args: Array[str]) -> Array[str]:
# Create arguments for compilation on to a string array
# This string array need to be deleted
Expand Down Expand Up @@ -291,6 +302,10 @@ def create_args(c: carp.Config, code_path: str, build_path: str, target: str, ra
if target == "wasm4":
arrput(args, "-target")
arrput(args, "wasm32-wasi-musl")
# m1/m2/etc must not build for native, instead build for "aarch64-macos-gnu"
if native and is_arm64_cpu() and is_target_macos(target):
arrput(args, "-target")
arrput(args, "aarch64-macos-gnu")
# runtime c codes
length = len(c.c_code.runtime_feature_c_code)
x = 0
Expand Down
15 changes: 15 additions & 0 deletions compiler/hammer/main.yaka
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ def is_target_macos(target_to_check: str) -> bool:
return os.is_macos()
return strings.contains(target_to_check, "macos")

@native
def is_arm64_cpu() -> bool:
# way to detect if we are running m1/m2/etc macos
ccode """
#if defined(__arm64__) || defined(__aarch64__) || defined(__arm64)
return true;
#else
return false;
#endif
"""

def is_target_windows(target_to_check: str) -> bool:
# Check if given target is windows, if target == native, check if we are running windows
native: bool = target_to_check == "native"
Expand All @@ -120,6 +131,10 @@ def get_base_args(c: conf.HammerConfig, target: str, cpp: bool) -> Array[str]:
if not (target == "native"):
arrput(args, "-target")
arrput(args, target)
# m1/m2/etc must not build for native, instead build for "aarch64-macos-gnu"
if target == "native" and is_arm64_cpu() and is_target_macos(target):
arrput(args, "-target")
arrput(args, "aarch64-macos-gnu")
args = sarr.extend(args, c.args_c_or_cpp)
if cpp:
args = sarr.extend(args, c.args_cpp)
Expand Down
Loading

0 comments on commit 53a2937

Please sign in to comment.