diff options
author | Emily Trau <emily@downunderctf.com> | 2023-09-17 18:59:31 -0700 |
---|---|---|
committer | Emily Trau <emily@downunderctf.com> | 2023-09-17 23:27:36 -0700 |
commit | d999a493b031e766b785c37731b45690451cf869 (patch) | |
tree | f6a6c79bbfe2f987d19e44ab36de2626a5439559 | |
parent | 913e70d77b67722a5b3bd42f21b9ea4cc02046e9 (diff) | |
download | nixpkgs-d999a493b031e766b785c37731b45690451cf869.tar nixpkgs-d999a493b031e766b785c37731b45690451cf869.tar.gz nixpkgs-d999a493b031e766b785c37731b45690451cf869.tar.bz2 nixpkgs-d999a493b031e766b785c37731b45690451cf869.tar.lz nixpkgs-d999a493b031e766b785c37731b45690451cf869.tar.xz nixpkgs-d999a493b031e766b785c37731b45690451cf869.tar.zst nixpkgs-d999a493b031e766b785c37731b45690451cf869.zip |
minimal-bootstrap.tinycc-musl: init at 0.9.27
-rw-r--r-- | pkgs/os-specific/linux/minimal-bootstrap/default.nix | 5 | ||||
-rw-r--r-- | pkgs/os-specific/linux/minimal-bootstrap/tinycc/musl.nix | 155 |
2 files changed, 160 insertions, 0 deletions
diff --git a/pkgs/os-specific/linux/minimal-bootstrap/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/default.nix index b0a6a30a13d..d13e7ae63ba 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/default.nix @@ -162,6 +162,10 @@ lib.makeScope tinycc-bootstrappable = lib.recurseIntoAttrs (callPackage ./tinycc/bootstrappable.nix { }); tinycc-mes = lib.recurseIntoAttrs (callPackage ./tinycc/mes.nix { }); + tinycc-musl = lib.recurseIntoAttrs (callPackage ./tinycc/musl.nix { + bash = bash_2_05; + musl = musl11; + }); xz = callPackage ./xz { bash = bash_2_05; @@ -194,6 +198,7 @@ lib.makeScope echo ${mes.compiler.tests.get-version} echo ${musl.tests.hello-world} echo ${tinycc-mes.compiler.tests.chain} + echo ${tinycc-musl.compiler.tests.hello-world} echo ${xz.tests.get-version} mkdir ''${out} ''; diff --git a/pkgs/os-specific/linux/minimal-bootstrap/tinycc/musl.nix b/pkgs/os-specific/linux/minimal-bootstrap/tinycc/musl.nix new file mode 100644 index 00000000000..6debf25c36b --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/tinycc/musl.nix @@ -0,0 +1,155 @@ +# Build steps adapted from https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/tcc-0.9.27/tcc-musl-pass1.sh +# +# SPDX-FileCopyrightText: 2021-22 fosslinux <fosslinux@aussies.space> +# +# SPDX-License-Identifier: GPL-3.0-or-later + +{ lib +, fetchurl +, callPackage +, bash +, tinycc-bootstrappable +, musl +, gnupatch +, gnutar +, bzip2 +}: +let + pname = "tinycc-musl"; + version = "0.9.27"; + + src = fetchurl { + url = "https://download.savannah.gnu.org/releases/tinycc/tcc-${version}.tar.bz2"; + hash = "sha256-3iOvePypDOMt/y3UWzQysjNHQLubt7Bb9g/b/Dls65w="; + }; + + # Thanks to the live-bootstrap project! + # See https://github.com/fosslinux/live-bootstrap/blob/424aa5be38a3023aa6842883a3954599b1597986/sysa/tcc-0.9.27/tcc-musl-pass1.sh + liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/424aa5be38a3023aa6842883a3954599b1597986/sysa/tcc-0.9.27"; + patches = [ + (fetchurl { + url = "${liveBootstrap}/patches/ignore-duplicate-symbols.patch"; + hash = "sha256-6Js8HkzjYlA8ETxeEYRWu+03OJI60NvR5h1QPkcMTlQ="; + }) + (fetchurl { + url = "${liveBootstrap}/patches/ignore-static-inside-array.patch"; + hash = "sha256-IF4RevLGjzRBuYqhuyG7+x6SVljzMAsYRKicNsmtbDY="; + }) + (fetchurl { + url = "${liveBootstrap}/patches/static-link.patch"; + hash = "sha256-gX/hJ9a/0Zg29KIBUme+mOA8WrPQvp0SvojP8DN9mSI="; + }) + ]; + + meta = with lib; { + description = "Small, fast, and embeddable C compiler and interpreter"; + homepage = "http://savannah.nongnu.org/projects/tinycc"; + license = licenses.lgpl21Only; + maintainers = teams.minimal-bootstrap.members; + platforms = [ "i686-linux" ]; + }; + + tinycc-musl = bash.runCommand "${pname}-${version}" { + inherit pname version meta; + + nativeBuildInputs = [ + tinycc-bootstrappable.compiler + gnupatch + gnutar + bzip2 + ]; + } '' + # Unpack + cp ${src} tinycc.tar.bz2 + bunzip2 tinycc.tar.bz2 + tar xf tinycc.tar + rm tinycc.tar + cd tcc-${version} + + # Patch + ${lib.concatMapStringsSep "\n" (f: "patch -Np0 -i ${f}") patches} + + # Configure + touch config.h + + # Build + # We first have to recompile using tcc-0.9.26 as tcc-0.9.27 is not self-hosting, + # but when linked with musl it is. + ln -s ${musl}/lib/libtcc1.a ./libtcc1.a + + tcc -v \ + -static \ + -o tcc-musl \ + -D TCC_TARGET_I386=1 \ + -D CONFIG_TCCDIR=\"\" \ + -D CONFIG_TCC_CRTPREFIX=\"{B}\" \ + -D CONFIG_TCC_ELFINTERP=\"/musl/loader\" \ + -D CONFIG_TCC_LIBPATHS=\"{B}\" \ + -D CONFIG_TCC_SYSINCLUDEPATHS=\"${musl}/include\" \ + -D TCC_LIBGCC=\"libc.a\" \ + -D TCC_LIBTCC1=\"libtcc1.a\" \ + -D CONFIG_TCC_STATIC=1 \ + -D CONFIG_USE_LIBGCC=1 \ + -D TCC_VERSION=\"0.9.27\" \ + -D ONE_SOURCE=1 \ + -B . \ + -B ${tinycc-bootstrappable.libs}/lib \ + tcc.c + # libtcc1.a + rm -f libtcc1.a + tcc -c -D HAVE_CONFIG_H=1 lib/libtcc1.c + tcc -ar cr libtcc1.a libtcc1.o + + # Rebuild tcc-musl with itself + ./tcc-musl \ + -v \ + -static \ + -o tcc-musl \ + -D TCC_TARGET_I386=1 \ + -D CONFIG_TCCDIR=\"\" \ + -D CONFIG_TCC_CRTPREFIX=\"{B}\" \ + -D CONFIG_TCC_ELFINTERP=\"/musl/loader\" \ + -D CONFIG_TCC_LIBPATHS=\"{B}\" \ + -D CONFIG_TCC_SYSINCLUDEPATHS=\"${musl}/include\" \ + -D TCC_LIBGCC=\"libc.a\" \ + -D TCC_LIBTCC1=\"libtcc1.a\" \ + -D CONFIG_TCC_STATIC=1 \ + -D CONFIG_USE_LIBGCC=1 \ + -D TCC_VERSION=\"0.9.27\" \ + -D ONE_SOURCE=1 \ + -B . \ + -B ${musl}/lib \ + tcc.c + # libtcc1.a + rm -f libtcc1.a + ./tcc-musl -c -D HAVE_CONFIG_H=1 lib/libtcc1.c + ./tcc-musl -ar cr libtcc1.a libtcc1.o + + # Install + install -D tcc-musl $out/bin/tcc + install -Dm444 libtcc1.a $out/lib/libtcc1.a + ''; +in +{ + compiler = bash.runCommand "${pname}-${version}-compiler" { + inherit pname version meta; + passthru.tests.hello-world = result: + bash.runCommand "${pname}-simple-program-${version}" {} '' + cat <<EOF >> test.c + #include <stdio.h> + int main() { + printf("Hello World!\n"); + return 0; + } + EOF + ${result}/bin/tcc -v -static -B${musl}/lib -o test test.c + ./test + mkdir $out + ''; + passthru.tinycc-musl = tinycc-musl; + } "install -D ${tinycc-musl}/bin/tcc $out/bin/tcc"; + + libs = bash.runCommand "${pname}-${version}-libs" { + inherit pname version meta; + } "install -D ${tinycc-musl}/lib/libtcc1.a $out/lib/libtcc1.a"; +} |