From c8dfaee895788edbb9cbb0a09e340cb485ccb038 Mon Sep 17 00:00:00 2001 From: Jack Leightcap <30168080+jleightcap@users.noreply.github.com> Date: Tue, 16 Jul 2024 06:27:18 -0400 Subject: [PATCH] lib25519: init at 20240321 (#319618) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * init: lib25519 at 20240321 Signed-off-by: Jack Leightcap * Add installCheckPhase to lib25519 * Set platforms for lib25519, libcpucycles and librandombytes * Fixed patch for libcpucycles * lib25519: remove openssl unneeded variable * lib25519: patch scripts to pull toolchain from environment variables * librandombytes: add regression test script * lib25519: checkpoint for successful cross-compile * testing without binfmt * compilation for arm64 without cross compiling * compilation for x86 that creates a x86 binary * lib25519: replace compiler command to fix cross- and native compiling * librandombytes, lib25519: cleanup * crosstest.sh: drop --------- Signed-off-by: Jack Leightcap Co-authored-by: Roland Coeurjoly Co-authored-by: imad.nyc Co-authored-by: Enric Morales Co-authored-by: Alberto Merino RisueƱo Co-authored-by: Weijia Wang <9713184+wegank@users.noreply.github.com> --- .../lib25519/environment-variable-tools.patch | 48 ++++++++++++ pkgs/by-name/li/lib25519/package.nix | 75 +++++++++++++++++++ .../environment-variable-tools.patch | 59 +++++++++++++++ pkgs/by-name/li/libcpucycles/package.nix | 8 +- pkgs/by-name/li/librandombytes/package.nix | 5 ++ 5 files changed, 190 insertions(+), 5 deletions(-) create mode 100644 pkgs/by-name/li/lib25519/environment-variable-tools.patch create mode 100644 pkgs/by-name/li/lib25519/package.nix create mode 100644 pkgs/by-name/li/libcpucycles/environment-variable-tools.patch diff --git a/pkgs/by-name/li/lib25519/environment-variable-tools.patch b/pkgs/by-name/li/lib25519/environment-variable-tools.patch new file mode 100644 index 000000000000..121055201b01 --- /dev/null +++ b/pkgs/by-name/li/lib25519/environment-variable-tools.patch @@ -0,0 +1,48 @@ +diff --git a/configure b/configure +index 04042b2..30d1ea9 100755 +--- a/configure ++++ b/configure +@@ -210,6 +210,17 @@ for arch in sorted(os.listdir('compilers')): + with open('compilers/%s' % arch) as f: + for c in f.readlines(): + c = c.strip() ++ if env_cc := os.getenv('CC'): ++ c_as_list= c.split() ++ # check if the compiler we're testing has the name inside the last ++ # part of the CC env var ++ # i.e. gcc == x86_64-linux-unknown-gnu-gcc ++ # or gcc == gcc ++ if c_as_list[0] == env_cc.split("-")[-1]: ++ c_as_list[0] = env_cc ++ c = ' '.join(c_as_list) ++ log('patched command as %s' % c) ++ + cv = compilerversion(c) + if cv == None: + log('skipping %s compiler %s' % (arch,c)) +diff --git a/scripts-build/checknamespace b/scripts-build/checknamespace +index ae11bed..bd9cb85 100755 +--- a/scripts-build/checknamespace ++++ b/scripts-build/checknamespace +@@ -36,7 +36,7 @@ def doit(d): + obj2U = {} + + try: +- p = subprocess.Popen(['nm','-ApP']+objs,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,universal_newlines=True) ++ p = subprocess.Popen([os.getenv('NM', 'nm'),'-ApP']+objs,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,universal_newlines=True) + out,err = p.communicate() + except Exception as e: + warn('nm failure: %s' % e) +diff --git a/scripts-build/staticlib b/scripts-build/staticlib +index 7683233..0445bc3 100755 +--- a/scripts-build/staticlib ++++ b/scripts-build/staticlib +@@ -3,6 +3,6 @@ + lib="$1" + + rm -f package/lib/"$lib".a +-ar cr package/lib/"$lib".a ofiles/*.o +-ranlib package/lib/"$lib".a || : ++${AR:-ar} cr package/lib/"$lib".a ofiles/*.o ++${RANLIB:-ranlib} package/lib/"$lib".a || : + chmod 644 package/lib/"$lib".a diff --git a/pkgs/by-name/li/lib25519/package.nix b/pkgs/by-name/li/lib25519/package.nix new file mode 100644 index 000000000000..90d377948f93 --- /dev/null +++ b/pkgs/by-name/li/lib25519/package.nix @@ -0,0 +1,75 @@ +{ + stdenv, + lib, + python3, + fetchzip, + librandombytes, + libcpucycles, +}: +stdenv.mkDerivation (finalAttrs: { + pname = "lib25519"; + version = "20240321"; + + src = fetchzip { + url = "https://lib25519.cr.yp.to/lib25519-${finalAttrs.version}.tar.gz"; + hash = "sha256-R10Q803vCjIZCS4Z/uErsx547RaXfAELGQm9NuNhw+I="; + }; + + patches = [ ./environment-variable-tools.patch ]; + + postPatch = '' + patchShebangs configure + patchShebangs scripts-build + ''; + + # NOTE: lib25519 uses a custom Python `./configure`: it does not expect standard + # autoconfig --build --host etc. arguments: disable + # Pass the hostPlatform string + configurePhase = '' + runHook preConfigure + ./configure --host=${stdenv.buildPlatform.system} --prefix=$out + runHook postConfigure + ''; + + nativeBuildInputs = [ python3 ]; + buildInputs = [ + librandombytes + libcpucycles + ]; + + preFixup = lib.optionalString stdenv.isDarwin '' + install_name_tool -id "$out/lib/lib25519.1.dylib" "$out/lib/lib25519.1.dylib" + for f in $out/bin/*; do + install_name_tool -change "lib25519.1.dylib" "$out/lib/lib25519.1.dylib" "$f" + done + ''; + + # failure: crypto_pow does not handle p=q overlap + doInstallCheck = !stdenv.isDarwin; + installCheckPhase = '' + runHook preInstallCheck + $out/bin/lib25519-test + runHook postInstallCheck + ''; + + meta = { + homepage = "https://randombytes.cr.yp.to/"; + description = "A simple API for applications generating fresh randomness"; + changelog = "https://randombytes.cr.yp.to/download.html"; + license = with lib.licenses; [ + # Upstream specifies the public domain licenses with the terms here https://cr.yp.to/spdx.html + publicDomain + cc0 + bsd0 + mit + mit0 + ]; + maintainers = with lib.maintainers; [ + kiike + imadnyc + jleightcap + ]; + # This supports whatever platforms libcpucycles supports + inherit (libcpucycles.meta) platforms; + }; +}) diff --git a/pkgs/by-name/li/libcpucycles/environment-variable-tools.patch b/pkgs/by-name/li/libcpucycles/environment-variable-tools.patch new file mode 100644 index 000000000000..b194e68c06b7 --- /dev/null +++ b/pkgs/by-name/li/libcpucycles/environment-variable-tools.patch @@ -0,0 +1,59 @@ +diff --git a/configure b/configure +index 87d5c14..5e2a1a4 100755 +--- a/configure ++++ b/configure +@@ -112,21 +112,26 @@ def compilerversion(c): + except: + pass + +-firstcompiler = None +- +-with open('compilers/default') as f: +- for c in f.readlines(): +- c = c.strip() +- cv = compilerversion(c) +- if cv == None: +- print('skipping default compiler %s' % c) +- continue +- print('using default compiler %s' % c) +- firstcompiler = c +- break +- +-if firstcompiler is None: +- raise ValueError('did not find a working compiler') ++if c := os.getenv("CC"): ++ firstcompiler = c ++ print('using default compiler %s' % c) ++else: ++ firstcompiler = None ++ ++ with open('compilers/default') as f: ++ for c in f.readlines(): ++ c = c.strip() ++ cv = compilerversion(c) ++ if cv == None: ++ print('skipping default compiler %s' % c) ++ continue ++ print('using default compiler %s' % c) ++ firstcompiler = c ++ break ++ ++ if firstcompiler is None: ++ raise ValueError('did not find a working compiler') ++ + + with open('build/%s/scripts/compiledefault' % host,'w') as f: + f.write('#!/bin/sh\n') +diff --git a/scripts-build/staticlib b/scripts-build/staticlib +index bb23658..111ab13 100755 +--- a/scripts-build/staticlib ++++ b/scripts-build/staticlib +@@ -1,6 +1,6 @@ + #!/bin/sh + + rm -f package/lib/libcpucycles.a +-ar cr package/lib/libcpucycles.a "$@" +-ranlib package/lib/libcpucycles.a || : ++${AR:-ar} cr package/lib/libcpucycles.a "$@" ++${RANLIB:-ranlib} package/lib/libcpucycles.a || : + chmod 644 package/lib/libcpucycles.a diff --git a/pkgs/by-name/li/libcpucycles/package.nix b/pkgs/by-name/li/libcpucycles/package.nix index 18f7d1a4f002..4e88903de66d 100644 --- a/pkgs/by-name/li/libcpucycles/package.nix +++ b/pkgs/by-name/li/libcpucycles/package.nix @@ -15,6 +15,8 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-Fb73EOHGgEehZJwTCtCG12xwyiqtDXFs9eFDsHBQiDo="; }; + patches = [ ./environment-variable-tools.patch ]; + postPatch = '' patchShebangs configure patchShebangs scripts-build @@ -46,10 +48,6 @@ stdenv.mkDerivation (finalAttrs: { imadnyc jleightcap ]; - # list of architectures it supports, but currentlly untested with nix https://cpucycles.cr.yp.to/libcpucycles-20240318/cpucycles/options.html - platforms = [ - "x86_64-linux" - "aarch64-linux" - ] ++ lib.platforms.darwin; + inherit (librandombytes.meta) platforms; }; }) diff --git a/pkgs/by-name/li/librandombytes/package.nix b/pkgs/by-name/li/librandombytes/package.nix index fa12ca954bdc..f36a94018e75 100644 --- a/pkgs/by-name/li/librandombytes/package.nix +++ b/pkgs/by-name/li/librandombytes/package.nix @@ -46,6 +46,11 @@ stdenv.mkDerivation (finalAttrs: { buildInputs = [ openssl ]; + preFixup = lib.optionalString stdenv.isDarwin '' + install_name_tool -id "$out/lib/librandombytes-kernel.1.dylib" "$out/lib/librandombytes-kernel.1.dylib" + install_name_tool -change "librandombytes-kernel.1.dylib" "$out/lib/librandombytes-kernel.1.dylib" "$out/bin/randombytes-info" + ''; + meta = { homepage = "https://randombytes.cr.yp.to/"; description = "A simple API for applications generating fresh randomness";