mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-16 04:28:26 +00:00
nix: make the iOS core package reproducible
This commit is contained in:
1 parent
d72649b4e4
commit
aeb12ca9fa
2 files changed
+56
-2
No files matched your search
@@ -108,6 +108,7 @@
|
||||
chmod +w $pkg
|
||||
${mac2ios.packages.${system}.mac2ios}/bin/mac2ios $pkg
|
||||
[[ "$pkg" == *simplex-chat* ]] && ${pkgs.stdenv.cc.targetPrefix}strip -x $pkg
|
||||
${pkgs.python3}/bin/python3 ${./scripts/nix/zero-ar-headers.py} $pkg
|
||||
chmod -w $pkg
|
||||
done
|
||||
|
||||
@@ -117,7 +118,8 @@
|
||||
|
||||
sha256sum $out/_pkg/*.a
|
||||
|
||||
(cd $out/_pkg; ${pkgs.zip}/bin/zip -r -9 $out/${bundleName}.zip *)
|
||||
find "$out/_pkg" -exec touch -h -d '@1764547200' {} +
|
||||
(cd $out/_pkg; ${pkgs.zip}/bin/zip -r -9 -X $out/${bundleName}.zip *)
|
||||
rm -fR $out/_pkg
|
||||
mkdir -p $out/nix-support
|
||||
echo "file binary-dist \"$(echo $out/*.zip)\"" \
|
||||
@@ -129,7 +131,8 @@
|
||||
# we need threaded here, otherwise all the queing logic doesn't work properly.
|
||||
# for iOS we also use -staticlib, to get one rolled up library.
|
||||
# still needs mac2ios patching of the archives.
|
||||
ghcOptions = [ "-staticlib" "-threaded" "-DIOS" ];
|
||||
# this list replaces the -j1 that all packages get: GHC's parallel compilation gives non-deterministic objects.
|
||||
ghcOptions = [ "-staticlib" "-threaded" "-DIOS" "-j1" ];
|
||||
postInstall = iosPostInstall bundleName;
|
||||
}; in
|
||||
rec {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
"""Zeroes the dates and owners in the member headers of ar archives, which GHC and strip take from the build's clock and user."""
|
||||
|
||||
import struct
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
AR_MAGIC = b"!<arch>\n"
|
||||
|
||||
|
||||
# name, date, uid, gid, mode, size and end of a member header
|
||||
AR_HEADER = struct.Struct("16s12s6s6s8s10s2s")
|
||||
|
||||
|
||||
AR_HEADER_END = b"`\n"
|
||||
|
||||
|
||||
# the date, uid, gid and mode that llvm-ar's deterministic mode writes
|
||||
DETERMINISTIC_FIELDS = (b"0".ljust(12), b"0".ljust(6), b"0".ljust(6), b"644".ljust(8))
|
||||
|
||||
|
||||
class ArchiveError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def zero_headers(data: bytes) -> bytes:
|
||||
if not data.startswith(AR_MAGIC):
|
||||
raise ArchiveError("not an ar archive")
|
||||
zeroed = bytearray(data)
|
||||
offset = len(AR_MAGIC)
|
||||
while offset < len(zeroed):
|
||||
if offset + AR_HEADER.size > len(zeroed):
|
||||
raise ArchiveError(f"ends in a member header at {offset}")
|
||||
name, *_, size, end = AR_HEADER.unpack_from(zeroed, offset)
|
||||
if end != AR_HEADER_END:
|
||||
raise ArchiveError(f"no member header at {offset}")
|
||||
AR_HEADER.pack_into(zeroed, offset, name, *DETERMINISTIC_FIELDS, size, end)
|
||||
# a member of odd size is padded with a newline
|
||||
offset += AR_HEADER.size + int(size) + int(size) % 2
|
||||
return bytes(zeroed)
|
||||
|
||||
|
||||
def main(paths: list[str]) -> None:
|
||||
for path in map(Path, paths):
|
||||
try:
|
||||
path.write_bytes(zero_headers(path.read_bytes()))
|
||||
except ArchiveError as e:
|
||||
sys.exit(f"{path}: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
Reference in new issue
Block a user