Skip to content

Commit

Permalink
Merge pull request #325827 from linsui/pjsip
Browse files Browse the repository at this point in the history
pjsip: fix build on python 3.12
  • Loading branch information
SuperSandro2000 authored Jul 20, 2024
2 parents 6e14bbc + 8a2af2b commit f1550ab
Showing 1 changed file with 96 additions and 77 deletions.
173 changes: 96 additions & 77 deletions pkgs/applications/networking/pjsip/default.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{ lib
, testers
, stdenv
, fetchFromGitHub
, openssl
, libsamplerate
, swig
, alsa-lib
, AppKit
, CoreFoundation
, Security
, python3
, pythonSupport ? true
, runCommand
{
lib,
testers,
stdenv,
fetchFromGitHub,
openssl,
libsamplerate,
swig,
alsa-lib,
AppKit,
CoreFoundation,
Security,
python3,
pythonSupport ? true,
runCommand,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "pjsip";
Expand All @@ -24,22 +25,41 @@ stdenv.mkDerivation (finalAttrs: {
hash = "sha256-LDA3o1QMrAxcGuOi/YRoMzXmw/wFkfDs2wweZuIJ2RY=";
};

patches = [
./fix-aarch64.patch
];
patches = [ ./fix-aarch64.patch ];

postPatch = ''
substituteInPlace \
pjsip-apps/src/py_pjsua/setup.py \
pjsip-apps/src/swig/python/setup.py \
pjsip-apps/src/python/setup.py \
pjsip-apps/src/python/setup-vc.py \
--replace-fail "distutils.core" "setuptools"
'';

nativeBuildInputs =
lib.optionals pythonSupport [ swig python3 ];
nativeBuildInputs = lib.optionals pythonSupport [
swig
python3
python3.pkgs.build
python3.pkgs.installer
python3.pkgs.setuptools
python3.pkgs.wheel
];

buildInputs = [ openssl libsamplerate ]
buildInputs =
[
openssl
libsamplerate
]
++ lib.optional stdenv.isLinux alsa-lib
++ lib.optionals stdenv.isDarwin [ AppKit CoreFoundation Security ];
++ lib.optionals stdenv.isDarwin [
AppKit
CoreFoundation
Security
];

env = lib.optionalAttrs stdenv.cc.isClang {
CXXFLAGS = "-std=c++11";
} // lib.optionalAttrs stdenv.isDarwin {
NIX_CFLAGS_LINK = "-headerpad_max_install_names";
};
env =
lib.optionalAttrs stdenv.cc.isClang { CXXFLAGS = "-std=c++11"; }
// lib.optionalAttrs stdenv.isDarwin { NIX_CFLAGS_LINK = "-headerpad_max_install_names"; };

preConfigure = ''
export LD=$CC
Expand All @@ -51,52 +71,55 @@ stdenv.mkDerivation (finalAttrs: {

configureFlags = [ "--enable-shared" ];

outputs = [ "out" ]
++ lib.optional pythonSupport "py";

postInstall = ''
mkdir -p $out/bin
cp pjsip-apps/bin/pjsua-* $out/bin/pjsua
mkdir -p $out/share/${finalAttrs.pname}-${finalAttrs.version}/samples
cp pjsip-apps/bin/samples/*/* $out/share/${finalAttrs.pname}-${finalAttrs.version}/samples
'' + lib.optionalString pythonSupport ''
(cd pjsip-apps/src/swig/python && \
python setup.py install --prefix=$py
)
'' + lib.optionalString stdenv.isDarwin ''
# On MacOS relative paths are used to refer to libraries. All libraries use
# a relative path like ../lib/*.dylib or ../../lib/*.dylib. We need to
# rewrite these to use absolute ones.
# First, find all libraries (and their symlinks) in our outputs to define
# the install_name_tool -change arguments we should pass.
readarray -t libraries < <(
for outputName in $(getAllOutputNames); do
find "''${!outputName}" \( -name '*.dylib*' -o -name '*.so*' \)
outputs = [ "out" ] ++ lib.optional pythonSupport "py";

postInstall =
''
mkdir -p $out/bin
cp pjsip-apps/bin/pjsua-* $out/bin/pjsua
mkdir -p $out/share/${finalAttrs.pname}-${finalAttrs.version}/samples
cp pjsip-apps/bin/samples/*/* $out/share/${finalAttrs.pname}-${finalAttrs.version}/samples
''
+ lib.optionalString pythonSupport ''
(cd pjsip-apps/src/swig/python && \
python -m build --no-isolation --outdir dist/ --wheel
python -m installer --prefix $py dist/*.whl
)
''
+ lib.optionalString stdenv.isDarwin ''
# On MacOS relative paths are used to refer to libraries. All libraries use
# a relative path like ../lib/*.dylib or ../../lib/*.dylib. We need to
# rewrite these to use absolute ones.
# First, find all libraries (and their symlinks) in our outputs to define
# the install_name_tool -change arguments we should pass.
readarray -t libraries < <(
for outputName in $(getAllOutputNames); do
find "''${!outputName}" \( -name '*.dylib*' -o -name '*.so*' \)
done
)
# Determine the install_name_tool -change arguments that are going to be
# applied to all libraries.
change_args=()
for lib in "''${libraries[@]}"; do
lib_name="$(basename $lib)"
change_args+=(-change ../lib/$lib_name $lib)
change_args+=(-change ../../lib/$lib_name $lib)
done
)
# Determine the install_name_tool -change arguments that are going to be
# applied to all libraries.
change_args=()
for lib in "''${libraries[@]}"; do
lib_name="$(basename $lib)"
change_args+=(-change ../lib/$lib_name $lib)
change_args+=(-change ../../lib/$lib_name $lib)
done
# Rewrite id and library refences for all non-symlinked libraries.
for lib in "''${libraries[@]}"; do
if [ -f "$lib" ]; then
install_name_tool -id $lib "''${change_args[@]}" $lib
fi
done
# Rewrite library references for all executables.
find "$out" -executable -type f | while read executable; do
install_name_tool "''${change_args[@]}" "$executable"
done
'';
# Rewrite id and library refences for all non-symlinked libraries.
for lib in "''${libraries[@]}"; do
if [ -f "$lib" ]; then
install_name_tool -id $lib "''${change_args[@]}" $lib
fi
done
# Rewrite library references for all executables.
find "$out" -executable -type f | while read executable; do
install_name_tool "''${change_args[@]}" "$executable"
done
'';

# We need the libgcc_s.so.1 loadable (for pthread_cancel to work)
dontPatchELF = true;
Expand All @@ -106,9 +129,7 @@ stdenv.mkDerivation (finalAttrs: {
command = "pjsua --version";
};

passthru.tests.pkg-config = testers.hasPkgConfigModules {
package = finalAttrs.finalPackage;
};
passthru.tests.pkg-config = testers.hasPkgConfigModules { package = finalAttrs.finalPackage; };

passthru.tests.python-pjsua2 = runCommand "python-pjsua2" { } ''
${(python3.withPackages (pkgs: [ pkgs.pjsua2 ])).interpreter} -c "import pjsua2" > $out
Expand All @@ -121,8 +142,6 @@ stdenv.mkDerivation (finalAttrs: {
maintainers = with maintainers; [ olynch ];
mainProgram = "pjsua";
platforms = platforms.linux ++ platforms.darwin;
pkgConfigModules = [
"libpjproject"
];
pkgConfigModules = [ "libpjproject" ];
};
})

0 comments on commit f1550ab

Please sign in to comment.