Skip to content

Commit 1d8c022

Browse files
author
Ash Cripps
committed
build: update Makefile to support fat binary
build a binary that is both x86_64 and arm64 on macos PR-URL: #37861 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Rod Vagg <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Beth Griggs <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 7df0fc5 commit 1d8c022

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

Diff for: Makefile

+26-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ TEST_CI_ARGS ?=
1010
STAGINGSERVER ?= node-www
1111
LOGLEVEL ?= silent
1212
OSTYPE := $(shell uname -s | tr '[:upper:]' '[:lower:]')
13+
ARCHTYPE := $(shell uname -m | tr '[:upper:]' '[:lower:]')
1314
COVTESTS ?= test-cov
1415
COV_SKIP_TESTS ?= core_line_numbers.js,testFinalizer.js,test_function/test.js
1516
GTEST_FILTER ?= "*"
@@ -972,6 +973,16 @@ release-only: check-xz
972973
fi
973974

974975
$(PKG): release-only
976+
# pkg building is currently only supported on an ARM64 macOS host for
977+
# ease of compiling fat-binaries for both macOS architectures.
978+
ifneq ($(OSTYPE),darwin)
979+
$(warning Invalid OSTYPE)
980+
$(error OSTYPE should be `darwin` currently is $(OSTYPE))
981+
endif
982+
ifneq ($(ARCHTYPE),arm64)
983+
$(warning Invalid ARCHTYPE)
984+
$(error ARCHTYPE should be `arm64` currently is $(ARCHTYPE))
985+
endif
975986
$(RM) -r $(MACOSOUTDIR)
976987
mkdir -p $(MACOSOUTDIR)/installer/productbuild
977988
cat tools/macos-installer/productbuild/distribution.xml.tmpl \
@@ -992,14 +1003,28 @@ $(PKG): release-only
9921003
| sed -E "s/\\{npmversion\\}/$(NPMVERSION)/g" \
9931004
>$(MACOSOUTDIR)/installer/productbuild/Resources/$$lang/conclusion.html ; \
9941005
done
1006+
CC_host="cc -arch x86_64" CXX_host="c++ -arch x86_64" \
1007+
CC_target="cc -arch x86_64" CXX_target="c++ -arch x86_64" \
1008+
CC="cc -arch x86_64" CXX="c++ -arch x86_64" $(PYTHON) ./configure \
1009+
--dest-cpu=x86_64 \
1010+
--tag=$(TAG) \
1011+
--release-urlbase=$(RELEASE_URLBASE) \
1012+
$(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
1013+
arch -x86_64 $(MAKE) install V=$(V) DESTDIR=$(MACOSOUTDIR)/dist/x64/node
1014+
SIGN="$(CODESIGN_CERT)" PKGDIR="$(MACOSOUTDIR)/dist/x64/node/usr/local" sh \
1015+
tools/osx-codesign.sh
9951016
$(PYTHON) ./configure \
996-
--dest-cpu=x64 \
1017+
--dest-cpu=arm64 \
9971018
--tag=$(TAG) \
9981019
--release-urlbase=$(RELEASE_URLBASE) \
9991020
$(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
10001021
$(MAKE) install V=$(V) DESTDIR=$(MACOSOUTDIR)/dist/node
10011022
SIGN="$(CODESIGN_CERT)" PKGDIR="$(MACOSOUTDIR)/dist/node/usr/local" sh \
10021023
tools/osx-codesign.sh
1024+
lipo $(MACOSOUTDIR)/dist/x64/node/usr/local/bin/node \
1025+
$(MACOSOUTDIR)/dist/node/usr/local/bin/node \
1026+
-output $(MACOSOUTDIR)/dist/node/usr/local/bin/node \
1027+
-create
10031028
mkdir -p $(MACOSOUTDIR)/dist/npm/usr/local/lib/node_modules
10041029
mkdir -p $(MACOSOUTDIR)/pkgs
10051030
mv $(MACOSOUTDIR)/dist/node/usr/local/lib/node_modules/npm \

0 commit comments

Comments
 (0)