diff --git a/pkgs/by-name/pi/picolibc/package.nix b/pkgs/by-name/pi/picolibc/package.nix index 61dc6fe8c136..9e1294eea70b 100644 --- a/pkgs/by-name/pi/picolibc/package.nix +++ b/pkgs/by-name/pi/picolibc/package.nix @@ -15,6 +15,7 @@ let canExecute = stdenvNoLibc.buildPlatform.canExecute stdenvNoLibc.hostPlatform; + isHosted = !stdenvNoLibc.hostPlatform.isNone; in stdenvNoLibc.mkDerivation (finalAttrs: { pname = "picolibc"; @@ -43,8 +44,14 @@ stdenvNoLibc.mkDerivation (finalAttrs: { ]; mesonFlags = [ - # Always non-default from upstream - (lib.mesonBool "use-stdlib" true) + # use-stdlib builds against a system C library, requiring a Linux-ABI libc + # whose headers we can compile against (libc/native needs statx() & 64-bit + # off_t/time_t)… so native glibc/musl only. + (lib.mesonBool "use-stdlib" ( + isHosted + && stdenvNoLibc.hostPlatform == stdenvNoLibc.buildPlatform + && (stdenvNoLibc.hostPlatform.libc == "glibc" || stdenvNoLibc.hostPlatform.libc == "musl") + )) (lib.mesonOption "specsdir" "${placeholder "dev"}/lib") # Multi-lib (cross-compilation) @@ -53,17 +60,23 @@ stdenvNoLibc.mkDerivation (finalAttrs: { (lib.mesonOption "multilib-exclude" (lib.concatStringsSep "," multilib-exclude)) # Platform-dependent: picolibc defaults are for bare-metal; adjust for - # hosted (non-none) platforms. - (lib.mesonBool "picolib" stdenvNoLibc.hostPlatform.isNone) - (lib.mesonBool "semihost" stdenvNoLibc.hostPlatform.isNone) - (lib.mesonBool "picocrt" stdenvNoLibc.hostPlatform.isNone) - (lib.mesonBool "posix-console" (!stdenvNoLibc.hostPlatform.isNone)) - (lib.mesonOption "tls-model" ( - if stdenvNoLibc.hostPlatform.isNone then "local-exec" else "global-dynamic" - )) - (lib.mesonOption "errno-function" ( - if stdenvNoLibc.hostPlatform.isNone then "false" else "auto" - )) + # hosted platforms. + (lib.mesonBool "semihost" (!isHosted)) + (lib.mesonBool "picocrt" (!isHosted)) + (lib.mesonBool "posix-console" isHosted) + (lib.mesonBool "initfini-array" (!isHosted)) + (lib.mesonOption "tls-model" (if isHosted then "global-dynamic" else "local-exec")) + (lib.mesonOption "errno-function" (if isHosted then "auto" else "false")) + + # For hosted builds, disable os-fallback since sbrk.c in the fallback + # library references __heap_start/__heap_end which are only defined for + # bare-metal targets with an internal heap. + (lib.mesonOption "os-fallback" (if isHosted then "false" else "auto")) + ] + ++ lib.optionals (stdenvNoLibc.hostPlatform.libc == "fblibc") [ + # Linkless cross toolchain: meson’s TLS auto-detect enables TLS then + # rejects -ftls-model; fall back to non-thread-local errno. + (lib.mesonBool "thread-local-storage" false) ] ++ lib.optionals finalAttrs.doCheck [ (lib.mesonBool "tests" true) @@ -73,12 +86,17 @@ stdenvNoLibc.mkDerivation (finalAttrs: { (lib.mesonOption "tests-cdefs" "false") ]; - doCheck = stdenvNoLibc.buildPlatform.canExecute stdenvNoLibc.hostPlatform; + # The cross no-libc toolchains cannot link (no crt files), so meson’s + # link-based probes (meaning the --defsym alias check that enables the printf + # tests) all fail. Keep tests on the native build only. + doCheck = canExecute && stdenvNoLibc.hostPlatform == stdenvNoLibc.buildPlatform; passthru = { updateScript = nix-update-script { }; tests = { arm = pkgsCross.arm-embedded.picolibc; + musl64 = pkgsCross.musl64.picolibc; + riscv64 = pkgsCross.riscv64-embedded.picolibc; }; }; @@ -97,6 +115,7 @@ stdenvNoLibc.mkDerivation (finalAttrs: { bsd3 ]; maintainers = with lib.maintainers; [ toastal ]; + badPlatforms = [ lib.systems.inspect.patterns.isMinGW ]; # https://github.com/picolibc/picolibc/tree/${finalAttrs.version}?tab=readme-ov-file#supported-architectures platforms = lib.platforms.all; };