Merge pull request #166277 from lourkeur/refactor-cosmopolitan

This commit is contained in:
Sandro 2022-03-30 17:28:47 +02:00 committed by GitHub
commit 0fa8cbf8de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 112 additions and 49 deletions

View File

@ -70,6 +70,14 @@ with lib.maintainers; {
scope = "Maintain the Chia blockchain and its dependencies";
};
cosmopolitan = {
members = [
lourkeur
tomberek
];
scope = "Maintain the Cosmopolitan LibC and related programs.";
};
deshaw = {
# Verify additions to this team with at least one already existing member of the team.
members = [

View File

@ -1253,6 +1253,13 @@
example.
</para>
</listitem>
<listitem>
<para>
<literal>pkgs.cosmopolitan</literal> no longer provides the
<literal>cosmoc</literal> command. It has been moved to
<literal>pkgs.cosmoc</literal>.
</para>
</listitem>
</itemizedlist>
</section>
<section xml:id="sec-release-22.05-notable-changes">

View File

@ -444,6 +444,8 @@ In addition to numerous new and upgraded packages, this release has the followin
See the `vscode` package for a more detailed example.
- `pkgs.cosmopolitan` no longer provides the `cosmoc` command. It has been moved to `pkgs.cosmoc`.
<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
## Other Notable Changes {#sec-release-22.05-notable-changes}

View File

@ -0,0 +1,39 @@
{ lib, stdenv, cosmopolitan, unzip, bintools-unwrapped }:
stdenv.mkDerivation rec {
pname = "python-cosmopolitan";
version = "3.6.14";
src = cosmopolitan.dist;
patches = [
./ioctl.patch # required /dev/tty
];
nativeBuildInputs = [ bintools-unwrapped unzip ];
# slashes are significant because upstream uses o/$(MODE)/foo.o
buildFlags = "o//third_party/python";
checkTarget = "o//third_party/python/test";
enableParallelBuilding = true;
doCheck = true;
dontConfigure = true;
dontFixup = true;
installPhase = ''
runHook preInstall
install o/third_party/python/*.com -Dt $out/bin
runHook postInstall
'';
meta = with lib; {
homepage = "https://justine.lol/cosmopolitan/";
description = "Actually Portable Python using Cosmopolitan";
platforms = platforms.x86_64;
badPlatforms = platforms.darwin;
license = licenses.isc;
maintainers = teams.cosmopolitan.members;
mainProgram = "python.com";
};
}

View File

@ -1,4 +1,4 @@
{ lib, stdenv, fetchFromGitHub, runCommand, unzip, cosmopolitan,bintools-unwrapped }:
{ lib, stdenv, fetchFromGitHub, unzip, bintools-unwrapped }:
stdenv.mkDerivation rec {
pname = "cosmopolitan";
@ -11,72 +11,35 @@ stdenv.mkDerivation rec {
sha256 = "sha256-UjL4wR5HhuXiQXg6Orcx2fKiVGRPMJk15P779BP1fRA=";
};
patches = [
./ioctl.patch # required /dev/tty
];
nativeBuildInputs = [ bintools-unwrapped unzip ];
postPatch = ''
patchShebangs build/
'';
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;
enableParallelBuilding = true;
nativeBuildInputs = [ bintools-unwrapped unzip ];
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 \
-I $out/include \
$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
find -iname "*.h" -type f -exec install -m644 -D {} $out/include/{} \;
find -iname "*.inc" -type f -exec install -m644 -D {} $out/include/{} \;
cp -RT . "$dist"
runHook postInstall
'';
passthru.tests = lib.optionalAttrs (stdenv.buildPlatform == stdenv.hostPlatform) {
hello = runCommand "hello-world" { } ''
printf '#include "libc/stdio/stdio.h"\nmain() { printf("hello world\\n"); }\n' >hello.c
${stdenv.cc}/bin/gcc -g -O -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone -o hello.com.dbg hello.c \
-fuse-ld=bfd -Wl,-T,${cosmopolitan}/lib/ape.lds \
-include ${cosmopolitan}/include/cosmopolitan.h \
-I ${cosmopolitan}/include \
${cosmopolitan}/lib/{crt.o,ape.o,cosmopolitan.a}
${stdenv.cc.bintools.bintools_bin}/bin/objcopy -S -O binary hello.com.dbg hello.com
./hello.com
printf "test successful" > $out
'';
cosmoc = runCommand "cosmoc-hello" { } ''
printf '#include "libc/stdio/stdio.h"\nmain() { printf("hello world\\n"); }\n' >hello.c
${cosmopolitan}/bin/cosmoc hello.c
./a.out
printf "test successful" > $out
'';
};
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 = with maintainers; [ lourkeur tomberek ];
maintainers = teams.cosmopolitan.members;
};
}

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 = teams.cosmopolitan.members;
};
}

View File

@ -16534,8 +16534,12 @@ with pkgs;
cog = callPackage ../development/web/cog { };
cosmoc = callPackage ../development/tools/cosmoc { };
cosmopolitan = callPackage ../development/libraries/cosmopolitan { };
python-cosmopolitan = callPackage ../development/interpreters/python-cosmopolitan { };
ctl = callPackage ../development/libraries/ctl { };
ctpp2 = callPackage ../development/libraries/ctpp2 { };