signal-desktop-from-src: support cross compilation

This commit is contained in:
Colin 2023-11-15 05:50:23 +00:00
parent c4367644dd
commit 319bfe205d

View File

@ -235,6 +235,7 @@
, at-spi2-core , at-spi2-core
, atk , atk
, autoPatchelfHook , autoPatchelfHook
, bash
, buildPackages , buildPackages
, callPackage , callPackage
, cups , cups
@ -248,6 +249,7 @@
, flac , flac
, fixup_yarn_lock , fixup_yarn_lock
, gdk-pixbuf , gdk-pixbuf
, gnused
, gtk3 , gtk3
, icu , icu
, libpulseaudio , libpulseaudio
@ -262,7 +264,7 @@
, pango , pango
, python3 , python3
, removeReferencesTo , removeReferencesTo
, signal-desktop # , signal-desktop
, sqlite , sqlite
, sqlcipher , sqlcipher
, srcOnly , srcOnly
@ -319,6 +321,9 @@ let
url = "https://build-artifacts.signal.org/desktop/sqlcipher-4.5.5-fts5-fix--3.0.7--0.2.1-ef53ea45ed92b928ecfd33c552d8d405263e86e63dec38e1ec63e1b0193b630b.tar.gz"; url = "https://build-artifacts.signal.org/desktop/sqlcipher-4.5.5-fts5-fix--3.0.7--0.2.1-ef53ea45ed92b928ecfd33c552d8d405263e86e63dec38e1ec63e1b0193b630b.tar.gz";
sha256 = "sha256:02v37ccv1qb3xkhkiv1xws33w9h5skc55i9kzpn2ifcjxm2yllzg"; sha256 = "sha256:02v37ccv1qb3xkhkiv1xws33w9h5skc55i9kzpn2ifcjxm2yllzg";
}; };
buildNpmArch = if stdenv.buildPlatform.isAarch64 then "arm64" else "x64";
hostNpmArch = if stdenv.hostPlatform.isAarch64 then "arm64" else "x64";
crossNpmArchExt = if buildNpmArch == hostNpmArch then "" else "-${hostNpmArch}";
in in
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
pname = "signal-desktop-from-src"; pname = "signal-desktop-from-src";
@ -337,6 +342,7 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ nativeBuildInputs = [
autoPatchelfHook autoPatchelfHook
fixup_yarn_lock fixup_yarn_lock
gnused
makeWrapper makeWrapper
nodejs' # possibly i could instead use nodejs-slim (npm-less nodejs) nodejs' # possibly i could instead use nodejs-slim (npm-less nodejs)
python3 python3
@ -345,27 +351,27 @@ stdenv.mkDerivation rec {
yarn' yarn'
]; ];
# buildInputs = [ buildInputs = [
# alsa-lib alsa-lib
# at-spi2-atk at-spi2-atk
# at-spi2-core at-spi2-core
# atk atk
# cups cups
# electron electron
# flac flac
# gdk-pixbuf gdk-pixbuf
# gtk3 gtk3
# libpulseaudio libpulseaudio
# libwebp libwebp
# libxslt libxslt
# mesa # for libgbm mesa # for libgbm
# nspr nspr
# nss nss
# pango pango
# # so that bettersqlite may link against sqlcipher (see patch) # so that bettersqlite may link against sqlcipher (see patch)
# # but i don't know if it actually needs to. just copied this from alpine. # but i don't know if it actually needs to. just copied this from alpine.
# sqlcipher sqlcipher
# ]; ];
# to update: # to update:
# - `cp ~/ref/repos/signalapp/Signal-Desktop/{package.json,yarn.lock} .` # - `cp ~/ref/repos/signalapp/Signal-Desktop/{package.json,yarn.lock} .`
@ -401,12 +407,25 @@ stdenv.mkDerivation rec {
tar xzf ${electron.headers} tar xzf ${electron.headers}
export npm_config_nodedir=$(pwd)/node_headers export npm_config_nodedir=$(pwd)/node_headers
export npm_config_arch=${buildNpmArch}
export npm_config_target_arch=${hostNpmArch}
# optional flags: --no-progress --non-interactive # optional flags: --no-progress --non-interactive
# yarn install creates the node_modules/ directory # yarn install creates the node_modules/ directory
# --ignore-scripts tells yarn to not run the "install" or "postinstall" commands mentioned in dependencies' package.json # --ignore-scripts tells yarn to not run the "install" or "postinstall" commands mentioned in dependencies' package.json
# since many of those require network access # since many of those require network access
yarn install --offline --frozen-lockfile --ignore-scripts yarn install --offline --frozen-lockfile --ignore-scripts
# substituteInPlace node_modules/@swc/helpers/scripts/gen.sh --replace '#!/bin/bash' '#!/bin/sh'
# substituteInPlace node_modules/@swc/helpers/scripts/generator.sh --replace '#!/bin/bash' '#!/bin/sh'
# substituteInPlace node_modules/dashdash/etc/dashdash.bash_completion.in --replace '#!/bin/bash' '#!/bin/sh'
patchShebangs node_modules/ patchShebangs node_modules/
# patch these out to remove a runtime reference back to the build bash
# (better, perhaps, would be for these build scripts to not be included in the asar...)
# substituteInPlace node_modules/@swc/helpers/scripts/gen.sh --replace '#!${bash}/bin/bash' '#!/bin/sh'
# substituteInPlace node_modules/@swc/helpers/scripts/generator.sh --replace '#!${bash}/bin/bash' '#!/bin/sh'
sed -i 's:#!.*/bin/bash:#!/bin/sh:g' node_modules/@swc/helpers/scripts/gen.sh
sed -i 's:#!.*/bin/bash:#!/bin/sh:g' node_modules/@swc/helpers/scripts/generator.sh
substituteInPlace node_modules/dashdash/etc/dashdash.bash_completion.in --replace '#!/bin/bash' '#!/bin/sh'
# provide necessecities which were skipped as part of --ignore-scripts # provide necessecities which were skipped as part of --ignore-scripts
cp ${ringrtcPrebuild} node_modules/@signalapp/ringrtc/scripts/prebuild.tar.gz cp ${ringrtcPrebuild} node_modules/@signalapp/ringrtc/scripts/prebuild.tar.gz
@ -495,14 +514,6 @@ stdenv.mkDerivation rec {
# npm rebuild @signalapp/better-sqlite3 --offline --nodedir="${nodeSources}" --build-from-source # npm rebuild @signalapp/better-sqlite3 --offline --nodedir="${nodeSources}" --build-from-source
# patchelf --add-needed ${icu}/lib/libicutu.so node_modules/@signalapp/better-sqlite3/build/Release/better_sqlite3.node # patchelf --add-needed ${icu}/lib/libicutu.so node_modules/@signalapp/better-sqlite3/build/Release/better_sqlite3.node
# provide the sqlite bindings ELF. TODO: build this from source
# cp -R ${signal-desktop}/lib/Signal/resources/app.asar.unpacked/node_modules/@signalapp/better-sqlite3/build \
# node_modules/@signalapp/better-sqlite3/
# provide the ringrtc (webrtc) dependency. TODO: build this from source
# cp -R ${signal-desktop}/lib/Signal/resources/app.asar.unpacked/node_modules/@signalapp/ringrtc/build \
# node_modules/@signalapp/ringrtc/
# yarn generate: # yarn generate:
yarn build-module-protobuf --offline --frozen-lockfile yarn build-module-protobuf --offline --frozen-lockfile
yarn build:esbuild --offline --frozen-lockfile yarn build:esbuild --offline --frozen-lockfile
@ -513,7 +524,7 @@ stdenv.mkDerivation rec {
yarn build:esbuild:prod --offline --frozen-lockfile yarn build:esbuild:prod --offline --frozen-lockfile
yarn build:release \ yarn build:release \
${if stdenv.isDarwin then "--macos" else "--linux"} ${if stdenv.hostPlatform.isAarch64 then "--arm64" else "--x64"} \ --linux --${hostNpmArch} \
-c.electronDist=${electron}/libexec/electron \ -c.electronDist=${electron}/libexec/electron \
-c.electronVersion=${electron.version} \ -c.electronVersion=${electron.version} \
--dir --dir
@ -536,8 +547,8 @@ stdenv.mkDerivation rec {
runHook preInstall runHook preInstall
# directory structure follows the original `signal-desktop` nix package # directory structure follows the original `signal-desktop` nix package
mkdir -p $out/lib/Signal mkdir -p $out/lib
cp -R release/linux-unpacked/* $out/lib/Signal cp -R release/linux${crossNpmArchExt}-unpacked $out/lib/Signal
# cp -R release/linux-unpacked/resources $out/lib/Signal/resources # cp -R release/linux-unpacked/resources $out/lib/Signal/resources
# cp -R release/linux-unpacked/locales $out/lib/Signal/locales # cp -R release/linux-unpacked/locales $out/lib/Signal/locales