This commit is contained in:
Santhosh Raju 2024-05-02 04:58:57 +00:00 committed by GitHub
commit 5f93ff1a03
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 1749 additions and 5 deletions

45
.github/workflows/cmake-netbsd.yml vendored Normal file
View file

@ -0,0 +1,45 @@
name: NetBSD CMake
on:
push:
branches: main
tags-ignore: '*.*'
paths:
- '.github/workflows/cmake-netbsd.yml'
- 'CMakeLists.txt'
- 'include/**'
- 'src/*pp'
- 'src/netbsd/*pp'
pull_request:
branches: main
paths:
- '.github/workflows/cmake-netbsd.yml'
- 'CMakeLists.txt'
- 'include/**'
- 'src/*pp'
- 'src/netbsd/*pp'
jobs:
cmake_build_on_netbsd:
runs-on: ubuntu-22.04
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
- name: Compile
uses: vmactions/netbsd-vm@v1
with:
release: '10.0'
usesh: true
prepare: |
PATH="/usr/pkg/sbin:/usr/pkg/bin:$PATH"
PKG_PATH="https://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/10.0/All/"
export PATH PKG_PATH
/usr/sbin/pkg_add pkgin
pkgin -y install cmake ninja-build gcc10 coreutils git
git config --global --add safe.directory /home/runner/work/btop/btop
run: |
cmake -DCMAKE_CXX_COMPILER="/usr/pkg/gcc10/bin/g++" -B build -G Ninja -DBTOP_STATIC=OFF
cmake --build build --verbose

View file

@ -11,6 +11,7 @@ on:
- 'src/**'
- '!src/linux/**'
- '!src/osx/**'
- '!src/netbsd/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'
@ -22,6 +23,7 @@ on:
- 'src/**'
- '!src/linux/**'
- '!src/osx/**'
- '!src/netbsd/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'

View file

@ -11,6 +11,7 @@ on:
- 'src/**'
- '!src/osx/**'
- '!src/freebsd/**'
- '!src/netbsd/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'
@ -22,6 +23,7 @@ on:
- 'src/**'
- '!src/osx/**'
- '!src/freebsd/**'
- '!src/netbsd/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'

View file

@ -11,6 +11,7 @@ on:
- 'src/**'
- '!src/osx/**'
- '!src/freebsd/**'
- '!src/netbsd/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'
@ -22,6 +23,7 @@ on:
- 'src/**'
- '!src/osx/**'
- '!src/freebsd/**'
- '!src/netbsd/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'

View file

@ -11,6 +11,7 @@ on:
- 'src/**'
- '!src/linux/**'
- '!src/freebsd/**'
- '!src/netbsd/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'
@ -22,6 +23,7 @@ on:
- 'src/**'
- '!src/linux/**'
- '!src/freebsd/**'
- '!src/netbsd/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'

View file

@ -0,0 +1,65 @@
name: Continuous Build NetBSD
on:
workflow_dispatch:
push:
branches:
- main
tags-ignore:
- '*.*'
paths:
- 'src/**'
- '!src/linux/**'
- '!src/osx/**'
- '!src/freebsd/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'
- '.github/workflows/continuous-build-netbsd.yml'
pull_request:
branches:
- main
paths:
- 'src/**'
- '!src/linux/**'
- '!src/osx/**'
- '!src/freebsd/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'
- '.github/workflows/continuous-build-netbsd.yml'
jobs:
build-netbsd:
runs-on: ubuntu-22.04
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Compile
uses: vmactions/netbsd-vm@v1
with:
release: '10.0'
usesh: true
prepare: |
PATH="/usr/pkg/sbin:/usr/pkg/bin:$PATH"
PKG_PATH="https://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/10.0/All/"
export PATH PKG_PATH
/usr/sbin/pkg_add pkgin
pkgin -y install gmake gcc10 coreutils git
git config --global --add safe.directory /home/runner/work/btop/btop
run: |
gmake CXX=/usr/pkg/gcc10/bin/g++ CXXFLAGS='-DNDEBUG -I/usr/pkg/gcc10/include -I/usr/include -I/usr/pkg/include' STATIC=true STRIP=true
GIT_HASH=$(git rev-parse --short "$GITHUB_SHA")
mv bin/btop bin/btop-GCC10-"$GIT_HASH"
ls -alh bin
- uses: actions/upload-artifact@v3
with:
name: btop-x86_64-netbsd-9.3
path: 'bin/*'
if-no-files-found: error

