darwin.top: convert to Meson and use mkAppleDerivation

This commit is contained in:
Randy Eckenrode 2024-09-22 17:26:02 -04:00
parent 97da1bdf09
commit 29a87d6751
No known key found for this signature in database
GPG Key ID: 64C1CD4EC2A600D9
5 changed files with 122 additions and 20 deletions

View File

@ -316,7 +316,7 @@ developerToolsPackages_11_3_1 // macosPackages_11_0_1 // {
shell_cmds = callPackage ./shell_cmds/package.nix { };
system_cmds = callPackage ./system_cmds/package.nix { };
text_cmds = callPackage ./text_cmds/package.nix { };
top = applePackage "top" "osx-10.11.6" "sha256-jbz64ODogtpNyLpXGSZj1jCBdFPVXcVcBkL1vc7g5qQ=" {};
top = callPackage ./top/package.nix { };
PowerManagement = callPackage ./PowerManagement/package.nix { };
# `configdHeaders` cant use an override because `pkgs.darwin.configd` on aarch64-darwin will

View File

@ -1,19 +0,0 @@
{xcbuildHook, appleDerivation, apple_sdk, ncurses, libutil, lib}:
appleDerivation {
nativeBuildInputs = [ xcbuildHook ];
buildInputs = [ apple_sdk.frameworks.IOKit ncurses libutil ];
# Workaround build failure on -fno-common toolchains:
# duplicate symbol '_tsamp' in: main.o top.o
env.NIX_CFLAGS_COMPILE = "-fcommon";
NIX_LDFLAGS = "-lutil";
installPhase = ''
install -D Products/Release/libtop.a $out/lib/libtop.a
install -D Products/Release/libtop.h $out/include/libtop.h
install -D Products/Release/top $out/bin/top
'';
meta = {
platforms = lib.platforms.darwin;
maintainers = with lib.maintainers; [ matthewbauer ];
};
}

View File

@ -0,0 +1,80 @@
# Build settings based on the upstream Xcode project.
# See: https://github.com/apple-oss-distributions/top/blob/main/top.xcodeproj/project.pbxproj
# Project settings
project('top', 'c', version : '@version@')
# Dependencies
cc = meson.get_compiler('c')
libutil = cc.find_library('util', has_headers : 'libutil.h')
ncurses = [
dependency('ncurses'),
dependency('form'),
dependency('panel'),
]
sdk_frameworks = dependency('appleframeworks', modules : ['CoreFoundation', 'IOKit'])
# Libraries
libtop = static_library(
'top',
sources : [
'libtop.c',
],
)
install_headers(
'libtop.h',
)
# Binaries
top = executable(
'top',
dependencies : [libutil, ncurses, sdk_frameworks],
install : true,
link_with : libtop,
sources : [
'command.c',
'cpu.c',
'csw.c',
'faults.c',
'generic.c',
'globalstats.c',
'layout.c',
'log.c',
'logging.c',
'main.c',
'memstats.c',
'messages.c',
'options.c',
'pgrp.c',
'pid.c',
'ports.c',
'power.c',
'ppid.c',
'preferences.c',
'pstate.c',
'sig.c',
'statistic.c',
'syscalls.c',
'threads.c',
'timestat.c',
'top.c',
'uid.c',
'uinteger.c',
'user.c',
'userinput.c',
'userinput_help.c',
'userinput_mode.c',
'userinput_order.c',
'userinput_secondary_order.c',
'userinput_signal.c',
'userinput_sleep.c',
'userinput_user.c',
'workqueue.c',
],
)
install_man(
'top.1',
)

View File

@ -0,0 +1,37 @@
{
apple-sdk_11,
fetchpatch2,
libutil,
mkAppleDerivation,
ncurses,
pkg-config,
}:
let
xnu = apple-sdk_11.sourceRelease "xnu";
in
mkAppleDerivation {
releaseName = "top";
xcodeHash = "sha256-TuBdZztwCpNwPP0er+7h6FoPV9AbdZAXpzGcqBAuD5Y=";
postPatch = ''
# Fix duplicate symbol error. `tsamp` is unused in `main.c`.
substituteInPlace main.c \
--replace-fail 'const libtop_tsamp_t *tsamp;' ""
# Adding the whole sys folder causes header conflicts, so copy only the private headers that are needed.
mkdir sys
cp ${xnu}/bsd/sys/{kern_memorystatus.h,reason.h} sys/
'';
buildInputs = [
apple-sdk_11
libutil
ncurses
];
nativeBuildInputs = [ pkg-config ];
meta.description = "Display information about processes";
}

View File

@ -74,5 +74,9 @@
"text_cmds": {
"hash": "sha256-KSebU7ZyUsPeqn51nzuGNaNxs9pvmlIQQdkWXIVzDxw=",
"version": "99"
},
"top": {
"hash": "sha256-jbz64ODogtpNyLpXGSZj1jCBdFPVXcVcBkL1vc7g5qQ=",
"version": "108"
}
}