diff --git a/pkgs/racket-lib/info.rkt b/pkgs/racket-lib/info.rkt index 9a9c71b08c..151d7069ae 100644 --- a/pkgs/racket-lib/info.rkt +++ b/pkgs/racket-lib/info.rkt @@ -9,6 +9,7 @@ ("racket-x86_64-macosx-3" #:platform "x86_64-macosx") ("racket-i386-macosx-3" #:platform "i386-macosx") ("racket-ppc-macosx-3" #:platform "ppc-macosx") + ("racket-aarch64-macosx-3" #:platform "aarch64-macosx") ("db-ppc-macosx" #:platform "ppc-macosx") ("db-win32-i386" #:platform "win32\\i386") ("db-win32-x86_64" #:platform "win32\\x86_64") diff --git a/racket/collects/compiler/private/mach-o.rkt b/racket/collects/compiler/private/mach-o.rkt index d813abd38e..3abc432a7f 100644 --- a/racket/collects/compiler/private/mach-o.rkt +++ b/racket/collects/compiler/private/mach-o.rkt @@ -28,7 +28,9 @@ (error 'check-same "not: ~e ~e" a b))) (define (round-up-page v) - (bitwise-and #xFFFFF000 (+ v #xFFF))) + (if (eq? 'aarch64 (system-type 'arch)) + (bitwise-and #xFFFFC000 (+ v #x3FFF)) + (bitwise-and #xFFFFF000 (+ v #xFFF)))) (define (mult-of-8 n) (let ([m (modulo n 8)]) @@ -285,8 +287,8 @@ ((if link-edit-64? write-xulong write-ulong) outlen out) ((if link-edit-64? write-xulong write-ulong) out-offset out) ((if link-edit-64? write-xulong write-ulong) outlen out) - (write-ulong 0 out) - (write-ulong 0 out) + (write-ulong 0 out) ; maxprot + (write-ulong 0 out) ; minprot (write-ulong 0 out) (write-ulong 4 out) ; 4 means SG_NORELOC ;; Shift command positions diff --git a/racket/collects/ffi/unsafe/objc.rkt b/racket/collects/ffi/unsafe/objc.rkt index 0f7612bb64..0c2b95f588 100644 --- a/racket/collects/ffi/unsafe/objc.rkt +++ b/racket/collects/ffi/unsafe/objc.rkt @@ -283,7 +283,8 @@ ;; But if we assume no unaligned data and that fancy types ;; like _m256 won't show up with ObjC, it seems to be as ;; simple as this: - ((ctype-sizeof v) . <= . 16))])) + ((ctype-sizeof v) . <= . 16))] + [(aarch64-macosx aarch64-darwin) (lambda (v) #t)])) ;; Make `msgSends' access atomic, so that a thread cannot be suspended ;; or killed during access, which would block other threads. diff --git a/racket/src/cs/c/Makefile.in b/racket/src/cs/c/Makefile.in index c4375a23a2..1c376e1fa4 100644 --- a/racket/src/cs/c/Makefile.in +++ b/racket/src/cs/c/Makefile.in @@ -239,18 +239,15 @@ GRAPPSKEL = GRacketCS.app/Contents/Info.plist MACLIBRKT_LINK_fw = -F. -framework Racket $(LDFLAGS) MACLIBRKT_LINK_static = $(BOOT_OBJS) $(LDFLAGS) $(LIBS) -racketcs@OSX@: main.o $(RKTFW) - $(CC) $(CFLAGS) -o racketcs main.o $(MACLIBRKT_LINK_@MACLIBRKT_LINK_MODE@) +racketcs@OSX@: raw_racketcs $(MAKE) link-fw-bootfiles-@MACLIBRKT_LINK_MODE@ - $(MAKE) raw_racketcs $(MAKE) adjust-framework-boot-compress - $(MAKE) mac-embed-boot-@MACLIBRKT_LINK_MODE@ EMBED_DEST=racketcs - $(STRIP_SIGNATURE) racketcs + $(MAKE) mac-embed-boot-@MACLIBRKT_LINK_MODE@ EMBED_SRC=raw_racketcs EMBED_DEST=racketcs /usr/bin/install_name_tool -change "Racket.framework/Versions/$(FWVERSION)_CS/Racket" "@executable_path/Racket.framework/Versions/$(FWVERSION)_CS/Racket" racketcs $(RESTORE_SIGNATURE) racketcs -raw_racketcs@OSX@: - ln -s racketcs raw_racketcs +raw_racketcs@OSX@: main.o $(RKTFW) + $(CC) $(CFLAGS) -o raw_racketcs main.o $(MACLIBRKT_LINK_@MACLIBRKT_LINK_MODE@) GRACKET_BIN = GRacketCS.app/Contents/MacOS/GRacketCS @@ -258,9 +255,8 @@ gracketcs@OSX@: $(MAKE) $(GRACKET_BIN) $(GRACKET_BIN): grmain.o $(RKTFW) $(GRAPPSKEL) - $(CC) $(CFLAGS) -o $(GRACKET_BIN) grmain.o $(MACLIBRKT_LINK_@MACLIBRKT_LINK_MODE@) - $(MAKE) mac-embed-boot-@MACLIBRKT_LINK_MODE@ EMBED_DEST=$(GRACKET_BIN) - $(STRIP_SIGNATURE) $(GRACKET_BIN) + $(CC) $(CFLAGS) -o $(GRACKET_BIN)_raw grmain.o $(MACLIBRKT_LINK_@MACLIBRKT_LINK_MODE@) + $(MAKE) mac-embed-boot-@MACLIBRKT_LINK_MODE@ EMBED_SRC=$(GRACKET_BIN)_raw EMBED_DEST=$(GRACKET_BIN) /usr/bin/install_name_tool -change "Racket.framework/Versions/$(FWVERSION)_CS/Racket" "@executable_path/../../../Racket.framework/Versions/$(FWVERSION)_CS/Racket" $(GRACKET_BIN) $(RESTORE_SIGNATURE) $(GRACKET_BIN) @@ -284,10 +280,15 @@ adjust-framework-boot-compress: $(BOOTSTRAP_RACKET) $(srcdir)/adjust-compress.rkt @BOOT_COMPRESS_COMP@ $(FW_BOOT_DEST)/petite.boot $(FW_BOOT_DEST)/scheme.boot $(FW_BOOT_DEST)/racket.boot mac-embed-boot-fw: - $(NOOP) + cp $(EMBED_SRC) $(EMBED_DEST) + $(STRIP_SIGNATURE) $(EMBED_DEST) + +FW_BOOT_DESTS = $(FW_BOOT_DEST)/petite.boot $(FW_BOOT_DEST)/scheme.boot $(FW_BOOT_DEST)/racket.boot mac-embed-boot-static: - $(BOOTSTRAP_RACKET) $(srcdir)/embed-boot.rkt @BOOT_COMPRESS_COMP@ "" $(EMBED_DEST) $(FW_BOOT_DEST)/petite.boot $(FW_BOOT_DEST)/scheme.boot $(FW_BOOT_DEST)/racket.boot + cp $(EMBED_SRC) $(EMBED_DEST) + $(STRIP_SIGNATURE) $(EMBED_DEST) + $(BOOTSTRAP_RACKET) $(srcdir)/embed-boot.rkt @BOOT_COMPRESS_COMP@ $(EMBED_SRC) $(EMBED_DEST) $(FW_BOOT_DESTS) link-fw-bootfiles-fw: $(NOOP) diff --git a/racket/src/cs/c/gen-system.rkt b/racket/src/cs/c/gen-system.rkt index 7cd21d9cdd..c122fb4219 100644 --- a/racket/src/cs/c/gen-system.rkt +++ b/racket/src/cs/c/gen-system.rkt @@ -92,6 +92,7 @@ (define-values (arch) (lookup 'arch-symbol)) (define-values (link) (lookup 'link-symbol)) (define-values (so-suffix) (lookup 'so-suffix-bytes)) + (define-values (so-mode) (lookup 'so-mode)) (define-values (lib-subpath) (string-append @@ -124,7 +125,7 @@ 'library-subpath (string->bytes/utf-8 lib-subpath) 'library-subpath-convention (if (eq? os 'windows) 'windows 'unix) 'so-suffix so-suffix - 'so-mode 'local + 'so-mode so-mode 'fs-change (if (eq? os 'windows) '#(supported scalable low-latency #f) ;; Warning: not necessarily right for cross compilation: diff --git a/racket/src/cs/rumble/system.ss b/racket/src/cs/rumble/system.ss index 4b698ee2d5..de9ecfd1e2 100644 --- a/racket/src/cs/rumble/system.ss +++ b/racket/src/cs/rumble/system.ss @@ -86,6 +86,11 @@ [(a6nt ta6nt i3nt ti3nt) (string->utf8 ".dll")] [else (string->utf8 ".so")])) +(define so-mode + (case (machine-type) + [(arm64osx tarm64osx) 'global] + [else 'local])) + ;; Force inline of some common cases, so optimization can use ;; the resulting constant: (define-syntax system-type @@ -118,7 +123,7 @@ [(link) link-symbol] [(machine) (get-machine-info)] [(so-suffix) so-suffix-bytes] - [(so-mode) 'local] + [(so-mode) so-mode] [(fs-change) fs-change-properties] [(target-machine) (machine-type)] [(cross) cross-mode] diff --git a/racket/src/native-libs/README.txt b/racket/src/native-libs/README.txt index f70ee8857b..d77e5fb8db 100644 --- a/racket/src/native-libs/README.txt +++ b/racket/src/native-libs/README.txt @@ -22,7 +22,7 @@ Currently, we use the following external packages and versions: openssl-1.1.1g libiconv-1.15 (Windows only) zlib-1.2.11 (Windows and Linux only) - libffi-3.2.1 + libffi-3.2.1 (AArch64 Mac OS: libffi-3.3) expat-2.2.5 gettext-0.19.8 glib-2.56.0 @@ -37,7 +37,7 @@ Currently, we use the following external packages and versions: pango-1.42.0 poppler-0.24.5 mpfr-3.1.6 - gmp-6.1.2 + gmp-6.1.2 (AArch64 Mac OS: gmp-6.2.1) atk-2.28.1 (Linux only:) diff --git a/racket/src/native-libs/build-all.rkt b/racket/src/native-libs/build-all.rkt index f014666b0a..9649f45fb4 100644 --- a/racket/src/native-libs/build-all.rkt +++ b/racket/src/native-libs/build-all.rkt @@ -59,6 +59,10 @@ "jpeg" "atk" "poppler") + (cond + [mac? + '("libedit")] + [else null]) (cond [linux? '("gdk-pixbuf" diff --git a/racket/src/native-libs/build.rkt b/racket/src/native-libs/build.rkt index b63f45ab1f..e511ff73e3 100644 --- a/racket/src/native-libs/build.rkt +++ b/racket/src/native-libs/build.rkt @@ -189,12 +189,18 @@ (define-runtime-path fcdirs-patch "patches/fcdirs.patch") (define-runtime-path fonts-conf "patches/fonts.conf") +;; Skip `fc-config` on install: +(define-runtime-path fc-config-patch "patches/fc-config.patch") + ;; Avoid problems compiling with an old version of g++ (define-runtime-path harfbuzz-oldcompiler-patch "patches/harfbuzz-oldcompiler.patch") ;; Adapt inline-function handling for an old gcc (define-runtime-path gmp-inline-patch "patches/gmp-inline.patch") +;; Configure for AArch64 +(define-runtime-path openssl-aarch64osx-patch "patches/openssl-aarch64osx.patch") + ;; -------------------------------------------------- (define (replace-in-file file orig new) @@ -239,6 +245,11 @@ (list "CC" (~a win-prefix "-gcc -static-libgcc")))])] [mac? (cond + [aarch64? + (define flags "-arch arm64 -mmacosx-version-min=11") + (list + (list "CPPFLAGS" (~a flags)) + (list "LDFLAGS" (~a flags)))] [m32? (define sdk-flags (sdk mac32-sdk)) (list @@ -327,6 +338,7 @@ #:setup [setup null] #:patches [patches null] #:post-patches [post-patches null] + #:install-patches [install-patches null] #:fixup [fixup #f] #:fixup-proc [fixup-proc #f]) (for ([d (in-list (append (if (or (equal? package-name "pkg-config") @@ -338,7 +350,7 @@ deps))]) (unless (file-exists? (build-path dest "stamps" d)) (error 'build "prerequisite needed: ~a" d))) - (values env exe args make make-install setup patches post-patches fixup fixup-proc)) + (values env exe args make make-install setup patches post-patches install-patches fixup fixup-proc)) (define path-flags (list (list "CPPFLAGS" (~a "-I" dest "/include")) @@ -357,7 +369,7 @@ (error (format "build ~a only for Linux" package-name)))) (define-values (extra-env configure-exe extra-args make-command make-install-command - setup patches post-patches fixup fixup-proc) + setup patches post-patches install-patches fixup fixup-proc) (case package-name [("pkg-config") (config #:configure (list "--with-internal-glib"))] [("sed") (config)] @@ -388,15 +400,20 @@ (~a "mingw" (if m32? "" "64")) "shared")] [mac? - (list "./Configure" - #f - "shared" - (cond - [ppc? "darwin-ppc-cc"] - [m32? "darwin-i386-cc"] - [else "darwin64-x86_64-cc"]) - (car (regexp-match #rx"-mmacosx-version-min=[0-9.]*" - (cadr (assoc "CPPFLAGS" all-env)))))] + (append + (list "./Configure" + #f + "shared" + (cond + [ppc? "darwin-ppc-cc"] + [m32? "darwin-i386-cc"] + [aarch64? "darwin64-aarch64-cc"] + [else "darwin64-x86_64-cc"]) + (car (regexp-match #rx"-mmacosx-version-min=[0-9.]*" + (cadr (assoc "CPPFLAGS" all-env))))) + (if aarch64? + '("no-asm") + null))] [else (list "./Configure" #f @@ -404,6 +421,7 @@ "linux-x86_64")]) #:make make #:make-install (~a make " install_sw") + #:patches (list openssl-aarch64osx-patch) #:fixup (and win? (~a "cd " (build-path dest "bin") " && mv libssl-1_1" (if m32? "" "-x64") ".dll ssleay32.dll" @@ -463,7 +481,10 @@ " FreeSans.ttf" " FreeSerif.ttf" " " dest "/lib/fonts"))] - [("libffi") (config)] + [("libffi") + (if (and mac? aarch64?) + (config #:configure '("-host=aarch64-apple-darwin")) + (config))] [("zlib") (nonmac-only) (config #:make (if win? @@ -511,7 +532,10 @@ `("--without-libiconv-prefix" "--without-libintl-prefix") '())) - #:patches (list fcdirs-patch))] + #:patches (list fcdirs-patch) + #:install-patches (cond + [(and mac? aarch64?) (list fc-config-patch)] + [else null]))] [("pixman") (config #:patches (append (cond [(and win? (not m32?)) (list noforceinline-patch)] @@ -582,6 +606,9 @@ [("gmp") (config #:patches (if gcc-4.0? (list gmp-weak-patch) null) #:configure (append '("--enable-shared" "--disable-static") + (if (and mac? aarch64?) + '("-host=aarch64-apple-darwin") + null) (if (and mac? (not ppc?)) '("--build=corei-apple-darwin") null) @@ -648,6 +675,8 @@ (for ([p (in-list post-patches)]) (system/show (~a "patch -p2 < " p)))) (system/show make-command) + (for ([p (in-list install-patches)]) + (system/show (~a "patch -p2 < " p))) (system/show make-install-command) (when fixup (system/show fixup)) diff --git a/racket/src/native-libs/cmdline.rkt b/racket/src/native-libs/cmdline.rkt index 7ac0b77e97..d5a690e9ad 100644 --- a/racket/src/native-libs/cmdline.rkt +++ b/racket/src/native-libs/cmdline.rkt @@ -2,7 +2,7 @@ (require racket/cmdline) (provide build-command-line - m32? win? mac? linux? ppc? + m32? win? mac? linux? ppc? aarch64? archives-dirs) (define m32? 'unknown) @@ -10,6 +10,7 @@ (define linux? #f) (define mac? 'unknown) (define ppc? #f) +(define aarch64? #f) (define archives-dirs #f) @@ -20,6 +21,7 @@ (define mac? 'unknown) (define linux? #f) (define ppc? (regexp-match? #rx"ppc" (system-library-subpath #f))) + (define aarch64? (eq? 'aarch64 (system-type 'arch))) (define archives-dirs #f) (begin0 (command-line @@ -34,11 +36,14 @@ #:once-any [("--m32") "build 32-bit mode x86/PowerPC" (set! m32? #t)] - [("--m64") "build 64-bit mode x86_64" + [("--m64") "build 64-bit mode x86_64/AArch64" (set! m32? #f)] [("--mppc") "build 32-bit mode PowerPC" (set! m32? #t) (set! ppc? #t)] + [("--maarch64") "build 64-bit mode AArch64" + (set! m32? #f) + (set! aarch64? #t)] #:multi [("--archives") dir "Find archives in