View file

@ -12,6 +12,7 @@ on:
- '!src/linux/**'
- '!src/osx/**'
- '!src/freebsd/**'
- '!src/netbsd/**'
- 'include/**'
- 'Makefile'
- '.github/workflows/continuous-build-openbsd.yml'
@ -23,6 +24,7 @@ on:
- '!src/linux/**'
- '!src/osx/**'
- '!src/freebsd/**'
- '!src/netbsd/**'
- 'include/**'
- 'Makefile'
- '.github/workflows/continuous-build-openbsd.yml'

View file

@ -9,6 +9,8 @@ on:
- 'src/**'
- '!src/osx/**'
- '!src/freebsd/**'
- '!src/netbsd/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'
- '.github/workflows/test-snap-can-build.yml'
@ -18,6 +20,8 @@ on:
- 'src/**'
- '!src/osx/**'
- '!src/freebsd/**'
- '!src/netbsd/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'
- '.github/workflows/test-snap-can-build.yml'

View file

@ -66,6 +66,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
target_sources(btop PRIVATE src/freebsd/btop_collect.cpp)
elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
target_sources(btop PRIVATE src/openbsd/btop_collect.cpp src/openbsd/sysctlbyname.cpp)
elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
target_sources(btop PRIVATE src/netbsd/btop_collect.cpp)
elseif(LINUX)
target_sources(btop PRIVATE src/linux/btop_collect.cpp)
else()
@ -208,6 +210,13 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
endif()
find_package(kvm REQUIRED)
target_link_libraries(btop kvm::kvm)
elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(btop PRIVATE -static-libstdc++ -std=c++20 -DNDEBUG)
endif()
find_package(kvm REQUIRED)
find_package(proplib REQUIRED)
target_link_libraries(btop kvm::kvm proplib::proplib)
endif()

View file

@ -146,6 +146,12 @@ else ifeq ($(PLATFORM_LC),openbsd)
override ADDFLAGS += -lkvm -static-libstdc++
export MAKE = gmake
SU_GROUP := wheel
else ifeq ($(PLATFORM_LC),netbsd)
PLATFORM_DIR := netbsd
THREADS := $(shell sysctl -n hw.ncpu || echo 1)
override ADDFLAGS += -lkvm -lprop
export MAKE = gmake
SU_GROUP := wheel
else
$(error $(shell printf "\033[1;91mERROR: \033[97mUnsupported platform ($(PLATFORM))\033[0m"))
endif

168
README.md
View file

