Skip to content

Add Meson build #604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
Expand All @@ -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);
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions maintainers/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
36 changes: 36 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions meson.format
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions meson.options
Original file line number Diff line number Diff line change
@@ -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 changes: 17 additions & 0 deletions package-meson.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
stdenv,
meson,
ninja,
version,
src,
}:

stdenv.mkDerivation {
pname = "patchelf";
inherit version src;
nativeBuildInputs = [
meson
ninja
];
doCheck = true;
}
18 changes: 18 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -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,
)
Loading