1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

Fix static linking of libcxx on macOS, more portable tonlibjson (#694)

* upgrade nix to 22.11

* add static libcxx

* fix darwin dylib names

* make sure static libs are inside dylib

* apply patches only for darwin

* apply patches only for darwin

* apply patches only for darwin

* test builds

* test builds 2, remove dependency corefoundation

* test builds 3, update flake.lock

* test builds 4

* test builds 5, dontAddStaticConfigureFlags only for darwin

* test builds 6, put back CoreFoundation flag

* improve testing
This commit is contained in:
neodiX42 2023-05-19 02:24:24 -05:00 committed by GitHub
parent ef64b92f08
commit 148688572f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 19 deletions

View file

@ -31,12 +31,16 @@
openssl_1_1
zlib
libmicrohttpd
] else
[
] else [
(openssl_1_1.override { static = true; }).dev
(zlib.override { shared = false; }).dev
pkgsStatic.libmicrohttpd.dev
] ++ optional staticGlibc glibc.static;
]
++ optionals (!stdenv.isDarwin) [ pkgsStatic.libmicrohttpd.dev ]
++ optionals stdenv.isDarwin [ (libiconv.override { enableStatic = true; enableShared = false; }) ]
++ optionals stdenv.isDarwin (forEach [ libmicrohttpd.dev gmp.dev nettle.dev (gnutls.override { withP11-kit = false; }).dev libtasn1.dev libidn2.dev libunistring.dev gettext ] (x: x.overrideAttrs(oldAttrs: rec { configureFlags = (oldAttrs.configureFlags or []) ++ [ "--enable-static" "--disable-shared" ]; dontDisableStatic = true; })))
++ optionals staticGlibc [ glibc.static ];
dontAddStaticConfigureFlags = stdenv.isDarwin;
cmakeFlags = [ "-DTON_USE_ABSEIL=OFF" "-DNIX=ON" ] ++ optionals staticMusl [
"-DCMAKE_CROSSCOMPILING=OFF" # pkgsStatic sets cross
@ -47,6 +51,7 @@
LDFLAGS = optional staticExternalDeps (concatStringsSep " " [
(optionalString stdenv.cc.isGNU "-static-libgcc")
(optionalString stdenv.isDarwin "-framework CoreFoundation")
"-static-libstdc++"
]);
@ -57,6 +62,14 @@
moveToOutput bin "$bin"
'';
preFixup = optionalString stdenv.isDarwin ''
for fn in "$bin"/bin/* "$out"/lib/*.dylib; do
echo Fixing libc++ in "$fn"
install_name_tool -change "$(otool -L "$fn" | grep libc++.1 | cut -d' ' -f1 | xargs)" libc++.1.dylib "$fn"
install_name_tool -change "$(otool -L "$fn" | grep libc++abi.1 | cut -d' ' -f1 | xargs)" libc++abi.dylib "$fn"
done
'';
outputs = [ "bin" "out" ];
};
hostPkgs = system:
@ -131,10 +144,10 @@
};
ton-staticbin-dylib = host.symlinkJoin {
name = "ton";
paths = [ ton-static.bin ton-normal.out ];
paths = [ ton-static.bin ton-static.out ];
};
};
devShells.default =
host.mkShell { inputsFrom = [ packages.ton-normal ]; };
})));
}
}