Skip to content

Commit 8b32c61

Browse files
committed
Add support for M1 Mac
* wref to issue #13 * We do this with the help of inbuilt arch command "Rosetta 2", For now Rosetta is here to stay * and we can make use of it's capabilities to compile x86 instructions on arm machine
1 parent 5ccb436 commit 8b32c61

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ CC = gcc
22
RACKET = racket
33
RM = rm
44

5+
UNAME_S := $(shell uname -s)
6+
UNAME_P := $(shell uname -p)
7+
ifeq ($(UNAME_S),Darwin)
8+
ifeq ($(UNAME_P),arm)
9+
$(info M1 MacOSX detected)
10+
CC := arch -x86_64 $(CC)
11+
endif
12+
endif
13+
514
runtime.o: runtime.c runtime.h
615
$(CC) -c -g -std=c99 runtime.c
716

utilities.rkt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2244,6 +2244,14 @@ Changelog:
22442244
(close-output-port out)
22452245
result)]))
22462246

2247+
(define (get-arch)
2248+
(match (system-type 'arch)
2249+
[ 'aarch64
2250+
(match (system-type 'os)
2251+
[ 'macosx "arch -x86_64 "]
2252+
[ else "" ])
2253+
[ else "" ]))
2254+
22472255
(define (compiler-tests-suite name typechecker passes test-family test-nums)
22482256
(let ([compiler (compile-file typechecker passes)])
22492257
(make-test-suite
@@ -2258,7 +2266,7 @@ Changelog:
22582266
(test-case "typecheck" (check-false typechecks "Expected expression to fail typechecking"))
22592267
(if (not typechecks) (fail "Expected expression to typecheck")
22602268
(test-case "code generation"
2261-
(let ([gcc-output (system (format "gcc -g -march=x86-64 -std=c99 runtime.o ./tests/~a.s -o ./tests/~a.out" test-name test-name))])
2269+
(let ([gcc-output (system (format (string-append (get-arch) "gcc -g -std=c99 runtime.o ./tests/~a.s -o ./tests/~a.out") test-name test-name))])
22622270
(if (not gcc-output) (fail "Failed during assembly")
22632271
(let ([input (if (file-exists? (format "./tests/~a.in" test-name))
22642272
(format " < ./tests/~a.in" test-name)

0 commit comments

Comments
 (0)