diff options
Diffstat (limited to 'nixpkgs/pkgs/development/tools/build-managers/meson')
6 files changed, 237 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/tools/build-managers/meson/allow-dirs-outside-of-prefix.patch b/nixpkgs/pkgs/development/tools/build-managers/meson/allow-dirs-outside-of-prefix.patch new file mode 100644 index 000000000000..591927c15285 --- /dev/null +++ b/nixpkgs/pkgs/development/tools/build-managers/meson/allow-dirs-outside-of-prefix.patch @@ -0,0 +1,25 @@ +--- a/mesonbuild/coredata.py ++++ b/mesonbuild/coredata.py +@@ -375,18 +375,13 @@ + ''' + if option.endswith('dir') and os.path.isabs(value) and \ + option not in builtin_dir_noprefix_options: +- # Value must be a subdir of the prefix + # commonpath will always return a path in the native format, so we + # must use pathlib.PurePath to do the same conversion before + # comparing. +- if os.path.commonpath([value, prefix]) != str(PurePath(prefix)): +- m = 'The value of the {!r} option is {!r} which must be a ' \ +- 'subdir of the prefix {!r}.\nNote that if you pass a ' \ +- 'relative path, it is assumed to be a subdir of prefix.' +- raise MesonException(m.format(option, value, prefix)) +- # Convert path to be relative to prefix +- skip = len(prefix) + 1 +- value = value[skip:] ++ if os.path.commonpath([value, prefix]) == str(PurePath(prefix)): ++ # Convert path to be relative to prefix ++ skip = len(prefix) + 1 ++ value = value[skip:] + return value + + def init_builtins(self): diff --git a/nixpkgs/pkgs/development/tools/build-managers/meson/default.nix b/nixpkgs/pkgs/development/tools/build-managers/meson/default.nix new file mode 100644 index 000000000000..92a0ae3eb85b --- /dev/null +++ b/nixpkgs/pkgs/development/tools/build-managers/meson/default.nix @@ -0,0 +1,92 @@ +{ lib, python3Packages, stdenv, writeTextDir, substituteAll, targetPackages }: + +python3Packages.buildPythonApplication rec { + version = "0.49.2"; + pname = "meson"; + + src = python3Packages.fetchPypi { + inherit pname version; + sha256 = "0ckkzq0kbnnk4rwv20lggm9a4fb5054jbv99i9pwjhid23qy7059"; + }; + + postFixup = '' + pushd $out/bin + # undo shell wrapper as meson tools are called with python + for i in *; do + mv ".$i-wrapped" "$i" + done + popd + + # Do not propagate Python + rm $out/nix-support/propagated-build-inputs + ''; + + patches = [ + # Upstream insists on not allowing bindir and other dir options + # outside of prefix for some reason: + # https://github.com/mesonbuild/meson/issues/2561 + # We remove the check so multiple outputs can work sanely. + ./allow-dirs-outside-of-prefix.patch + + # Unlike libtool, vanilla Meson does not pass any information + # about the path library will be installed to to g-ir-scanner, + # breaking the GIR when path other than ${!outputLib}/lib is used. + # We patch Meson to add a --fallback-library-path argument with + # library install_dir to g-ir-scanner. + ./gir-fallback-path.patch + + # In common distributions, RPATH is only needed for internal libraries so + # meson removes everything else. With Nix, the locations of libraries + # are not as predictable, therefore we need to keep them in the RPATH. + # At the moment we are keeping the paths starting with /nix/store. + # https://github.com/NixOS/nixpkgs/issues/31222#issuecomment-365811634 + (substituteAll { + src = ./fix-rpath.patch; + inherit (builtins) storeDir; + }) + ] ++ lib.optionals stdenv.isDarwin [ + # We use custom Clang, which makes Meson think *not Apple*, while still + # relying on system linker. When it detects standard Clang, Meson will + # pass it `-Wl,-O1` flag but optimizations are not recognized by + # Mac linker. + # https://github.com/mesonbuild/meson/issues/4784 + ./fix-objc-linking.patch + ]; + + setupHook = ./setup-hook.sh; + + crossFile = writeTextDir "cross-file.conf" '' + [binaries] + c = '${targetPackages.stdenv.cc.targetPrefix}cc' + cpp = '${targetPackages.stdenv.cc.targetPrefix}c++' + ar = '${targetPackages.stdenv.cc.bintools.targetPrefix}ar' + strip = '${targetPackages.stdenv.cc.bintools.targetPrefix}strip' + pkgconfig = 'pkg-config' + + [properties] + needs_exe_wrapper = true + + [host_machine] + system = '${targetPackages.stdenv.targetPlatform.parsed.kernel.name}' + cpu_family = '${targetPackages.stdenv.targetPlatform.parsed.cpu.family}' + cpu = '${targetPackages.stdenv.targetPlatform.parsed.cpu.name}' + endian = ${if targetPackages.stdenv.targetPlatform.isLittleEndian then "'little'" else "'big'"} + ''; + + # 0.45 update enabled tests but they are failing + doCheck = false; + # checkInputs = [ ninja pkgconfig ]; + # checkPhase = "python ./run_project_tests.py"; + + inherit (stdenv) cc; + + isCross = stdenv.targetPlatform != stdenv.hostPlatform; + + meta = with lib; { + homepage = http://mesonbuild.com; + description = "SCons-like build system that use python as a front-end language and Ninja as a building backend"; + license = licenses.asl20; + maintainers = with maintainers; [ mbe rasendubi ]; + platforms = platforms.all; + }; +} diff --git a/nixpkgs/pkgs/development/tools/build-managers/meson/fix-objc-linking.patch b/nixpkgs/pkgs/development/tools/build-managers/meson/fix-objc-linking.patch new file mode 100644 index 000000000000..60a205828f5d --- /dev/null +++ b/nixpkgs/pkgs/development/tools/build-managers/meson/fix-objc-linking.patch @@ -0,0 +1,20 @@ +--- a/mesonbuild/environment.py ++++ b/mesonbuild/environment.py +@@ -795,7 +795,7 @@ + compiler_type = self.get_gnu_compiler_type(defines) + version = self.get_gnu_version_from_defines(defines) + return GnuObjCCompiler(ccache + compiler, version, compiler_type, is_cross, exe_wrap, defines) +- if out.startswith('Apple LLVM'): ++ if out.startswith('Apple LLVM') or mesonlib.for_darwin(want_cross, self): + return ClangObjCCompiler(ccache + compiler, version, CompilerType.CLANG_OSX, is_cross, exe_wrap) + if out.startswith('clang'): + return ClangObjCCompiler(ccache + compiler, version, CompilerType.CLANG_STANDARD, is_cross, exe_wrap) +@@ -822,7 +822,7 @@ + compiler_type = self.get_gnu_compiler_type(defines) + version = self.get_gnu_version_from_defines(defines) + return GnuObjCPPCompiler(ccache + compiler, version, compiler_type, is_cross, exe_wrap, defines) +- if out.startswith('Apple LLVM'): ++ if out.startswith('Apple LLVM') or mesonlib.for_darwin(want_cross, self): + return ClangObjCPPCompiler(ccache + compiler, version, CompilerType.CLANG_OSX, is_cross, exe_wrap) + if out.startswith('clang'): + return ClangObjCPPCompiler(ccache + compiler, version, CompilerType.CLANG_STANDARD, is_cross, exe_wrap) diff --git a/nixpkgs/pkgs/development/tools/build-managers/meson/fix-rpath.patch b/nixpkgs/pkgs/development/tools/build-managers/meson/fix-rpath.patch new file mode 100644 index 000000000000..1a5f8cb89dce --- /dev/null +++ b/nixpkgs/pkgs/development/tools/build-managers/meson/fix-rpath.patch @@ -0,0 +1,43 @@ +--- a/mesonbuild/compilers/compilers.py ++++ b/mesonbuild/compilers/compilers.py +@@ -1202,8 +1202,10 @@ + # In order to avoid relinking for RPATH removal, the binary needs to contain just + # enough space in the ELF header to hold the final installation RPATH. + paths = ':'.join(all_paths) +- if len(paths) < len(install_rpath): +- padding = 'X' * (len(install_rpath) - len(paths)) ++ store_paths = ':'.join(filter(lambda path: path.startswith('@storeDir@'), all_paths)) ++ extra_space_needed = len(install_rpath + (':' if install_rpath and store_paths else '') + store_paths) - len(paths) ++ if extra_space_needed > 0: ++ padding = 'X' * extra_space_needed + if not paths: + paths = padding + else: +--- a/mesonbuild/scripts/depfixer.py ++++ b/mesonbuild/scripts/depfixer.py +@@ -303,6 +303,14 @@ + return + self.bf.seek(rp_off) + old_rpath = self.read_str() ++ ++ if new_rpath: ++ new_rpath += b':' ++ else: ++ new_rpath = b'' ++ ++ new_rpath += b':'.join(filter(lambda path: path.startswith(b'@storeDir@'), old_rpath.split(b':'))) ++ + if len(old_rpath) < len(new_rpath): + sys.exit("New rpath must not be longer than the old one.") + # The linker does read-only string deduplication. If there is a +@@ -316,6 +324,10 @@ + if not new_rpath: + self.remove_rpath_entry(entrynum) + else: ++ # clean old rpath to avoid stale references ++ # (see https://github.com/NixOS/nixpkgs/pull/46020) ++ self.bf.seek(rp_off) ++ self.bf.write(b'\0'*len(old_rpath)) + self.bf.seek(rp_off) + self.bf.write(new_rpath) + self.bf.write(b'\0') diff --git a/nixpkgs/pkgs/development/tools/build-managers/meson/gir-fallback-path.patch b/nixpkgs/pkgs/development/tools/build-managers/meson/gir-fallback-path.patch new file mode 100644 index 000000000000..7a33d4127fae --- /dev/null +++ b/nixpkgs/pkgs/development/tools/build-managers/meson/gir-fallback-path.patch @@ -0,0 +1,16 @@ +--- a/mesonbuild/modules/gnome.py ++++ b/mesonbuild/modules/gnome.py +@@ -805,6 +805,13 @@ + scan_command += self._scan_langs(state, [lc[0] for lc in langs_compilers]) + scan_command += list(external_ldflags) + ++ if len(set([girtarget.get_custom_install_dir()[0] for girtarget in girtargets])) > 1: ++ raise MesonException('generate_gir tries to build multiple libraries with different install_dir at once: {}'.format(','.join([str(girtarget) for girtarget in girtargets]))) ++ ++ fallback_libpath = girtargets[0].get_custom_install_dir()[0] ++ if fallback_libpath is not None and isinstance(fallback_libpath, str) and len(fallback_libpath) > 0 and fallback_libpath[0] == "/": ++ scan_command += ['--fallback-library-path=' + fallback_libpath] ++ + scan_target = self._make_gir_target(state, girfile, scan_command, depends, kwargs) + + typelib_output = '%s-%s.typelib' % (ns, nsversion) diff --git a/nixpkgs/pkgs/development/tools/build-managers/meson/setup-hook.sh b/nixpkgs/pkgs/development/tools/build-managers/meson/setup-hook.sh new file mode 100644 index 000000000000..06375c1528e0 --- /dev/null +++ b/nixpkgs/pkgs/development/tools/build-managers/meson/setup-hook.sh @@ -0,0 +1,41 @@ +mesonConfigurePhase() { + runHook preConfigure + + if [ -z "$dontAddPrefix" ]; then + mesonFlags="--prefix=$prefix $mesonFlags" + fi + + # Build release by default. + if [ -n "@isCross@" ]; then + crossMesonFlags="--cross-file=@crossFile@/cross-file.conf" + fi + + # See multiple-outputs.sh and meson’s coredata.py + mesonFlags="\ + --libdir=${!outputLib}/lib --libexecdir=${!outputLib}/libexec \ + --bindir=${!outputBin}/bin --sbindir=${!outputBin}/sbin \ + --includedir=${!outputInclude}/include \ + --mandir=${!outputMan}/share/man --infodir=${!outputInfo}/share/info \ + --localedir=${!outputLib}/share/locale \ + -Dauto_features=disabled \ + $mesonFlags" + + mesonFlags="${crossMesonFlags+$crossMesonFlags }--buildtype=${mesonBuildType:-release} $mesonFlags" + + echo "meson flags: $mesonFlags ${mesonFlagsArray[@]}" + + CC=@cc@/bin/cc CXX=@cc@/bin/c++ meson build $mesonFlags "${mesonFlagsArray[@]}" + cd build + + if ! [[ -v enableParallelBuilding ]]; then + enableParallelBuilding=1 + echo "meson: enabled parallel building" + fi + + runHook postConfigure +} + +if [ -z "$dontUseMesonConfigure" -a -z "$configurePhase" ]; then + setOutputFlags= + configurePhase=mesonConfigurePhase +fi |