about summary refs log tree commit diff
path: root/pkgs/development/libraries/cosmopolitan/default.nix
blob: 63f45f62fd145389b9da2f962e6a8af68942c47e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{ lib, stdenv, fetchFromGitHub, unzip, bintools-unwrapped, coreutils, substituteAll }:

stdenv.mkDerivation rec {
  pname = "cosmopolitan";
  version = "2.1.1";

  src = fetchFromGitHub {
    owner = "jart";
    repo = pname;
    rev = version;
    sha256 = "sha256-2Q4lutSIQ6tBwTy01lPSMepNAww9Kb7BwNyEcsSdWZ0=";
  };

  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
  '';

  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;
  };
}