@@ -1,22 +1,44 @@
1−{ lib, stdenv, fetchFromGitHub, fixDarwinDylibNames, compiler ? if stdenv.cc.isClang then "clang" else null, stdver ? null }:
1+{ lib
2+, stdenv
3+, fetchurl
4+, fetchFromGitHub
5+, fixDarwinDylibNames
6+}:
27
3−with lib; stdenv.mkDerivation rec {
8+stdenv.mkDerivation rec {
49 pname = "tbb";
5− version = "2020_U3";
10+ version = "2020.3";
611
712 src = fetchFromGitHub {
8− owner = "01org";
9− repo = "tbb";
10− rev = version;
11− sha256 = "sha256-prO2O5hd+Wz5iA0vfrqmyHFr0Ptzk64so5KpSpvuKmU=";
13+ owner = "oneapi-src";
14+ repo = "oneTBB";
15+ rev = "v${version}";
16+ sha256 = "prO2O5hd+Wz5iA0vfrqmyHFr0Ptzk64so5KpSpvuKmU=";
1217 };
1318
14− nativeBuildInputs = optional stdenv.isDarwin fixDarwinDylibNames;
19+ patches = [
20+ # Fixes build with Musl.
21+ (fetchurl {
22+ url = "https://github.com/openembedded/meta-openembedded/raw/39185eb1d1615e919e3ae14ae63b8ed7d3e5d83f/meta-oe/recipes-support/tbb/tbb/GLIBC-PREREQ-is-not-defined-on-musl.patch";
23+ sha256 = "gUfXQ9OZQ82qD6brgauBCsKdjLvyHafMc18B+KxZoYs=";
24+ })
1525
16− makeFlags = optional (compiler != null) "compiler=${compiler}"
17− ++ optional (stdver != null) "stdver=${stdver}";
26+ # Fixes build with Musl.
27+ (fetchurl {
28+ url = "https://github.com/openembedded/meta-openembedded/raw/39185eb1d1615e919e3ae14ae63b8ed7d3e5d83f/meta-oe/recipes-support/tbb/tbb/0001-mallinfo-is-glibc-specific-API-mark-it-so.patch";
29+ sha256 = "fhorfqO1hHKZ61uq+yTR7eQ8KYdyLwpM3K7WpwJpV74=";
30+ })
31+ ];
1832
19− patches = lib.optional stdenv.hostPlatform.isMusl ./glibc-struct-mallinfo.patch;
33+ nativeBuildInputs = lib.optionals stdenv.isDarwin [
34+ fixDarwinDylibNames
35+ ];
36+
37+ makeFlags = lib.optionals stdenv.cc.isClang [
38+ "compiler=clang"
39+ ];
40+
41+ enableParallelBuilding = true;
2042
2143 installPhase = ''
2244 runHook preInstall
@@ -29,9 +51,24 @@ with lib; stdenv.mkDerivation rec {
2951 runHook postInstall
3052 '';
3153
32− enableParallelBuilding = true;
54+ postInstall = let
55+ pcTemplate = fetchurl {
56+ url = "https://github.com/oneapi-src/oneTBB/raw/master/integration/pkg-config/tbb.pc.in";
57+ sha256 = "2pCad9txSpNbzac0vp/VY3x7HNySaYkbH3Rx8LK53pI=";
58+ };
59+ in ''
60+ # Generate pkg-config file based on upstream template.
61+ # It should not be necessary with tbb after 2021.2.
62+ mkdir -p "$out/lib/pkgconfig"
63+ substitute "${pcTemplate}" "$out/lib/pkgconfig/tbb.pc" \
64+ --subst-var-by CMAKE_INSTALL_PREFIX "$out" \
65+ --subst-var-by CMAKE_INSTALL_LIBDIR "lib" \
66+ --subst-var-by CMAKE_INSTALL_INCLUDEDIR "include" \
67+ --subst-var-by TBB_VERSION "${version}" \
68+ --subst-var-by TBB_LIB_NAME "tbb"
69+ '';
3370
34− meta = {
71+ meta = with lib; {
3572 description = "Intel Thread Building Blocks C++ Library";
3673 homepage = "http://threadingbuildingblocks.org/";
3774 license = licenses.asl20;
@@ -43,7 +80,7 @@ with lib; stdenv.mkDerivation rec {
4380 represents a higher-level, task-based parallelism that abstracts platform
4481 details and threading mechanisms for scalability and performance.
4582 '';
46− platforms = with platforms; linux ++ darwin;
83+ platforms = platforms.unix;
4784 maintainers = with maintainers; [ thoughtpolice dizfer ];
4885 };
4986}