2022-06-26 10:26:21 +00:00
{ stdenv
, lib
2024-01-13 08:15:51 +00:00
, fetchzip
2022-06-26 10:26:21 +00:00
, fetchpatch
2023-07-15 17:15:38 +00:00
, meson
, ninja
2022-06-26 10:26:21 +00:00
, flex
, bison
, pkg-config
, which
, pythonSupport ? false
, python ? null
, swig
, libyaml
2020-04-24 23:36:52 +00:00
} :
2023-07-15 17:15:38 +00:00
stdenv . mkDerivation ( finalAttrs : {
2020-04-24 23:36:52 +00:00
pname = " d t c " ;
2023-07-15 17:15:38 +00:00
version = " 1 . 7 . 0 " ;
2020-04-24 23:36:52 +00:00
2024-01-13 08:15:51 +00:00
src = fetchzip {
url = " h t t p s : / / g i t . k e r n e l . o r g / p u b / s c m / u t i l s / d t c / d t c . g i t / s n a p s h o t / d t c - v ${ finalAttrs . version } . t a r . g z " ;
2023-07-15 17:15:38 +00:00
sha256 = " s h a 2 5 6 - F M h 3 V v l Y 3 f U K 8 f b d 0 M + a C m l U r m G 9 Y e g i O O Q 7 M O B y f f c = " ;
2020-04-24 23:36:52 +00:00
} ;
2024-07-27 06:49:29 +00:00
# Big pile of backports.
# FIXME: remove all of these after next upstream release.
patches = let
fetchUpstreamPatch = { rev , hash }: fetchpatch {
name = " d t c - ${ rev } . p a t c h " ;
url = " h t t p s : / / g i t . k e r n e l . o r g / p u b / s c m / u t i l s / d t c / d t c . g i t / p a t c h / ? i d = ${ rev } " ;
inherit hash ;
} ;
in [
2023-07-15 17:15:38 +00:00
# meson: Fix cell overflow tests when running from meson
2024-07-27 06:49:29 +00:00
( fetchUpstreamPatch {
rev = " 3 2 1 7 4 a 6 6 e f a 4 a d 1 9 f c 6 a 2 a 6 4 2 2 e 4 a f 2 a e 4 f 0 5 5 c b " ;
hash = " s h a 2 5 6 - C 7 O z w Y 0 z q + 2 C V 3 S B 5 u n I 7 I l l 2 M 3 d e F 7 F X e Q E 3 B / K x 2 s = " ;
2023-07-15 17:15:38 +00:00
} )
2022-07-14 12:49:19 +00:00
2023-07-15 17:15:38 +00:00
# Use #ifdef NO_VALGRIND
2024-07-27 06:49:29 +00:00
( fetchUpstreamPatch {
rev = " 4 1 8 2 1 8 2 1 1 0 1 a d 8 a 9 f 8 3 7 4 6 b 9 6 b 1 6 3 e 5 b c b d b e 8 0 4 " ;
hash = " s h a 2 5 6 - 7 Q E F D t a p 2 D W b U G q t y T / R g J Z J F l d K B 8 o S u b K i C t L Z 0 w 4 = " ;
2023-07-15 17:15:38 +00:00
} )
# dtc: Fix linker options so it also works in Darwin
2024-07-27 06:49:29 +00:00
( fetchUpstreamPatch {
rev = " 7 1 a 8 b 8 e f 0 a d f 0 1 a f 4 c 7 8 c 7 3 9 e 0 4 5 3 3 a 3 5 c 1 d c 8 9 c " ;
hash = " s h a 2 5 6 - u L X L 0 S j c n + b n M u F + A 6 P j U W 1 R q 6 u N g 1 d Q l 5 8 z b e Y p P / U = " ;
2023-07-15 17:15:38 +00:00
} )
# meson: allow disabling tests
2024-07-27 06:49:29 +00:00
( fetchUpstreamPatch {
rev = " b d c 5 c 8 7 9 3 a 1 3 a b b 8 8 4 6 d 1 1 5 b 7 9 2 3 d f 8 7 6 0 5 d 0 5 b d " ;
hash = " s h a 2 5 6 - c O 4 f / j J X / p Q L 7 k k 4 j p K U h s C V E S W 2 Z u W a T r 7 z 3 B u v V k w = " ;
2023-07-15 17:15:38 +00:00
} )
2024-05-15 15:35:15 +00:00
2024-07-27 06:49:29 +00:00
# meson: fix installation with meson-python
( fetchUpstreamPatch {
rev = " 3 f b f d d 0 8 a f d 2 a 7 a 2 5 b 2 7 4 3 3 f 6 f 5 6 7 8 c 0 f e 6 9 4 7 2 1 " ;
2024-05-15 15:35:15 +00:00
hash = " s h a 2 5 6 - s k K 8 m 1 s 4 x k K 6 x 9 A q z x i E K + 1 u M E m S 2 7 d B I 1 C d E X N F T f U = " ;
} )
2024-07-27 06:49:29 +00:00
# pylibfdt: fix get_mem_rsv for newer Python versions
( fetchUpstreamPatch {
rev = " 8 2 2 1 2 3 8 5 6 9 8 0 f 8 4 5 6 2 4 0 6 c c 7 b d 1 d 4 d 6 c 2 b 8 b c 1 8 4 " ;
hash = " s h a 2 5 6 - I J p R g P 3 p P 8 E e w x 2 P N K x h X Z d s n o m z 2 A R 6 o O s u n 5 0 q A m s = " ;
} )
2022-06-26 10:26:21 +00:00
] ;
2023-07-15 17:15:38 +00:00
env . SETUPTOOLS_SCM_PRETEND_VERSION = finalAttrs . version ;
nativeBuildInputs = [
meson
ninja
flex
bison
pkg-config
which
] ++ lib . optionals pythonSupport [
python
python . pkgs . setuptools-scm
swig
] ;
2022-06-26 10:26:21 +00:00
2021-04-12 18:23:04 +00:00
buildInputs = [ libyaml ] ;
2020-04-24 23:36:52 +00:00
postPatch = ''
2023-07-15 17:15:38 +00:00
patchShebangs setup . py
# meson.build: bump version to 1.7.0
substituteInPlace libfdt/meson.build \
- - replace " v e r s i o n : ' 1 . 6 . 0 ' , " " v e r s i o n : ' ${ finalAttrs . version } ' , "
substituteInPlace meson . build \
- - replace " v e r s i o n : ' 1 . 6 . 0 ' , " " v e r s i o n : ' ${ finalAttrs . version } ' , "
2020-04-24 23:36:52 +00:00
'' ;
2023-07-15 17:15:38 +00:00
# Required for installation of Python library and is innocuous otherwise.
env . DESTDIR = " / " ;
2020-04-24 23:36:52 +00:00
2023-07-15 17:15:38 +00:00
mesonAutoFeatures = " a u t o " ;
mesonFlags = [
( lib . mesonBool " s t a t i c - b u i l d " stdenv . hostPlatform . isStatic )
( lib . mesonBool " t e s t s " finalAttrs . finalPackage . doCheck )
] ;
doCheck =
# Checks are broken on aarch64 darwin
# https://github.com/NixOS/nixpkgs/pull/118700#issuecomment-885892436
2024-09-26 11:04:55 +00:00
! stdenv . hostPlatform . isDarwin &&
2024-09-19 14:19:46 +00:00
# Checks are broken when building statically on x86_64 linux with musl
# One of the test tries to build a shared library and this causes the linker:
# x86_64-unknown-linux-musl-ld: /nix/store/h9gcvnp90mpniyx2v0d0p3s06hkx1v2p-x86_64-unknown-linux-musl-gcc-13.3.0/lib/gcc/x86_64-unknown-linux-musl/13.3.0/crtbeginT.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a shared object
# x86_64-unknown-linux-musl-ld: failed to set dynamic section sizes: bad value
! stdenv . hostPlatform . isStatic &&
2022-09-14 18:05:37 +00:00
2023-07-15 17:15:38 +00:00
# we must explicitly disable this here so that mesonFlags receives
# `-Dtests=disabled`; without it meson will attempt to run
# hostPlatform binaries during the configurePhase.
( with stdenv ; buildPlatform . canExecute hostPlatform ) ;
2021-04-12 18:23:04 +00:00
2020-04-24 23:36:52 +00:00
meta = with lib ; {
description = " D e v i c e T r e e C o m p i l e r " ;
2022-06-16 17:23:12 +00:00
homepage = " h t t p s : / / g i t . k e r n e l . o r g / p u b / s c m / u t i l s / d t c / d t c . g i t " ;
2021-04-12 18:23:04 +00:00
license = licenses . gpl2Plus ; # dtc itself is GPLv2, libfdt is dual GPL/BSD
2020-04-24 23:36:52 +00:00
maintainers = [ maintainers . dezgeg ] ;
platforms = platforms . unix ;
2024-04-21 15:54:59 +00:00
mainProgram = " d t c " ;
2020-04-24 23:36:52 +00:00
} ;
2023-07-15 17:15:38 +00:00
} )