Unverified Commit e427a1d3 authored by Tristan Ross's avatar Tristan Ross Committed by GitHub
Browse files

llvmPackages.libc: init at 20.0.0-unstable-2024-12-08 (#363449)

parents 91df0dc2 41b14024
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ let
        else if final.isMusl                  then "musl"
        else if final.isUClibc                then "uclibc"
        else if final.isAndroid               then "bionic"
        else if final.isLLVMLibc              then "llvm"
        else if final.isLinux  /* default */  then "glibc"
        else if final.isFreeBSD               then "fblibc"
        else if final.isOpenBSD               then "oblibc"
+1 −0
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ rec {
    isGnu          = with abis; map (a: { abi = a; }) [ gnuabi64 gnuabin32 gnu gnueabi gnueabihf gnuabielfv1 gnuabielfv2 ];
    isMusl         = with abis; map (a: { abi = a; }) [ musl musleabi musleabihf muslabin32 muslabi64 ];
    isUClibc       = with abis; map (a: { abi = a; }) [ uclibc uclibceabi uclibceabihf ];
    isLLVMLibc     = [ { abi = abis.llvm; } ];

    isEfi = [
      { cpu = { family = "arm"; version = "6"; }; }
+3 −0
Original line number Diff line number Diff line
@@ -416,6 +416,9 @@ rec {
    uclibceabihf = { float = "hard"; };
    uclibc       = {};

    # LLVM libc
    llvm         = {};

    unknown = {};
  };

+127 −114
Original line number Diff line number Diff line
@@ -1075,6 +1075,7 @@ let
          relative = "compiler-rt";
        });
    in
    (
      {
        compiler-rt-libc = callPackage ./compiler-rt (
          let
@@ -1204,6 +1205,18 @@ let
                );
        };
      }
      // lib.optionalAttrs (lib.versionAtLeast metadata.release_version "20") {
        libc-overlay = callPackage ./libc {
          isFullBuild = false;
        };

        libc-full = callPackage ./libc {
          isFullBuild = true;
        };

        libc = if stdenv.targetPlatform.libc == "llvm" then libraries.libc-full else libraries.libc-overlay;
      }
    )
  );

  noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ];
+95 −0
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  llvm_meta,
  src ? null,
  monorepoSrc ? null,
  version,
  release_version,
  runCommand,
  python3,
  python3Packages,
  patches ? [ ],
  cmake,
  ninja,
  isFullBuild ? true,
  linuxHeaders,
}:
let
  pname = "libc";

  src' = runCommand "${pname}-src-${version}" { } (''
    mkdir -p "$out"
    cp -r ${monorepoSrc}/cmake "$out"
    cp -r ${monorepoSrc}/runtimes "$out"
    cp -r ${monorepoSrc}/llvm "$out"
    cp -r ${monorepoSrc}/${pname} "$out"
  '');

  stdenv' =
    if stdenv.cc.isClang then
      stdenv.override {
        cc = stdenv.cc.override {
          nixSupport = stdenv.cc.nixSupport // {
            cc-cflags = lib.remove "-lunwind" stdenv.cc.nixSupport.cc-cflags;
          };
        };
      }
    else
      stdenv;
in
stdenv'.mkDerivation (finalAttrs: {
  inherit pname version patches;

  src = src';

  sourceRoot = "${finalAttrs.src.name}/runtimes";

  nativeBuildInputs =
    [
      cmake
      python3
    ]
    ++ (lib.optional (lib.versionAtLeast release_version "15") ninja)
    ++ (lib.optional isFullBuild python3Packages.pyyaml);

  buildInputs = lib.optional isFullBuild linuxHeaders;

  outputs = [ "out" ] ++ (lib.optional isFullBuild "dev");

  postUnpack = lib.optionalString isFullBuild ''
    patchShebangs $sourceRoot/../$pname/hdrgen/yaml_to_classes.py
    chmod +x $sourceRoot/../$pname/hdrgen/yaml_to_classes.py
  '';

  prePatch = ''
    cd ../${finalAttrs.pname}
    chmod -R u+w ../
  '';

  postPatch = ''
    cd ../runtimes
  '';

  postInstall = lib.optionalString (!isFullBuild) ''
    substituteAll ${./libc-shim.so} $out/lib/libc.so
  '';

  libc = if (!isFullBuild) then stdenv.cc.libc else null;

  cmakeFlags = [
    (lib.cmakeBool "LLVM_LIBC_FULL_BUILD" isFullBuild)
    (lib.cmakeFeature "LLVM_ENABLE_RUNTIMES" "libc")
  ];

  # For the update script:
  passthru = {
    monorepoSrc = monorepoSrc;
    inherit isFullBuild;
  };

  meta = llvm_meta // {
    homepage = "https://libc.llvm.org/";
    description = "Standard C library for LLVM";
  };
})
Loading