Skip to content

Commit

Permalink
Build nodejs (21.7.2) with the --shared flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rootmos committed Apr 16, 2024
0 parents commit 78796c7
Show file tree
Hide file tree
Showing 7 changed files with 394 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/check-upstream-PKGBUILD
@@ -0,0 +1,21 @@
#!/bin/bash

set -o nounset -o pipefail -o errexit

SCRIPT_DIR=$(readlink -f "$0" | xargs dirname)
ROOT=$(readlink -f "$SCRIPT_DIR/..")
LOCAL="$ROOT/PKGBUILD.upstream"

TMP=$(mktemp -d)
trap 'rm -rf $TMP' EXIT

NEW="$TMP/PKGBUILD.upstream.new"

URL="https://gitlab.archlinux.org/archlinux/packaging/packages/nodejs/-/raw/main/PKGBUILD"
echo 1>&2 "fetching: $URL"
wget -q -O"$NEW" "$URL"

if ! diff "$LOCAL" "$NEW"; then
cp -v "$NEW" "$ROOT/PKGBUILD.upstream.new"
exit 1
fi
167 changes: 167 additions & 0 deletions .github/makepkg.conf
@@ -0,0 +1,167 @@
#!/hint/bash
# shellcheck disable=2034

#
# /etc/makepkg.conf
#

#########################################################################
# SOURCE ACQUISITION
#########################################################################
#
#-- The download utilities that makepkg should use to acquire sources
# Format: 'protocol::agent'
DLAGENTS=('file::/usr/bin/curl -qgC - -o %o %u'
'ftp::/usr/bin/curl -qgfC - --ftp-pasv --retry 3 --retry-delay 3 -o %o %u'
'http::/usr/bin/curl -qgb "" -fLC - --retry 3 --retry-delay 3 -o %o %u'
'https::/usr/bin/curl -qgb "" -fLC - --retry 3 --retry-delay 3 -o %o %u'
'rsync::/usr/bin/rsync --no-motd -z %u %o'
'scp::/usr/bin/scp -C %u %o')

# Other common tools:
# /usr/bin/snarf
# /usr/bin/lftpget -c
# /usr/bin/wget

#-- The package required by makepkg to download VCS sources
# Format: 'protocol::package'
VCSCLIENTS=('bzr::breezy'
'fossil::fossil'
'git::git'
'hg::mercurial'
'svn::subversion')

#########################################################################
# ARCHITECTURE, COMPILE FLAGS
#########################################################################
#
CARCH="x86_64"
CHOST="x86_64-pc-linux-gnu"

#-- Compiler and Linker Flags
#CPPFLAGS=""
CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions \
-Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security \
-fstack-clash-protection -fcf-protection \
-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"
CXXFLAGS="$CFLAGS -Wp,-D_GLIBCXX_ASSERTIONS"
LDFLAGS="-Wl,-O1 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now \
-Wl,-z,pack-relative-relocs"
LTOFLAGS="-flto=auto"
RUSTFLAGS="-Cforce-frame-pointers=yes"
#-- Make Flags: change this for DistCC/SMP systems
#MAKEFLAGS="-j2"
#-- Debugging flags
DEBUG_CFLAGS="-g"
DEBUG_CXXFLAGS="$DEBUG_CFLAGS"
DEBUG_RUSTFLAGS="-C debuginfo=2"

#########################################################################
# BUILD ENVIRONMENT
#########################################################################
#
# Makepkg defaults: BUILDENV=(!distcc !color !ccache check !sign)
# A negated environment option will do the opposite of the comments below.
#
#-- distcc: Use the Distributed C/C++/ObjC compiler
#-- color: Colorize output messages
#-- ccache: Use ccache to cache compilation
#-- check: Run the check() function if present in the PKGBUILD
#-- sign: Generate PGP signature file
#
BUILDENV=(!distcc color !ccache !check !sign)
#
#-- If using DistCC, your MAKEFLAGS will also need modification. In addition,
#-- specify a space-delimited list of hosts running in the DistCC cluster.
#DISTCC_HOSTS=""
#
#-- Specify a directory for package building.
#BUILDDIR=/tmp/makepkg

