Skip to content
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

openbsd bringup #607

Merged
merged 7 commits into from
Jan 2, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/continuous-build-freebsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- 'src/**'
- '!src/linux/**'
- '!src/osx/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'
- '.github/workflows/continuous-build-freebsd.yml'
Expand All @@ -21,6 +22,7 @@ on:
- 'src/**'
- '!src/linux/**'
- '!src/osx/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'
- '.github/workflows/continuous-build-freebsd.yml'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/continuous-build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- 'src/**'
- '!src/osx/**'
- '!src/freebsd/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'
- '.github/workflows/continuous-build-linux.yml'
Expand All @@ -21,6 +22,7 @@ on:
- 'src/**'
- '!src/osx/**'
- '!src/freebsd/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'
- '.github/workflows/continuous-build-linux.yml'
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/continuous-build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- 'src/**'
- '!src/linux/**'
- '!src/freebsd/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'
- '.github/workflows/continuous-build-macos.yml'
Expand All @@ -21,6 +22,7 @@ on:
- 'src/**'
- '!src/linux/**'
- '!src/freebsd/**'
- '!src/openbsd/**'
- 'include/**'
- 'Makefile'
- '.github/workflows/continuous-build-macos.yml'
Expand All @@ -44,18 +46,18 @@ jobs:
with:
name: btop-x86_64-macos11-BigSur
path: 'bin/*'

build-macos12:
runs-on: macos-12
steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
xcode-version: latest-stable

- uses: actions/checkout@v3
with:
submodules: recursive

- name: Compile
run: |
make CXX=g++-12 ARCH=x86_64 STATIC=true STRIP=true
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/continuous-build-openbsd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Continuous Build OpenBSD

on:
workflow_dispatch:
push:
branches:
- main
tags-ignore:
- '*.*'
paths:
- 'src/**'
- '!src/linux/**'
- '!src/osx/**'
- '!src/freebsd/**'
- 'include/**'
- 'Makefile'
- '.github/workflows/continuous-build-openbsd.yml'
pull_request:
branches:
- main
paths:
- 'src/**'
- '!src/linux/**'
- '!src/osx/**'
- '!src/freebsd/**'
- 'include/**'
- 'Makefile'
- '.github/workflows/continuous-build-openbsd.yml'

jobs:
build-openbsd:
runs-on: ubuntu-22.04
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Compile
uses: vmactions/openbsd-vm@v1
with:
release: '7.4'
usesh: true
prepare: |
pkg_add gmake gcc%11 g++%11 coreutils git
git config --global --add safe.directory /home/runner/work/btop/btop
run: |
gmake CXX=eg++ STATIC=true STRIP=true
GIT_HASH=$(git rev-parse --short "$GITHUB_SHA")
mv bin/btop bin/btop-GCC11-"$GIT_HASH"
ls -alh bin

- uses: actions/upload-artifact@v3
with:
name: btop-x86_64-openbsd-7.4
path: 'bin/*'
if-no-files-found: error

8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ ifeq ($(CLANG_WORKS),false)
CXX := g++11
else ifeq ($(shell command -v g++ >/dev/null; echo $$?),0)
CXX := g++
else ifeq ($(shell command -v eg++ >/dev/null; echo $$?),0)
CXX := eg++
else
GCC_NOT_FOUND := true
endif
Expand Down Expand Up @@ -158,6 +160,12 @@ else ifeq ($(PLATFORM_LC),macos)
THREADS := $(shell sysctl -n hw.ncpu || echo 1)
override ADDFLAGS += -framework IOKit -framework CoreFoundation -Wno-format-truncation
SU_GROUP := wheel
else ifeq ($(PLATFORM_LC),openbsd)
PLATFORM_DIR := openbsd
THREADS := $(shell sysctl -n hw.ncpu || echo 1)
override ADDFLAGS += -lkvm
export MAKE = gmake
SU_GROUP := wheel
else
$(error $(shell printf "\033[1;91mERROR: \033[97mUnsupported platform ($(PLATFORM))\033[0m"))
endif
Expand Down
95 changes: 95 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* [Compilation Linux](#compilation-linux)
* [Compilation macOS](#compilation-macos-osx)
* [Compilation FreeBSD](#compilation-freebsd)
* [Compilation OpenBSD](#compilation-openbsd)
* [GPU compatibility](#gpu-compatibility)
* [Installing the snap](#installing-the-snap)
* [Configurability](#configurability)
Expand Down Expand Up @@ -868,6 +869,100 @@ Also needs a UTF8 locale and a font that covers:

</details>

## Compilation OpenBSD

Requires at least GCC 10.

Note that GNU make (`gmake`) is required to compile on OpenBSD.

<details>
<summary>

### With gmake
</summary>

1. **Install dependencies**

```bash
pkg_add gmake gcc%11 g++%11 coreutils git
```

2. **Clone repository**

```bash
git clone https://github.com/aristocratos/btop.git
cd btop
```

3. **Compile**

```bash
gmake CXX=eg++
```

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 |
| `ADDFLAGS=<flags>` | For appending flags to both compiler and linker |
| `CXX=<compiler>` | Manualy 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>

## Installing the snap
[![btop](https://snapcraft.io/btop/badge.svg)](https://snapcraft.io/btop)

Expand Down
8 changes: 4 additions & 4 deletions src/btop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void clean_quit(int sig) {
Global::quitting = true;
Runner::stop();
if (Global::_runner_started) {
#ifdef __APPLE__
#if defined __APPLE__ || defined __OpenBSD__
if (pthread_join(Runner::runner_id, nullptr) != 0) {
Logger::warning("Failed to join _runner thread on exit!");
pthread_cancel(Runner::runner_id);
Expand Down Expand Up @@ -291,7 +291,7 @@ void clean_quit(int sig) {

const auto excode = (sig != -1 ? sig : 0);

#ifdef __APPLE__
#if defined __APPLE__ || defined __OpenBSD__
_Exit(excode);
#else
quick_exit(excode);
Expand Down Expand Up @@ -931,7 +931,7 @@ int main(int argc, char **argv) {
catch (...) { found.clear(); }
}
}

//
#ifdef __APPLE__
if (found.empty()) {
CFLocaleRef cflocale = CFLocaleCopyCurrent();
Expand Down Expand Up @@ -975,7 +975,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");
}
#ifndef __APPLE__
#if not defined __APPLE__ && not defined __OpenBSD__
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");
Expand Down
4 changes: 3 additions & 1 deletion src/btop_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ namespace Term {
tcgetattr(STDIN_FILENO, &initial_settings);
current_tty = (ttyname(STDIN_FILENO) != nullptr ? static_cast<string>(ttyname(STDIN_FILENO)) : "unknown");

//? Disable stream sync
//? Disable stream sync - this does not seem to work on OpenBSD
#ifndef __OpenBSD__
cin.sync_with_stdio(false);
cout.sync_with_stdio(false);
#endif

//? Disable stream ties
cin.tie(nullptr);
Expand Down
Loading
Loading