@ -7,6 +7,7 @@
![Linux](https://img.shields.io/badge/-Linux-grey?logo=linux)
![macOS](https://img.shields.io/badge/-OSX-black?logo=apple)
![FreeBSD](https://img.shields.io/badge/-FreeBSD-red?logo=freebsd)
![NetBSD](https://img.shields.io/badge/-NetBSD-black?logo=netbsd)
![OpenBSD](https://img.shields.io/badge/-OpenBSD-black?logo=openbsd)
![Usage](https://img.shields.io/badge/Usage-System%20resource%20monitor-yellow)
![c++20](https://img.shields.io/badge/cpp-c%2B%2B20-green)
@ -18,6 +19,7 @@
[![Continuous Build Linux](https://github.com/aristocratos/btop/actions/workflows/continuous-build-linux.yml/badge.svg)](https://github.com/aristocratos/btop/actions/workflows/continuous-build-linux.yml)
[![Continuous Build macOS](https://github.com/aristocratos/btop/actions/workflows/continuous-build-macos.yml/badge.svg)](https://github.com/aristocratos/btop/actions/workflows/continuous-build-macos.yml)
[![Continuous Build FreeBSD](https://github.com/aristocratos/btop/actions/workflows/continuous-build-freebsd.yml/badge.svg)](https://github.com/aristocratos/btop/actions/workflows/continuous-build-freebsd.yml)
[![Continuous Build NetBSD](https://github.com/aristocratos/btop/actions/workflows/continuous-build-netbsd.yml/badge.svg)](https://github.com/aristocratos/btop/actions/workflows/continuous-build-netbsd.yml)
[![Continuous Build OpenBSD](https://github.com/aristocratos/btop/actions/workflows/continuous-build-openbsd.yml/badge.svg)](https://github.com/aristocratos/btop/actions/workflows/continuous-build-openbsd.yml)
## Index
@ -35,6 +37,7 @@
* [Compilation Linux](#compilation-linux)
* [Compilation macOS](#compilation-macos-osx)
* [Compilation FreeBSD](#compilation-freebsd)
* [Compilation NetBSD](#compilation-netbsd)
* [Compilation OpenBSD](#compilation-openbsd)
* [GPU compatibility](#gpu-compatibility)
* [Installing the snap](#installing-the-snap)
@ -343,6 +346,10 @@ If you have an AMD GPU `rocm_smi_lib` is required, which may or may not be packa
```sh
pkg install btop
```
* **NetBSD**
```sh
pkg_add btop
```
**Binary release on Homebrew (macOS (x86_64 & ARM64) / Linux (x86_64))**
@ -902,6 +909,167 @@ If you have an AMD GPU `rocm_smi_lib` is required, which may or may not be packa
</details>
## Compilation NetBSD
Requires at least GCC 10.
Note that GNU make (`gmake`) is required to compile on NetBSD.
<details>
<summary>
### With gmake
</summary>
1. **Install dependencies**
```bash
pkg_add gmake gcc10 coreutils git
```
2. **Clone repository**
```bash
git clone https://github.com/aristocratos/btop.git
cd btop
```
3. **Compile**
```bash
gmake CXXFLAGS="-DNDEBUG"
```
Options for make:
| Flag | Description |
|---------------------------------|-------------------------------------------------------------------------|
| `VERBOSE=true` | To display full compiler/linker commands |
| `STATIC=true` | For static compilation (only libgcc and libstdc++) |
| `QUIET=true` | For less verbose output |
| `STRIP=true` | To force stripping of debug symbols (adds `-s` linker flag) |
| `DEBUG=true` | Sets OPTFLAGS to `-O0 -g` and enables more verbose debug logging |
| `ARCH=<architecture>` | To manually set the target architecture |
| `FORTIFY_SOURCE=false` | Disable fortification with `_FORTIFY_SOURCE=3` |
| `ADDFLAGS=<flags>` | For appending flags to both compiler and linker |
| `CXX=<compiler>` | Manually set which compiler to use |
Example: `gmake ADDFLAGS=-march=native` might give a performance boost if compiling only for your own system.
4. **Install**
```bash
sudo gmake install
```
Append `PREFIX=/target/dir` to set target, default: `/usr/local`
Notice! Only use "sudo" when installing to a NON user owned directory.
5. **(Recommended) Set suid bit to make btop always run as root (or other user)**
```bash
sudo gmake setuid
```
No need for `sudo` to see information for non user owned processes and to enable signal sending to any process.
Run after make install and use same PREFIX if any was used at install.
Set `SU_USER` and `SU_GROUP` to select user and group, default is `root` and `wheel`
* **Uninstall**
```bash
sudo gmake uninstall
```
* **Remove any object files from source dir**
```bash
gmake clean
```
* **Remove all object files, binaries and created directories in source dir**
```bash
gmake distclean
```
* **Show help**
```bash
gmake help
```
</details>
<details>
<summary>
### With CMake (Community maintained)
</summary>
1. **Install build dependencies**
Requires GCC, CMake, Ninja and Git
```bash
pkg_add cmake ninja-build gcc10 coreutils git
```
2. **Clone the repository**
```bash
git clone https://github.com/aristocratos/btop.git && cd btop
```
3. **Compile**
```bash
# Configure
cmake -DCMAKE_CXX_COMPILER="/usr/pkg/gcc10/bin/g++" -B build -G Ninja
# Build
cmake --build build
```
This will automatically build a release version of btop.
Some useful options to pass to the configure step:
| Configure flag | Description |
|---------------------------------|-------------------------------------------------------------------------|
| `-DBTOP_LTO=<ON\|OFF>` | Enables link time optimization (ON by default) |
| `-DBTOP_USE_MOLD=<ON\|OFF>` | Use mold to link btop (OFF by default) |
| `-DBTOP_PEDANTIC=<ON\|OFF>` | Compile with additional warnings (OFF by default) |
| `-DBTOP_WERROR=<ON\|OFF>` | Compile with warnings as errors (OFF by default) |
| `-DBTOP_FORTIFY=<ON\|OFF>` | Detect buffer overflows with `_FORTIFY_SOURCE=3` (ON by default) |
| `-DCMAKE_INSTALL_PREFIX=<path>` | The installation prefix ('/usr/local' by default) |
To force any other compiler, run `CXX=<compiler> cmake -B build -G Ninja`
4. **Install**
```bash
cmake --install build
```
May require root privileges
5. **Uninstall**
CMake doesn't generate an uninstall target by default. To remove installed files, run
```
cat build/install_manifest.txt | xargs rm -irv
```
6. **Cleanup build directory**
```bash
cmake --build build -t clean
```
</details>
## Compilation OpenBSD
Requires at least GCC 10.

View file

@ -0,0 +1,23 @@
# SPDX-License-Identifier: Apache-2.0
#
# Find proplib property container object library
#
if(BSD)
find_path(proplib_INCLUDE_DIR NAMES prop/proplib.h)
find_library(proplib_LIBRARY NAMES libprop prop)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(proplib REQUIRED_VARS proplib_LIBRARY proplib_INCLUDE_DIR)
if(proplib_FOUND AND NOT TARGET proplib::proplib)
add_library(proplib::proplib UNKNOWN IMPORTED)
set_target_properties(proplib::proplib PROPERTIES
IMPORTED_LOCATION "${proplib_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${proplib_INCLUDE_DIR}"
)
endif()
mark_as_advanced(proplib_INCLUDE_DIR proplib_LIBRARY)
endif()

View file

@ -293,7 +293,7 @@ void clean_quit(int sig) {
Global::quitting = true;
Runner::stop();
if (Global::_runner_started) {
#if defined __APPLE__ || defined __OpenBSD__
#if defined __APPLE__ || defined __OpenBSD__ || defined __NetBSD__
if (pthread_join(Runner::runner_id, nullptr) != 0) {
Logger::warning("Failed to join _runner thread on exit!");
pthread_cancel(Runner::runner_id);
@ -329,7 +329,7 @@ void clean_quit(int sig) {
const auto excode = (sig != -1 ? sig : 0);
#if defined __APPLE__ || defined __OpenBSD__
#if defined __APPLE__ || defined __OpenBSD__ || defined __NetBSD__
_Exit(excode);
#else
quick_exit(excode);
@ -1024,7 +1024,7 @@ int main(int argc, char **argv) {
Config::set("tty_mode", true);
Logger::info("Forcing tty mode: setting 16 color mode and using tty friendly graph symbols");
}
#if not defined __APPLE__ && not defined __OpenBSD__
#if not defined __APPLE__ && not defined __OpenBSD__ && not defined __NetBSD__
else if (not Global::arg_tty and Term::current_tty.starts_with("/dev/tty")) {
Config::set("tty_mode", true);
Logger::info("Real tty detected: setting 16 color mode and using tty friendly graph symbols");

View file

@ -34,7 +34,7 @@ tab-size = 4
#include <ifaddrs.h>
// clang-format on
#if defined(__FreeBSD__) || defined(__OpenBSD__)
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
# include <kvm.h>
#endif
@ -93,7 +93,7 @@ namespace Shared {
extern long coreCount, page_size, clk_tck;
#if defined(__FreeBSD__) || defined(__OpenBSD__)
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
struct KvmDeleter {
void operator()(kvm_t* handle) {
kvm_close(handle);

1414
src/netbsd/btop_collect.cpp Normal file

File diff suppressed because it is too large Load diff