about summary refs log tree commit diff
path: root/pkgs/by-name/co/cosmopolitan
diff options
context:
space:
mode:
authorAnderson Torres <torres.anderson.85@protonmail.com>2023-10-16 22:46:17 -0300
committerAnderson Torres <torres.anderson.85@protonmail.com>2023-11-02 11:42:11 -0300
commitf8d72a6defcd821daabbe2a8ad0e60efdcdd6bd3 (patch)
tree7901c796d79e7d552860dc6f3008f73bb505aa65 /pkgs/by-name/co/cosmopolitan
parent5c9058156322d30fdeaf9423c072112baab855f9 (diff)
cosmopolitan: migrate to by-name
Diffstat (limited to 'pkgs/by-name/co/cosmopolitan')
-rw-r--r--pkgs/by-name/co/cosmopolitan/fix-paths.patch12
-rw-r--r--pkgs/by-name/co/cosmopolitan/package.nix60
2 files changed, 72 insertions, 0 deletions
diff --git a/pkgs/by-name/co/cosmopolitan/fix-paths.patch b/pkgs/by-name/co/cosmopolitan/fix-paths.patch
new file mode 100644
index 0000000000000..85c59f3f12a39
--- /dev/null
+++ b/pkgs/by-name/co/cosmopolitan/fix-paths.patch
@@ -0,0 +1,12 @@
+--- a/test/tool/plinko/plinko_test.c
++++ b/test/tool/plinko/plinko_test.c
+@@ -91,8 +91,8 @@ TEST(plinko, worksOrPrintsNiceError) {
+     sigaction(SIGQUIT, &savequit, 0);
+     sigaction(SIGPIPE, &savepipe, 0);
+     sigprocmask(SIG_SETMASK, &savemask, 0);
+     execve("bin/plinko.com", (char *const[]){"bin/plinko.com", 0},
+-           (char *const[]){0});
++           (char *const[]){"PATH=@coreutils@/bin", 0});
+     _exit(127);
+   }
+   close(pfds[0][0]);
diff --git a/pkgs/by-name/co/cosmopolitan/package.nix b/pkgs/by-name/co/cosmopolitan/package.nix
new file mode 100644
index 0000000000000..6f4cdb1cf6878
--- /dev/null
+++ b/pkgs/by-name/co/cosmopolitan/package.nix
@@ -0,0 +1,60 @@
+{ lib, stdenv, fetchFromGitHub, unzip, bintools-unwrapped, coreutils, substituteAll }:
+
+stdenv.mkDerivation rec {
+  pname = "cosmopolitan";
+  version = "2.2";
+
+  src = fetchFromGitHub {
+    owner = "jart";
+    repo = pname;
+    rev = version;
+    sha256 = "sha256-DTL1dXH+LhaxWpiCrsNjV74Bw5+kPbhEAA2Z1NKiPDk=";
+  };
+
+  patches = [
+    # make sure tests set PATH correctly
+    (substituteAll { src = ./fix-paths.patch; inherit coreutils; })
+  ];
+
+  nativeBuildInputs = [ bintools-unwrapped unzip ];
+
+  outputs = [ "out" "dist" ];
+
+  # slashes are significant because upstream uses o/$(MODE)/foo.o
+  buildFlags = [ "o/cosmopolitan.h" "o//cosmopolitan.a" "o//libc/crt/crt.o" "o//ape/ape.o" "o//ape/ape.lds" ];
+  checkTarget = "o//test";
+  enableParallelBuilding = true;
+
+  doCheck = true;
+  dontConfigure = true;
+  dontFixup = true;
+
+  preCheck = ''
+    # some syscall tests fail because we're in a sandbox
+    rm test/libc/calls/sched_setscheduler_test.c
+    rm test/libc/thread/pthread_create_test.c
+    rm test/libc/calls/getgroups_test.c
+
+    # fails
+    rm test/libc/stdio/posix_spawn_test.c
+  '';
+
+  installPhase = ''
+    runHook preInstall
+    mkdir -p $out/{include,lib}
+    install o/cosmopolitan.h $out/include
+    install o/cosmopolitan.a o/libc/crt/crt.o o/ape/ape.{o,lds} o/ape/ape-no-modify-self.o $out/lib
+
+    cp -RT . "$dist"
+    runHook postInstall
+  '';
+
+  meta = with lib; {
+    homepage = "https://justine.lol/cosmopolitan/";
+    description = "Your build-once run-anywhere c library";
+    platforms = platforms.x86_64;
+    badPlatforms = platforms.darwin;
+    license = licenses.isc;
+    maintainers = teams.cosmopolitan.members;
+  };
+}