cosmoc: init

This commit is contained in:
Louis Bettens 2022-03-29 14:07:44 +02:00
parent 6443507c12
commit 0d5810ede0
3 changed files with 43 additions and 19 deletions

View file

@ -25,22 +25,10 @@ stdenv.mkDerivation rec {
installPhase = ''
runHook preInstall
mkdir -p $out/{bin,include,lib}
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} $out/lib
cat > $out/bin/cosmoc <<EOF
#!${stdenv.shell}
exec ${stdenv.cc}/bin/${stdenv.cc.targetPrefix}gcc \
-O -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone \
"\$@" \
-Wl,--gc-sections -Wl,-z,max-page-size=0x1000 \
-fuse-ld=bfd -Wl,-T,$out/lib/ape.lds \
-include $out/include/cosmopolitan.h \
$out/lib/{crt.o,ape.o,cosmopolitan.a}
EOF
chmod +x $out/bin/cosmoc
pushd o
find -iname "*.com" -type f -exec install -D {} $out/{} \;
popd
@ -63,12 +51,6 @@ stdenv.mkDerivation rec {
./hello.com
printf "test successful" > $out
'';
cosmoc = runCommand "cosmoc-hello" { } ''
printf 'main() { printf("hello world\\n"); }\n' >hello.c
${cosmopolitan}/bin/cosmoc hello.c
./a.out
printf "test successful" > $out
'';
};
meta = with lib; {

View file

@ -0,0 +1,40 @@
{ stdenv, lib, cosmopolitan }:
stdenv.mkDerivation {
pname = "cosmoc";
inherit (cosmopolitan) version;
doInstallCheck = true;
dontUnpack = true;
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cat <<EOF >$out/bin/cosmoc
#!${stdenv.shell}
exec ${stdenv.cc}/bin/${stdenv.cc.targetPrefix}gcc \
-O -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone \
"\$@" \
-Wl,--gc-sections -Wl,-z,max-page-size=0x1000 \
-fuse-ld=bfd -Wl,-T,${cosmopolitan}/lib/ape.lds \
-include ${cosmopolitan}/include/cosmopolitan.h \
${cosmopolitan}/lib/{crt.o,ape.o,cosmopolitan.a}
EOF
chmod +x $out/bin/cosmoc
runHook postInstall
'';
installCheckPhase = ''
printf 'main() { printf("hello world\\n"); }\n' >hello.c
$out/bin/cosmoc hello.c
./a.out
'';
meta = with lib; {
homepage = "https://justine.lol/cosmopolitan/";
description = "compiler for Cosmopolitan C programs";
license = licenses.mit;
maintainers = with maintainers; [ lourkeur tomberek ];
};
}

View file

@ -16516,6 +16516,8 @@ with pkgs;
cog = callPackage ../development/web/cog { };
cosmoc = callPackage ../development/tools/cosmoc { };
cosmopolitan = callPackage ../development/libraries/cosmopolitan { };
ctl = callPackage ../development/libraries/ctl { };