initial commit
This commit is contained in:
commit
c6b956ffa9
33 changed files with 3077 additions and 0 deletions
68
support/compile-rust.nix
Normal file
68
support/compile-rust.nix
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
{ pkgs
|
||||
, zig
|
||||
, ...
|
||||
}:
|
||||
{ target
|
||||
, cargoLock
|
||||
, src
|
||||
, extraLibs
|
||||
, ...
|
||||
}:
|
||||
let
|
||||
importCargoLock = pkgs.rustPlatform.importCargoLock;
|
||||
cargoSetupHook = pkgs.rustPlatform.cargoSetupHook;
|
||||
stdenv = pkgs.stdenv;
|
||||
|
||||
targetAsRust = {
|
||||
amd64-linux = "x86_64-unknown-linux-musl";
|
||||
arm64-linux = "aarch64-unknown-linux-musl";
|
||||
}.${target};
|
||||
|
||||
rust-pkg = import ./rust.nix { inherit pkgs zig; system = "x86_64-linux"; };
|
||||
|
||||
libPaths = map (x: "${x}/lib") extraLibs;
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
name = "yaar-${target}";
|
||||
|
||||
inherit src;
|
||||
|
||||
cargoDeps = importCargoLock cargoLock;
|
||||
|
||||
RUSTFLAGS =
|
||||
"-C link-self-contained=no "
|
||||
+ builtins.concatStringsSep " " (map (p: "-L ${p}") libPaths);
|
||||
|
||||
hardeningDisable = ["all"];
|
||||
|
||||
nativeBuildInputs = [
|
||||
cargoSetupHook
|
||||
rust-pkg
|
||||
zig
|
||||
pkgs.glibc
|
||||
];
|
||||
|
||||
configurePhase = ''
|
||||
runHook preConfigure
|
||||
runHook postConfigure
|
||||
'';
|
||||
|
||||
doCheck = false;
|
||||
strictDeps = true;
|
||||
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
|
||||
echo "RUSTFLAGS=$RUSTFLAGS"
|
||||
echo cargo build --target ${targetAsRust} -j $NIX_BUILD_CORES --offline --release
|
||||
cargo build --target ${targetAsRust} -j $NIX_BUILD_CORES --offline --release
|
||||
|
||||
runHook postBuild
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
cp target/${targetAsRust}/release/yaar "$out"
|
||||
'';
|
||||
|
||||
dontFixup = true;
|
||||
}
|
||||
14
support/lib-bzip2.nix
Normal file
14
support/lib-bzip2.nix
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{ mkMuslLib, pkgs, zigCC, zigAR, zigRANLIB, ... }:
|
||||
mkMuslLib {
|
||||
pname = "bzip2-musl-static";
|
||||
src = pkgs.bzip2.src;
|
||||
dontConfigure = true;
|
||||
buildPhase = ''
|
||||
make -j$NIX_BUILD_CORES CC="${zigCC}" AR="${zigAR}" RANLIB="${zigRANLIB}" libbz2.a
|
||||
'';
|
||||
installPhase = ''
|
||||
mkdir -p $out/lib $out/include
|
||||
cp libbz2.a $out/lib/
|
||||
cp bzlib.h $out/include/
|
||||
'';
|
||||
}
|
||||
53
support/lib-libarchive.nix
Normal file
53
support/lib-libarchive.nix
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
{ mkMuslLib, pkgs, zigCC, zigAR, zigRANLIB, autotoolsHost, ... }:
|
||||
let
|
||||
ctx = { inherit mkMuslLib pkgs zigCC zigAR zigRANLIB autotoolsHost; };
|
||||
zlib = import ./lib-zlib.nix ctx;
|
||||
bzip2 = import ./lib-bzip2.nix ctx;
|
||||
xz = import ./lib-xz.nix ctx;
|
||||
lz4 = import ./lib-lz4.nix ctx;
|
||||
zstd = import ./lib-zstd.nix ctx;
|
||||
libxml2 = import ./lib-libxml2.nix ctx;
|
||||
in
|
||||
{
|
||||
libarchive = mkMuslLib {
|
||||
pname = "libarchive-musl-static";
|
||||
src = pkgs.libarchive.src;
|
||||
nativeBuildInputs = [ pkgs.cmake pkgs.pkg-config ];
|
||||
configurePhase = ''
|
||||
cmake -B builddir \
|
||||
-DCMAKE_C_COMPILER="${zigCC}" \
|
||||
-DCMAKE_CXX_COMPILER="${zigCC}" \
|
||||
-DCMAKE_AR="${zigAR}" \
|
||||
-DCMAKE_RANLIB="${zigRANLIB}" \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DENABLE_TEST=OFF \
|
||||
-DENABLE_TAR=OFF \
|
||||
-DENABLE_CPIO=OFF \
|
||||
-DENABLE_CAT=OFF \
|
||||
-DENABLE_UNZIP=OFF \
|
||||
-DENABLE_OPENSSL=OFF \
|
||||
-DENABLE_LIBB2=OFF \
|
||||
-DENABLE_ICONV=OFF \
|
||||
-DENABLE_EXPAT=OFF \
|
||||
-DENABLE_PCRE2POSIX=OFF \
|
||||
-DENABLE_PCREPOSIX=OFF \
|
||||
-DENABLE_LIBXML2=ON \
|
||||
-DENABLE_ZLIB=ON \
|
||||
-DENABLE_BZip2=ON \
|
||||
-DENABLE_LZMA=ON \
|
||||
-DENABLE_ZSTD=ON \
|
||||
-DENABLE_LZ4=ON \
|
||||
-DENABLE_ACL=OFF \
|
||||
-DENABLE_XATTR=OFF \
|
||||
-DCMAKE_PREFIX_PATH="${zlib};${bzip2};${xz};${lz4};${zstd};${libxml2}" \
|
||||
-DCMAKE_FIND_ROOT_PATH="${zlib};${bzip2};${xz};${lz4};${zstd};${libxml2}" \
|
||||
-DCMAKE_INSTALL_PREFIX=$out \
|
||||
-DCMAKE_INSTALL_LIBDIR=lib
|
||||
'';
|
||||
buildPhase = "cmake --build builddir -j$NIX_BUILD_CORES";
|
||||
installPhase = "cmake --install builddir";
|
||||
};
|
||||
|
||||
# All libs needed for static linking (libarchive + its deps)
|
||||
allLibs = [ zlib bzip2 xz lz4 zstd libxml2 ];
|
||||
}
|
||||
28
support/lib-libxml2.nix
Normal file
28
support/lib-libxml2.nix
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{ mkMuslLib, pkgs, zigCC, zigAR, zigRANLIB, ... }:
|
||||
mkMuslLib {
|
||||
pname = "libxml2-musl-static";
|
||||
src = pkgs.libxml2.src;
|
||||
nativeBuildInputs = [ pkgs.cmake pkgs.pkg-config ];
|
||||
configurePhase = ''
|
||||
cmake -B builddir \
|
||||
-DCMAKE_C_COMPILER="${zigCC}" \
|
||||
-DCMAKE_CXX_COMPILER="${zigCC}" \
|
||||
-DCMAKE_AR="${zigAR}" \
|
||||
-DCMAKE_RANLIB="${zigRANLIB}" \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DLIBXML2_WITH_PYTHON=OFF \
|
||||
-DLIBXML2_WITH_ICU=OFF \
|
||||
-DLIBXML2_WITH_LZMA=OFF \
|
||||
-DLIBXML2_WITH_ZLIB=OFF \
|
||||
-DLIBXML2_WITH_ICONV=OFF \
|
||||
-DLIBXML2_WITH_HTTP=OFF \
|
||||
-DLIBXML2_WITH_FTP=OFF \
|
||||
-DLIBXML2_WITH_THREADS=ON \
|
||||
-DLIBXML2_WITH_PROGRAMS=OFF \
|
||||
-DLIBXML2_WITH_TESTS=OFF \
|
||||
-DCMAKE_INSTALL_PREFIX=$out \
|
||||
-DCMAKE_INSTALL_LIBDIR=lib
|
||||
'';
|
||||
buildPhase = "cmake --build builddir -j$NIX_BUILD_CORES";
|
||||
installPhase = "cmake --install builddir";
|
||||
}
|
||||
21
support/lib-lz4.nix
Normal file
21
support/lib-lz4.nix
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{ mkMuslLib, pkgs, zigCC, zigAR, zigRANLIB, ... }:
|
||||
mkMuslLib {
|
||||
pname = "lz4-musl-static";
|
||||
src = pkgs.lz4.src;
|
||||
nativeBuildInputs = [ pkgs.cmake ];
|
||||
configurePhase = ''
|
||||
cmake -S build/cmake -B builddir \
|
||||
-DCMAKE_C_COMPILER="${zigCC}" \
|
||||
-DCMAKE_CXX_COMPILER="${zigCC}" \
|
||||
-DCMAKE_AR="${zigAR}" \
|
||||
-DCMAKE_RANLIB="${zigRANLIB}" \
|
||||
-DLZ4_BUILD_CLI=OFF \
|
||||
-DLZ4_BUILD_LEGACY_LZ4C=OFF \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DBUILD_STATIC_LIBS=ON \
|
||||
-DCMAKE_INSTALL_PREFIX=$out \
|
||||
-DCMAKE_INSTALL_LIBDIR=lib
|
||||
'';
|
||||
buildPhase = "cmake --build builddir -j$NIX_BUILD_CORES";
|
||||
installPhase = "cmake --install builddir";
|
||||
}
|
||||
15
support/lib-xz.nix
Normal file
15
support/lib-xz.nix
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{ mkMuslLib, pkgs, autotoolsHost, ... }:
|
||||
mkMuslLib {
|
||||
pname = "xz-musl-static";
|
||||
src = pkgs.xz.src;
|
||||
nativeBuildInputs = [ pkgs.updateAutotoolsGnuConfigScriptsHook ];
|
||||
configurePhase = ''
|
||||
./configure --host=${autotoolsHost} \
|
||||
--disable-shared --enable-static \
|
||||
--disable-xz --disable-xzdec --disable-lzmadec --disable-lzmainfo \
|
||||
--disable-scripts --disable-doc --disable-nls \
|
||||
--prefix=$out
|
||||
'';
|
||||
buildPhase = "make -j$NIX_BUILD_CORES";
|
||||
installPhase = "make install";
|
||||
}
|
||||
10
support/lib-zlib.nix
Normal file
10
support/lib-zlib.nix
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{ mkMuslLib, pkgs, ... }:
|
||||
mkMuslLib {
|
||||
pname = "zlib-musl-static";
|
||||
src = pkgs.zlib.src;
|
||||
configurePhase = ''
|
||||
./configure --static --prefix=$out
|
||||
'';
|
||||
buildPhase = "make -j$NIX_BUILD_CORES";
|
||||
installPhase = "make install";
|
||||
}
|
||||
20
support/lib-zstd.nix
Normal file
20
support/lib-zstd.nix
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{ mkMuslLib, pkgs, zigCC, zigAR, zigRANLIB, ... }:
|
||||
mkMuslLib {
|
||||
pname = "zstd-musl-static";
|
||||
src = pkgs.zstd.src;
|
||||
nativeBuildInputs = [ pkgs.cmake ];
|
||||
configurePhase = ''
|
||||
cmake -S build/cmake -B builddir \
|
||||
-DCMAKE_C_COMPILER="${zigCC}" \
|
||||
-DCMAKE_CXX_COMPILER="${zigCC}" \
|
||||
-DCMAKE_AR="${zigAR}" \
|
||||
-DCMAKE_RANLIB="${zigRANLIB}" \
|
||||
-DZSTD_BUILD_PROGRAMS=OFF \
|
||||
-DZSTD_BUILD_SHARED=OFF \
|
||||
-DZSTD_BUILD_STATIC=ON \
|
||||
-DCMAKE_INSTALL_PREFIX=$out \
|
||||
-DCMAKE_INSTALL_LIBDIR=lib
|
||||
'';
|
||||
buildPhase = "cmake --build builddir -j$NIX_BUILD_CORES";
|
||||
installPhase = "cmake --install builddir";
|
||||
}
|
||||
30
support/musl-libs.nix
Normal file
30
support/musl-libs.nix
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
{ pkgs, zig, name-target }:
|
||||
let
|
||||
zigCC = "${zig}/bin/zig-cc-${name-target}";
|
||||
zigAR = "${zig}/bin/zig-ar";
|
||||
zigRANLIB = "${zig}/bin/zig-ranlib";
|
||||
|
||||
autotoolsHost = {
|
||||
"amd64-linux" = "x86_64-linux-musl";
|
||||
"arm64-linux" = "aarch64-linux-musl";
|
||||
}.${name-target};
|
||||
|
||||
mkMuslLib = args: pkgs.stdenvNoCC.mkDerivation ({
|
||||
nativeBuildInputs = [ zig pkgs.gnumake pkgs.binutils ] ++ (args.nativeBuildInputs or []);
|
||||
dontFixup = true;
|
||||
CC = zigCC;
|
||||
AR = zigAR;
|
||||
RANLIB = zigRANLIB;
|
||||
} // builtins.removeAttrs args [ "nativeBuildInputs" ] // {
|
||||
name = "${args.pname}-${name-target}";
|
||||
});
|
||||
|
||||
ctx = {
|
||||
inherit pkgs zigCC zigAR zigRANLIB autotoolsHost mkMuslLib;
|
||||
};
|
||||
|
||||
libarchiveResult = import ./lib-libarchive.nix ctx;
|
||||
in {
|
||||
inherit (libarchiveResult) libarchive;
|
||||
allLibs = [ libarchiveResult.libarchive ] ++ libarchiveResult.allLibs;
|
||||
}
|
||||
100
support/rust.nix
Normal file
100
support/rust.nix
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
{ pkgs
|
||||
, system ? "x86_64-linux"
|
||||
, zig
|
||||
, ...
|
||||
}:
|
||||
let
|
||||
systemAsRust = {
|
||||
x86_64-linux = "x86_64-unknown-linux-gnu";
|
||||
aarch64-linux = "aarch64-unknown-linux-gnu";
|
||||
}.${system};
|
||||
|
||||
manifest-src = builtins.fetchurl {
|
||||
url = "https://static.rust-lang.org/dist/2025-05-15/channel-rust-stable.toml";
|
||||
sha256 = "0594aavj08dw7ba9wndbjg31crkpqz7wcbzzfmgc9yg3j7mbaj99";
|
||||
};
|
||||
|
||||
manifest = builtins.fromTOML (builtins.readFile manifest-src);
|
||||
|
||||
simpleComponent = x: builtins.fetchurl {
|
||||
url = x.url;
|
||||
sha256 = x.hash;
|
||||
};
|
||||
|
||||
components = [
|
||||
(simpleComponent manifest.pkg.cargo.target.${systemAsRust})
|
||||
(simpleComponent manifest.pkg.rustc.target.${systemAsRust})
|
||||
(simpleComponent manifest.pkg.rust-std.target.${systemAsRust})
|
||||
(simpleComponent manifest.pkg.rust-std.target.x86_64-unknown-linux-musl)
|
||||
(simpleComponent manifest.pkg.rust-std.target.aarch64-unknown-linux-musl)
|
||||
];
|
||||
in pkgs.stdenvNoCC.mkDerivation rec {
|
||||
name = "yaar-rust";
|
||||
|
||||
srcs = components;
|
||||
sourceRoot = ".";
|
||||
|
||||
dontConfigure = true;
|
||||
dontBuild = true;
|
||||
|
||||
nativeBuildInputs = [ pkgs.makeWrapper ];
|
||||
|
||||
buildInputs = [
|
||||
pkgs.glibc
|
||||
pkgs.zlib
|
||||
pkgs.bash
|
||||
pkgs.gcc.cc.lib
|
||||
zig
|
||||
];
|
||||
|
||||
dontAutoPatchelf = true;
|
||||
|
||||
fixupPhase = ''
|
||||
SEARCH_DIRS="$out/bin"
|
||||
if [[ "${system}" == "x86_64-linux" ]]
|
||||
then
|
||||
SEARCH_DIRS="$SEARCH_DIRS $out/lib/rustlib/x86_64-unknown-linux-gnu/bin"
|
||||
fi
|
||||
if [[ "${system}" == "aarch64-linux" ]]
|
||||
then
|
||||
SEARCH_DIRS="$SEARCH_DIRS $out/lib/rustlib/aarch64-unknown-linux-gnu/bin"
|
||||
fi
|
||||
find $SEARCH_DIRS -type f -executable | while read binary; do
|
||||
if file "$binary" | grep -q "ELF"
|
||||
then
|
||||
echo "Patching $binary"
|
||||
patchelf \
|
||||
--set-interpreter ${pkgs.glibc}/lib/ld-linux-x86-64.so.2 \
|
||||
--set-rpath "${pkgs.lib.makeLibraryPath buildInputs}:"'$ORIGIN/../lib' \
|
||||
"$binary"
|
||||
fi
|
||||
done
|
||||
|
||||
find $out/lib -type f -maxdepth 1 | while read binary; do
|
||||
if file "$binary" | grep -q "ELF"
|
||||
then
|
||||
echo "Patching $binary"
|
||||
patchelf \
|
||||
--set-rpath "${pkgs.lib.makeLibraryPath buildInputs}:"'$ORIGIN/../lib' \
|
||||
"$binary"
|
||||
fi
|
||||
done
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out
|
||||
for i in $(find . -type d -maxdepth 2 -mindepth 1) ;
|
||||
do
|
||||
cp -r "$i/." $out/.
|
||||
done
|
||||
|
||||
wrapProgram $out/bin/cargo \
|
||||
--set CC_x86_64_unknown_linux_musl zig-cc-amd64-linux \
|
||||
--set CC_aarch64_unknown_linux_musl zig-cc-arm64-linux \
|
||||
--set CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER zig-cc-amd64-linux \
|
||||
--set CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER zig-cc-arm64-linux \
|
||||
--prefix LD_LIBRARY_PATH : "${pkgs.lib.makeLibraryPath buildInputs}"
|
||||
'';
|
||||
}
|
||||
80
support/zig.nix
Normal file
80
support/zig.nix
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
{ pkgs
|
||||
, system ? "x86_64-linux"
|
||||
, ...
|
||||
}:
|
||||
let
|
||||
zig = {
|
||||
x86_64-linux = builtins.fetchTarball {
|
||||
url = "https://ziglang.org/download/0.15.1/zig-x86_64-linux-0.15.1.tar.xz";
|
||||
sha256 = "0yar24a1qjg503czwnkdipky1cfb08k0mm9c8gwv827d33df1070";
|
||||
};
|
||||
aarch64-linux = builtins.fetchTarball {
|
||||
url = "https://ziglang.org/download/0.15.1/zig-aarch64-linux-0.15.1.tar.xz";
|
||||
sha256 = "19vcv7a1scm4wpj5cgv3dmzajz37fdyx5x1inxfgxzsavbmvq3zy";
|
||||
};
|
||||
}.${system};
|
||||
|
||||
make-cc-wrapper = trg: pkgs.writeShellScript "zig-cc-${trg}" ''
|
||||
if [ ! -d "$HOME" ]; then
|
||||
export ZIG_GLOBAL_CACHE_DIR=/build/.zig-cache
|
||||
export ZIG_LOCAL_CACHE_DIR=/build/.zig-cache-local
|
||||
fi
|
||||
args=()
|
||||
for arg in "$@"; do
|
||||
if [[ "$skip_next" == true ]]; then
|
||||
skip_next=false
|
||||
continue
|
||||
fi
|
||||
if [[ "$arg" != --target=* ]] && \
|
||||
[[ "$arg" != -framework ]] && \
|
||||
[[ "$arg" != CoreFoundation ]] && \
|
||||
[[ "$arg" != Foundation ]] && \
|
||||
[[ "$arg" != *CoreFoundation* ]] && \
|
||||
[[ "$arg" != *Foundation* ]] && \
|
||||
[[ "$arg" != -F ]] && \
|
||||
[[ "$arg" != -F* ]]; then
|
||||
args+=("$arg")
|
||||
elif [[ "$arg" == -framework ]] || [[ "$arg" == -F ]]; then
|
||||
skip_next=true
|
||||
fi
|
||||
done
|
||||
|
||||
exec "${zig}/zig" cc -fdebug-prefix-map=${toString zig}=/zig -target ${trg} "''${args[@]}"
|
||||
'';
|
||||
|
||||
make-ar-wrapper = pkgs.writeShellScript "zig-ar" ''
|
||||
if [ ! -d "$HOME" ]; then
|
||||
export ZIG_GLOBAL_CACHE_DIR=/build/.zig-cache
|
||||
export ZIG_LOCAL_CACHE_DIR=/build/.zig-cache-local
|
||||
fi
|
||||
exec "${zig}/zig" ar "$@"
|
||||
'';
|
||||
|
||||
make-ranlib-wrapper = pkgs.writeShellScript "zig-ranlib" ''
|
||||
if [ ! -d "$HOME" ]; then
|
||||
export ZIG_GLOBAL_CACHE_DIR=/build/.zig-cache
|
||||
export ZIG_LOCAL_CACHE_DIR=/build/.zig-cache-local
|
||||
fi
|
||||
exec "${zig}/zig" ranlib "$@"
|
||||
'';
|
||||
in
|
||||
pkgs.stdenvNoCC.mkDerivation {
|
||||
name = "yaar-zig";
|
||||
|
||||
src = zig;
|
||||
|
||||
nativeBuildInputs = [ pkgs.coreutils ];
|
||||
|
||||
dontConfigure = true;
|
||||
|
||||
dontBuild = true;
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p "$out/bin"
|
||||
cp -r "./." "$out"
|
||||
cp ${make-cc-wrapper "x86_64-linux-musl"} "$out/bin/zig-cc-amd64-linux"
|
||||
cp ${make-cc-wrapper "aarch64-linux-musl"} "$out/bin/zig-cc-arm64-linux"
|
||||
cp ${make-ar-wrapper} "$out/bin/zig-ar"
|
||||
cp ${make-ranlib-wrapper} "$out/bin/zig-ranlib"
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue