Subject: [alpine-aports] [PATCH] main/nodejs: fix build on mips{el} (-latomic), disable on mips64*

From: alpine-mips-patches <[email-masked]>
Date: Fri, 30 Nov 2018 10:36:49 +0000

1) Add the usual -latomic for pre-R6 MIPS32.

2) Alpine mips64* definitions assume MIPS III but nodejs wants MIPS32 at least and can
actually generate instructions missing in MIPS III, e.g. movn/movz. There is also some
support for Loongson 2 (which is a MIPS III CPU) however it apparently always targets
hard-float O32 ABI so be safe and disable build on mips64* completely.

Keep pkgrel intact since no previously built mips* apks exist and changes are strictly
mips-specific.
---
 main/nodejs/APKBUILD                          | 14 +++++++++---
 .../link-with-libatomic-on-mips32.patch       | 22 +++++++++++++++++++
 2 files changed, 33 insertions(+), 3 deletions(-)
 create mode 100644 main/nodejs/link-with-libatomic-on-mips32.patch

diff --git a/main/nodejs/APKBUILD b/main/nodejs/APKBUILD
index 63dffdf469..784d5f8d4f 100644
--- a/main/nodejs/APKBUILD
+++ b/main/nodejs/APKBUILD
@@ -37,7 +37,7 @@ pkgver=10.14.0
 pkgrel=0
 pkgdesc="JavaScript runtime built on V8 engine - LTS version"
 url="https://nodejs.org/"
-arch="all"
+arch="all !mips64 !mips64el"
 license="MIT"
 depends="ca-certificates"
 depends_dev="libuv"
@@ -48,7 +48,9 @@ subpackages="$pkgname-dev $pkgname-doc npm::noarch"
 provides="nodejs-lts=$pkgver"  # for backward compatibility
 replaces="nodejs-current nodejs-lts"  # nodejs-lts for backward compatibility
 source="https://nodejs.org/dist/v$pkgver/node-v$pkgver.tar.gz
-	dont-run-gyp-files-for-bundled-deps.patch"
+	dont-run-gyp-files-for-bundled-deps.patch
+	link-with-libatomic-on-mips32.patch
+	"
 builddir="$srcdir/node-v$pkgver"
 
 prepare() {
@@ -61,7 +63,12 @@ prepare() {
 build() {
 	cd "$builddir"
 
+	case "$CARCH" in
+	mips*) _carchflags="--with-mips-arch-variant=r1 --with-mips-float-abi=soft";;
+	esac
+
 	./configure --prefix=/usr \
+		$_carchflags \
 		--shared-zlib \
 		--shared-libuv \
 		--shared-openssl \
@@ -120,4 +127,5 @@ npm() {
 }
 
 sha512sums="35506ab4cb2d3fa8ab2540aa3df87df5bd7e254ee092bd8872895bcac256ad0f54eab0277d3f67fed223a2634e75143a3a796657a9c8981fa444d599bc93cecc  node-v10.14.0.tar.gz
-9d09a88074bf0093f35c5b610e73ebf4c5381df2a2b29feb69da1af0b18776a683b13f1276375bbcfc60936cc27769539e1f01b4ba94b22cad2d5f4daae14c46  dont-run-gyp-files-for-bundled-deps.patch"
+9d09a88074bf0093f35c5b610e73ebf4c5381df2a2b29feb69da1af0b18776a683b13f1276375bbcfc60936cc27769539e1f01b4ba94b22cad2d5f4daae14c46  dont-run-gyp-files-for-bundled-deps.patch
+9256f6f84978c4fea7ac625bbf3934e85de5d00393d28a50df2c234a7309fdf5c49b59da1825e8817a3794044af0219c698a0c57367cc6f1fe0ef813f837aa97  link-with-libatomic-on-mips32.patch"
diff --git a/main/nodejs/link-with-libatomic-on-mips32.patch b/main/nodejs/link-with-libatomic-on-mips32.patch
new file mode 100644
index 0000000000..b8f6a144b7
--- /dev/null
+++ b/main/nodejs/link-with-libatomic-on-mips32.patch
@@ -0,0 +1,22 @@
+--- a/node.gyp
++++ b/node.gyp
+@@ -247,6 +247,9 @@
+       'msvs_disabled_warnings!': [4244],
+ 
+       'conditions': [
++        [ '(target_arch=="mips" or target_arch=="mipsel") and mips_arch_variant!="r6"', {
++          'libraries': [ '-latomic' ],
++        }],
+         [ 'node_intermediate_lib_type=="static_library" and '
+             'node_shared=="true" and OS=="aix"', {
+           # For AIX, shared lib is linked by static lib and .exp. In the
+@@ -934,6 +937,9 @@
+       ],
+ 
+       'conditions': [
++        [ '(target_arch=="mips" or target_arch=="mipsel") and mips_arch_variant!="r6"', {
++          'libraries': [ '-latomic' ],
++        }],
+         [ 'node_use_openssl=="true"', {
+           'defines': [
+             'HAVE_OPENSSL=1',
-- 
2.19.2

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---