#########################################################################
# GLOBAL PACKAGE OPTIONS
# These are default values for the options=() settings
#########################################################################
#
# Makepkg defaults: OPTIONS=(!strip docs libtool staticlibs emptydirs !zipman !purge !debug !lto !autodeps)
# A negated option will do the opposite of the comments below.
#
#-- strip: Strip symbols from binaries/libraries
#-- docs: Save doc directories specified by DOC_DIRS
#-- libtool: Leave libtool (.la) files in packages
#-- staticlibs: Leave static library (.a) files in packages
#-- emptydirs: Leave empty directories in packages
#-- zipman: Compress manual (man and info) pages in MAN_DIRS with gzip
#-- purge: Remove files specified by PURGE_TARGETS
#-- debug: Add debugging flags as specified in DEBUG_* variables
#-- lto: Add compile flags for building with link time optimization
#-- autodeps: Automatically add depends/provides
#
OPTIONS=(strip docs !libtool !staticlibs emptydirs zipman purge !debug lto)

#-- File integrity checks to use. Valid: md5, sha1, sha224, sha256, sha384, sha512, b2
INTEGRITY_CHECK=(sha256)
#-- Options to be used when stripping binaries. See `man strip' for details.
STRIP_BINARIES="--strip-all"
#-- Options to be used when stripping shared libraries. See `man strip' for details.
STRIP_SHARED="--strip-unneeded"
#-- Options to be used when stripping static libraries. See `man strip' for details.
STRIP_STATIC="--strip-debug"
#-- Manual (man and info) directories to compress (if zipman is specified)
MAN_DIRS=({usr{,/local}{,/share},opt/*}/{man,info})
#-- Doc directories to remove (if !docs is specified)
DOC_DIRS=(usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc})
#-- Files to be removed from all packages (if purge is specified)
PURGE_TARGETS=(usr/{,share}/info/dir .packlist *.pod)
#-- Directory to store source code in for debug packages
DBGSRCDIR="/usr/src/debug"
#-- Prefix and directories for library autodeps
LIB_DIRS=('lib:usr/lib' 'lib32:usr/lib32')

#########################################################################
# PACKAGE OUTPUT
#########################################################################
#
# Default: put built package and cached source in build directory
#
#-- Destination: specify a fixed directory where all packages will be placed
#PKGDEST=/home/packages
#-- Source cache: specify a fixed directory where source files will be cached
#SRCDEST=/home/sources
#-- Source packages: specify a fixed directory where all src packages will be placed
#SRCPKGDEST=/home/srcpackages
#-- Log files: specify a fixed directory where all log files will be placed
#LOGDEST=/home/makepkglogs
#-- Packager: name/email of the person or organization building packages
#PACKAGER="John Doe <john@doe.com>"
#-- Specify a key to use for package signing
#GPGKEY=""

#########################################################################
# COMPRESSION DEFAULTS
#########################################################################
#
COMPRESSGZ=(gzip -c -f -n)
COMPRESSBZ2=(bzip2 -c -f)
COMPRESSXZ=(xz -c -z -)
COMPRESSZST=(zstd -c -T0 --ultra -20 -)
COMPRESSLRZ=(lrzip -q)
COMPRESSLZO=(lzop -q)
COMPRESSZ=(compress -c -f)
COMPRESSLZ4=(lz4 -q)
COMPRESSLZ=(lzip -c -f)

#########################################################################
# EXTENSION DEFAULTS
#########################################################################
#
PKGEXT='.pkg.tar.zst'
SRCEXT='.src.tar.gz'

#########################################################################
# OTHER
#########################################################################
#
#-- Command used to run pacman as root, instead of trying sudo and su
#PACMAN_AUTH=()
# vim: set ft=sh ts=2 sw=2 et:
66 changes: 66 additions & 0 deletions .github/workflows/build.yaml
@@ -0,0 +1,66 @@
name: Build package
on:
push:
branches:
- 'main'

jobs:
build:
runs-on: ubuntu-latest
container:
image: archlinux:latest
env:
UNPRIVILEGED: arch
steps:
- name: Install minimal dependencies
run: pacman -Suy --noconfirm base-devel

- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Create an unprivileged user
run: |
useradd -m $UNPRIVILEGED
chown -R $UNPRIVILEGED:$UNPRIVILEGED .
tee -a /etc/sudoers.d/$UNPRIVILEGED <<< "$UNPRIVILEGED ALL = NOPASSWD: $(which pacman)"
- name: Build package
run: |
sudo -u $UNPRIVILEGED makepkg --syncdeps --noconfirm --config=.github/makepkg.conf "MAKEFLAGS=-j$(nproc)"
- name: Keep package
uses: actions/upload-artifact@v4
with:
name: pkg.${{github.sha}}
retention-days: 7
path: "*.pkg.tar.zst"

release:
runs-on: ubuntu-latest
needs: build
permissions:
contents: write
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Figure out release name
run: |
. PKGBUILD
echo "RELEASE_NAME=v$pkgver-$pkgrel" | tee -a "$GITHUB_ENV"
- name: Download package
uses: actions/download-artifact@v4
with:
name: pkg.${{github.sha}}

- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
find -name "*.pkg.tar.zst" \
| xargs gh release create "$RELEASE_NAME"
17 changes: 17 additions & 0 deletions .github/workflows/check-upstream.yaml
@@ -0,0 +1,17 @@
name: Check upstream PKGBUILD
on:
schedule:
- cron: "0 0 21 * *"
workflow_dispatch:

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check upstream PKGBUILD
run: .github/check-upstream-PKGBUILD
56 changes: 56 additions & 0 deletions PKGBUILD
@@ -0,0 +1,56 @@
pkgname=nodejs-shared
provides=('nodejs')
pkgver=21.7.2
_commit=d4a1d050c0b22f0455bb6eb53eca8f7e7da937d2
pkgrel=1
pkgdesc='Evented I/O for V8 javascript'
arch=('x86_64')
url='https://nodejs.org/'
license=('MIT')
options=(!lto)
depends=('icu' 'libuv' 'libnghttp2' 'libnghttp3' 'libngtcp2' 'openssl' 'zlib' 'brotli' 'c-ares') # 'http-parser' 'v8')
makedepends=('git' 'python' 'procps-ng')
optdepends=('npm: nodejs package manager')
source=("git+https://github.com/nodejs/node.git#commit=$_commit")
sha512sums=('488d9f320dc183d27bd6ec770d9070da39cebe135a2582cbb44c4577d68addea3ffe15548ce17e02004e0ecd54bd55c7e7e5b2fbc8b3dac61fbbdad29df30cef')

build() {
cd node

# /usr/lib/libnode.so uses malloc_usable_size, which is incompatible with fortification level 3
export CFLAGS="${CFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"
export CXXFLAGS="${CXXFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"

./configure --shared \
--prefix=/usr \
--without-npm \
--with-intl=system-icu \
--shared-libuv \
--shared-nghttp2 \
--shared-nghttp3 \
--shared-ngtcp2 \
--shared-openssl \
--shared-zlib \
--shared-brotli \
--shared-cares
# --shared-v8
# --shared-http-parser

make
}

check() {
cd node
make test || :
}

package() {
cd node
make DESTDIR="$pkgdir" install
install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/nodejs/

cd "$pkgdir"/usr/lib
ln -s libnode.so.* libnode.so
}

# vim:set ts=2 sw=2 et:
61 changes: 61 additions & 0 deletions PKGBUILD.upstream
@@ -0,0 +1,61 @@
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Thomas Dziedzic < gostrc at gmail >
# Contributor: James Campos <james.r.campos@gmail.com>
# Contributor: BlackEagle < ike DOT devolder AT gmail DOT com >
# Contributor: Dongsheng Cai <dongsheng at moodle dot com>
# Contributor: Masutu Subric <masutu.arch at googlemail dot com>
# Contributor: TIanyi Cui <tianyicui@gmail.com>

pkgname=nodejs
pkgver=21.7.2
_commit=d4a1d050c0b22f0455bb6eb53eca8f7e7da937d2
pkgrel=1
pkgdesc='Evented I/O for V8 javascript'
arch=('x86_64')
url='https://nodejs.org/'
license=('MIT')
options=(!lto)
depends=('icu' 'libuv' 'libnghttp2' 'libnghttp3' 'libngtcp2' 'openssl' 'zlib' 'brotli' 'c-ares') # 'http-parser' 'v8')
makedepends=('git' 'python' 'procps-ng')
optdepends=('npm: nodejs package manager')
source=("git+https://github.com/nodejs/node.git#commit=$_commit")
sha512sums=('488d9f320dc183d27bd6ec770d9070da39cebe135a2582cbb44c4577d68addea3ffe15548ce17e02004e0ecd54bd55c7e7e5b2fbc8b3dac61fbbdad29df30cef')

build() {
cd node

# /usr/lib/libnode.so uses malloc_usable_size, which is incompatible with fortification level 3
export CFLAGS="${CFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"
export CXXFLAGS="${CXXFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"

./configure \
--prefix=/usr \
--without-npm \
--with-intl=system-icu \
--shared-libuv \
--shared-nghttp2 \
--shared-nghttp3 \
--shared-ngtcp2 \
--shared-openssl \
--shared-zlib \
--shared-brotli \
--shared-cares
# --shared-v8
# --shared-http-parser

make
}

check() {
cd node
make test || :
}

package() {
cd node
make DESTDIR="$pkgdir" install
install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/nodejs/
}

# vim:set ts=2 sw=2 et:

0 comments on commit 78796c7

Please sign in to comment.