Add Meson build

Progress on #599. Tests still need to be done, though.
This commit is contained in:
John Ericson
2025-08-10 16:49:25 -04:00
parent 2156b8e6ce
commit a7c595db2c
7 changed files with 141 additions and 3 deletions

View File

@@ -36,13 +36,25 @@
./completions
./patchelf.1
./patchelf.spec.in
./src
./tests
(lib.fileset.difference ./src (
lib.fileset.unions [
./src/Makefile.am
./src/meson.build
]
))
(lib.fileset.difference ./tests (
lib.fileset.unions [
./tests/Makefile.am
#./tests/meson.build
]
))
./version
];
autotoolsSrcFiles = [
./Makefile.am
./src/Makefile.am
./tests/Makefile.am
./configure.ac
./m4
];
@@ -51,6 +63,12 @@
./CMakeLists.txt
];
mesonSrcFiles = [
./meson.build
./meson.options
./src/meson.build
];
autotoolsSrc = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions (baseSrcFiles ++ autotoolsSrcFiles);
@@ -89,7 +107,7 @@
inherit version;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions (baseSrcFiles ++ autotoolsSrcFiles ++ cmakeSrcFiles);
fileset = lib.fileset.unions (baseSrcFiles ++ autotoolsSrcFiles ++ cmakeSrcFiles ++ mesonSrcFiles);
};
versionSuffix = ""; # obsolete
preAutoconf = "echo ${version} > version";
@@ -133,6 +151,8 @@
build-cmake = forAllSystems (system: self.packages.${system}.patchelf-cmake);
build-meson = forAllSystems (system: self.packages.${system}.patchelf-meson);
# x86_64-linux seems to be only working clangStdenv at the moment
build-sanitized-clang = lib.genAttrs [ "x86_64-linux" ] (
system:
@@ -151,6 +171,7 @@
self.hydraJobs.build.x86_64-linux
self.hydraJobs.build.i686-linux
self.hydraJobs.build-cmake.x86_64-linux
self.hydraJobs.build-meson.x86_64-linux
# FIXME: add aarch64 emulation to our github action...
#self.hydraJobs.build.aarch64-linux
self.hydraJobs.build-sanitized.x86_64-linux
@@ -190,6 +211,7 @@
};
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
#pkgs.buildPackages.cmake
#pkgs.buildPackages.meson
#pkgs.buildPackages.ninja
modular.pre-commit.settings.package
(pkgs.buildPackages.writeScriptBin "pre-commit-hooks-install" modular.pre-commit.settings.installationScript)
@@ -245,6 +267,14 @@
};
};
patchelf-meson = pkgs.callPackage ./package-meson.nix {
inherit version;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions (baseSrcFiles ++ mesonSrcFiles);
};
};
# This is a good test to see if packages can be cross-compiled. It also
# tests if our testsuite uses target-prefixed executable names.
patchelf-musl-cross = patchelfFor pkgs.pkgsCross.musl64;

View File

@@ -40,6 +40,29 @@
cmake-format = {
enable = true;
};
meson-format =
let
meson = pkgs.meson.overrideAttrs {
doCheck = false;
doInstallCheck = false;
patches = [
(pkgs.fetchpatch {
url = "https://github.com/mesonbuild/meson/commit/38d29b4dd19698d5cad7b599add2a69b243fd88a.patch";
hash = "sha256-PgPBvGtCISKn1qQQhzBW5XfknUe91i5XGGBcaUK4yeE=";
})
];
};
in
{
enable = true;
files = "(meson.build|meson.options)$";
entry = "${pkgs.writeScript "format-meson" ''
#!${pkgs.runtimeShell}
for file in "$@"; do
${lib.getExe meson} format -ic ${../meson.format} "$file"
done
''}";
};
nixfmt-rfc-style = {
enable = true;
};

36
meson.build Normal file
View File

@@ -0,0 +1,36 @@
project(
'patchelf',
'cpp',
'c',
version : files('version'),
default_options : {
'cpp_std' : 'c++17',
'warning_level' : '2',
},
meson_version : '>=1.2',
)
subdir('src')
#subdir('tests') # TODO
install_man('patchelf.1')
#specfile = configure_file(
# output : 'patchelf.spec',
# configuration : {'PACKAGE_VERSION' : meson.project_version()},
#)
# Commented things out should only be for `meson dist`. Need to
# reimplement for that.
install_data(
'README.md',
#'COPYING',
#specfile,
#'version',
install_dir : get_option('datadir') / 'doc' / 'patchelf',
)
install_data(
'completions/zsh/_patchelf',
install_dir : get_option('datadir') / 'zsh' / 'site-functions',
)

7
meson.format Normal file
View File

@@ -0,0 +1,7 @@
indent_by = ' '
space_array = true
kwargs_force_multiline = false
wide_colon = true
group_arg_value = true
indent_before_comments = ' '
use_editor_config = true

7
meson.options Normal file
View File

@@ -0,0 +1,7 @@
option(
'page_size',
type : 'combo',
value : 'auto',
choices : [ 'auto', '4096', '65536', '16384', '8192' ],
description : 'Default page size, or "auto" to detect at runtime',
)

17
package-meson.nix Normal file
View File

@@ -0,0 +1,17 @@
{
stdenv,
meson,
ninja,
version,
src,
}:
stdenv.mkDerivation {
pname = "patchelf";
inherit version src;
nativeBuildInputs = [
meson
ninja
];
doCheck = true;
}

18
src/meson.build Normal file
View File

@@ -0,0 +1,18 @@
# Configure DEFAULT_PAGESIZE via config.h
confdata = configuration_data()
page_size = get_option('page_size')
if page_size != 'auto'
confdata.set_quoted('DEFAULT_PAGESIZE', page_size)
else
# For "auto", leave it undefined so runtime detection happens
endif
config_h = configure_file(output : 'config.h', configuration : confdata)
executable(
'patchelf',
[ 'patchelf.cc', 'patchelf.h', config_h ],
include_directories : include_directories('.'),
cpp_args : [ '-include', meson.current_build_dir() / 'config.h' ],
install : true,
)