git.iko.soy/typeable/nixpkgs
on master help sign in
cosmopolitan: init at 0.3

Apply suggestions from code review Co-authored-by: Louis Bettens <lourkeur@users.noreply.github.com>

commitca373323f1dc92702a606e761b8d58faa9dc610c authorThomas Bereknyei <tomberek@gmail.com> dateSun 28 Feb 2021, 04:00 (6 years ago) parent9eee6b3
2 files changed+82
pkgs/development/libraries/cosmopolitan/default.nix+80 pkgs/top-level/all-packages.nix+2
pkgs/development/libraries/cosmopolitan/default.nixnew file+80
@@ -0,0 +1,80 @@
1+{ lib, gcc9Stdenv, fetchFromGitHub, runCommand, cosmopolitan }:
2+
3+gcc9Stdenv.mkDerivation rec {
4+ pname = "cosmopolitan";
5+ version = "0.3";
6+
7+ src = fetchFromGitHub {
8+ owner = "jart";
9+ repo = "cosmopolitan";
10+ rev = version;
11+ sha256 = "sha256-OVdOObO82W6JN63OWKHaERS7y0uvgxt+WLp6Y0LsmJk=";
12+ };
13+
14+ postPatch = ''
15+ patchShebangs build/
16+ rm -r third_party/gcc
17+ '';
18+
19+ dontConfigure = true;
20+ dontFixup = true;
21+ enableParallelBuilding = true;
22+
23+ preBuild = ''
24+ makeFlagsArray=(
25+ SHELL=/bin/sh
26+ AS=${gcc9Stdenv.cc.targetPrefix}as
27+ CC=${gcc9Stdenv.cc.targetPrefix}gcc
28+ GCC=${gcc9Stdenv.cc.targetPrefix}gcc
29+ CXX=${gcc9Stdenv.cc.targetPrefix}g++
30+ LD=${gcc9Stdenv.cc.targetPrefix}ld
31+ OBJCOPY=${gcc9Stdenv.cc.targetPrefix}objcopy
32+ "MKDIR=mkdir -p"
33+ )
34+ '';
35+
36+ installPhase = ''
37+ runHook preInstall
38+ mkdir -p $out/{bin,lib/include}
39+ install o/cosmopolitan.h $out/lib/include
40+ install o/cosmopolitan.a o/libc/crt/crt.o o/ape/ape.{o,lds} $out/lib
41+ cat > $out/bin/cosmoc <<EOF
42+ #!${gcc9Stdenv.shell}
43+ exec ${gcc9Stdenv.cc}/bin/${gcc9Stdenv.cc.targetPrefix}gcc \
44+ -O -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone \
45+ "\$@" \
46+ -Wl,--oformat=binary -Wl,--gc-sections -Wl,-z,max-page-size=0x1000 \
47+ -fuse-ld=bfd -Wl,-T,$out/lib/ape.lds \
48+ -include $out/lib/{include/cosmopolitan.h,crt.o,ape.o,cosmopolitan.a}
49+ EOF
50+ chmod +x $out/bin/cosmoc
51+ runHook postInstall
52+ '';
53+
54+ passthru.tests = lib.optional (gcc9Stdenv.buildPlatform == gcc9Stdenv.hostPlatform) {
55+ hello = runCommand "hello-world" { } ''
56+ printf 'main() { printf("hello world\\n"); }\n' >hello.c
57+ ${gcc9Stdenv.cc}/bin/gcc -g -O -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone -o hello.com.dbg hello.c \
58+ -fuse-ld=bfd -Wl,-T,${cosmopolitan}/lib/ape.lds \
59+ -include ${cosmopolitan}/lib/{include/cosmopolitan.h,crt.o,ape.o,cosmopolitan.a}
60+ ${gcc9Stdenv.cc.bintools.bintools_bin}/bin/objcopy -S -O binary hello.com.dbg hello.com
61+ ./hello.com
62+ printf "test successful" > $out
63+ '';
64+ cosmoc = runCommand "cosmoc-hello" { } ''
65+ printf 'main() { printf("hello world\\n"); }\n' >hello.c
66+ ${cosmopolitan}/bin/cosmoc hello.c
67+ ./a.out
68+ printf "test successful" > $out
69+ '';
70+ };
71+
72+ meta = with lib; {
73+ homepage = "https://justine.lol/cosmopolitan/";
74+ description = "Your build-once run-anywhere c library";
75+ platforms = platforms.x86_64;
76+ badPlatforms = platforms.darwin;
77+ license = licenses.isc;
78+ maintainers = with maintainers; [ lourkeur tomberek ];
79+ };
80+}
pkgs/top-level/all-packages.nix+2
@@ -13950,6 +13950,8 @@ in
1395013950
1395113951 cog = callPackage ../development/web/cog { };
1395213952
13953+ cosmopolitan = callPackage ../development/libraries/cosmopolitan { };
13954+
1395313955 ctl = callPackage ../development/libraries/ctl { };
1395413956
1395513957 ctpp2 = callPackage ../development/libraries/ctpp2 { };