lib25519: init at 20240321 (#319618)

* init: lib25519 at 20240321

Signed-off-by: Jack Leightcap <jack@leightcap.com>

* 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 <jack@leightcap.com>
Co-authored-by: Roland Coeurjoly <rolandcoeurjoly@gmail.com>
Co-authored-by: imad.nyc <me@imad.nyc>
Co-authored-by: Enric Morales <me@enric.me>
Co-authored-by: Alberto Merino Risueño <Alberto.Merino@uclm.es>
Co-authored-by: Weijia Wang <9713184+wegank@users.noreply.github.com>

+190 -5
+48
pkgs/by-name/li/lib25519/environment-variable-tools.patch
··· 1 + diff --git a/configure b/configure 2 + index 04042b2..30d1ea9 100755 3 + --- a/configure 4 + +++ b/configure 5 + @@ -210,6 +210,17 @@ for arch in sorted(os.listdir('compilers')): 6 + with open('compilers/%s' % arch) as f: 7 + for c in f.readlines(): 8 + c = c.strip() 9 + + if env_cc := os.getenv('CC'): 10 + + c_as_list= c.split() 11 + + # check if the compiler we're testing has the name inside the last 12 + + # part of the CC env var 13 + + # i.e. gcc == x86_64-linux-unknown-gnu-gcc 14 + + # or gcc == gcc 15 + + if c_as_list[0] == env_cc.split("-")[-1]: 16 + + c_as_list[0] = env_cc 17 + + c = ' '.join(c_as_list) 18 + + log('patched command as %s' % c) 19 + + 20 + cv = compilerversion(c) 21 + if cv == None: 22 + log('skipping %s compiler %s' % (arch,c)) 23 + diff --git a/scripts-build/checknamespace b/scripts-build/checknamespace 24 + index ae11bed..bd9cb85 100755 25 + --- a/scripts-build/checknamespace 26 + +++ b/scripts-build/checknamespace 27 + @@ -36,7 +36,7 @@ def doit(d): 28 + obj2U = {} 29 + 30 + try: 31 + - p = subprocess.Popen(['nm','-ApP']+objs,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,universal_newlines=True) 32 + + p = subprocess.Popen([os.getenv('NM', 'nm'),'-ApP']+objs,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,universal_newlines=True) 33 + out,err = p.communicate() 34 + except Exception as e: 35 + warn('nm failure: %s' % e) 36 + diff --git a/scripts-build/staticlib b/scripts-build/staticlib 37 + index 7683233..0445bc3 100755 38 + --- a/scripts-build/staticlib 39 + +++ b/scripts-build/staticlib 40 + @@ -3,6 +3,6 @@ 41 + lib="$1" 42 + 43 + rm -f package/lib/"$lib".a 44 + -ar cr package/lib/"$lib".a ofiles/*.o 45 + -ranlib package/lib/"$lib".a || : 46 + +${AR:-ar} cr package/lib/"$lib".a ofiles/*.o 47 + +${RANLIB:-ranlib} package/lib/"$lib".a || : 48 + chmod 644 package/lib/"$lib".a
+75
pkgs/by-name/li/lib25519/package.nix
··· 1 + { 2 + stdenv, 3 + lib, 4 + python3, 5 + fetchzip, 6 + librandombytes, 7 + libcpucycles, 8 + }: 9 + stdenv.mkDerivation (finalAttrs: { 10 + pname = "lib25519"; 11 + version = "20240321"; 12 + 13 + src = fetchzip { 14 + url = "https://lib25519.cr.yp.to/lib25519-${finalAttrs.version}.tar.gz"; 15 + hash = "sha256-R10Q803vCjIZCS4Z/uErsx547RaXfAELGQm9NuNhw+I="; 16 + }; 17 + 18 + patches = [ ./environment-variable-tools.patch ]; 19 + 20 + postPatch = '' 21 + patchShebangs configure 22 + patchShebangs scripts-build 23 + ''; 24 + 25 + # NOTE: lib25519 uses a custom Python `./configure`: it does not expect standard 26 + # autoconfig --build --host etc. arguments: disable 27 + # Pass the hostPlatform string 28 + configurePhase = '' 29 + runHook preConfigure 30 + ./configure --host=${stdenv.buildPlatform.system} --prefix=$out 31 + runHook postConfigure 32 + ''; 33 + 34 + nativeBuildInputs = [ python3 ]; 35 + buildInputs = [ 36 + librandombytes 37 + libcpucycles 38 + ]; 39 + 40 + preFixup = lib.optionalString stdenv.isDarwin '' 41 + install_name_tool -id "$out/lib/lib25519.1.dylib" "$out/lib/lib25519.1.dylib" 42 + for f in $out/bin/*; do 43 + install_name_tool -change "lib25519.1.dylib" "$out/lib/lib25519.1.dylib" "$f" 44 + done 45 + ''; 46 + 47 + # failure: crypto_pow does not handle p=q overlap 48 + doInstallCheck = !stdenv.isDarwin; 49 + installCheckPhase = '' 50 + runHook preInstallCheck 51 + $out/bin/lib25519-test 52 + runHook postInstallCheck 53 + ''; 54 + 55 + meta = { 56 + homepage = "https://randombytes.cr.yp.to/"; 57 + description = "A simple API for applications generating fresh randomness"; 58 + changelog = "https://randombytes.cr.yp.to/download.html"; 59 + license = with lib.licenses; [ 60 + # Upstream specifies the public domain licenses with the terms here https://cr.yp.to/spdx.html 61 + publicDomain 62 + cc0 63 + bsd0 64 + mit 65 + mit0 66 + ]; 67 + maintainers = with lib.maintainers; [ 68 + kiike 69 + imadnyc 70 + jleightcap 71 + ]; 72 + # This supports whatever platforms libcpucycles supports 73 + inherit (libcpucycles.meta) platforms; 74 + }; 75 + })
+59
pkgs/by-name/li/libcpucycles/environment-variable-tools.patch
··· 1 + diff --git a/configure b/configure 2 + index 87d5c14..5e2a1a4 100755 3 + --- a/configure 4 + +++ b/configure 5 + @@ -112,21 +112,26 @@ def compilerversion(c): 6 + except: 7 + pass 8 + 9 + -firstcompiler = None 10 + - 11 + -with open('compilers/default') as f: 12 + - for c in f.readlines(): 13 + - c = c.strip() 14 + - cv = compilerversion(c) 15 + - if cv == None: 16 + - print('skipping default compiler %s' % c) 17 + - continue 18 + - print('using default compiler %s' % c) 19 + - firstcompiler = c 20 + - break 21 + - 22 + -if firstcompiler is None: 23 + - raise ValueError('did not find a working compiler') 24 + +if c := os.getenv("CC"): 25 + + firstcompiler = c 26 + + print('using default compiler %s' % c) 27 + +else: 28 + + firstcompiler = None 29 + + 30 + + with open('compilers/default') as f: 31 + + for c in f.readlines(): 32 + + c = c.strip() 33 + + cv = compilerversion(c) 34 + + if cv == None: 35 + + print('skipping default compiler %s' % c) 36 + + continue 37 + + print('using default compiler %s' % c) 38 + + firstcompiler = c 39 + + break 40 + + 41 + + if firstcompiler is None: 42 + + raise ValueError('did not find a working compiler') 43 + + 44 + 45 + with open('build/%s/scripts/compiledefault' % host,'w') as f: 46 + f.write('#!/bin/sh\n') 47 + diff --git a/scripts-build/staticlib b/scripts-build/staticlib 48 + index bb23658..111ab13 100755 49 + --- a/scripts-build/staticlib 50 + +++ b/scripts-build/staticlib 51 + @@ -1,6 +1,6 @@ 52 + #!/bin/sh 53 + 54 + rm -f package/lib/libcpucycles.a 55 + -ar cr package/lib/libcpucycles.a "$@" 56 + -ranlib package/lib/libcpucycles.a || : 57 + +${AR:-ar} cr package/lib/libcpucycles.a "$@" 58 + +${RANLIB:-ranlib} package/lib/libcpucycles.a || : 59 + chmod 644 package/lib/libcpucycles.a
+3 -5
pkgs/by-name/li/libcpucycles/package.nix
··· 15 15 hash = "sha256-Fb73EOHGgEehZJwTCtCG12xwyiqtDXFs9eFDsHBQiDo="; 16 16 }; 17 17 18 + patches = [ ./environment-variable-tools.patch ]; 19 + 18 20 postPatch = '' 19 21 patchShebangs configure 20 22 patchShebangs scripts-build ··· 46 48 imadnyc 47 49 jleightcap 48 50 ]; 49 - # list of architectures it supports, but currentlly untested with nix https://cpucycles.cr.yp.to/libcpucycles-20240318/cpucycles/options.html 50 - platforms = [ 51 - "x86_64-linux" 52 - "aarch64-linux" 53 - ] ++ lib.platforms.darwin; 51 + inherit (librandombytes.meta) platforms; 54 52 }; 55 53 })
+5
pkgs/by-name/li/librandombytes/package.nix
··· 46 46 47 47 buildInputs = [ openssl ]; 48 48 49 + preFixup = lib.optionalString stdenv.isDarwin '' 50 + install_name_tool -id "$out/lib/librandombytes-kernel.1.dylib" "$out/lib/librandombytes-kernel.1.dylib" 51 + install_name_tool -change "librandombytes-kernel.1.dylib" "$out/lib/librandombytes-kernel.1.dylib" "$out/bin/randombytes-info" 52 + ''; 53 + 49 54 meta = { 50 55 homepage = "https://randombytes.cr.yp.to/"; 51 56 description = "A simple API for applications generating fresh randomness";