Skip to content

Commit

Permalink
update plugin bundling scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
bjia56 committed Jan 14, 2025
1 parent c3eb8f7 commit 4823898
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 45 deletions.
32 changes: 11 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ jobs:
export CXX="zig c++ -target ${{ matrix.arch }}-linux-gnu.2.17"
cmake -B build -DBTOP_TARGET=plugin
cmake --build build --parallel 4
cp build/libbtop.so ${{ github.workspace }}/libbtop-Linux-${{ matrix.arch }}.so
cp build/libbtop.so ${{ github.workspace }}/btop-linux-${{ matrix.arch }}.so
- name: Upload plugin
uses: actions/upload-artifact@v4
with:
name: plugin-Linux-${{ matrix.arch }}
path: ./libbtop-Linux-${{ matrix.arch }}.so
name: plugin-linux-${{ matrix.arch }}
path: ./btop-linux-${{ matrix.arch }}.so

bundle:
name: Bundle plugins with btop
Expand Down Expand Up @@ -126,27 +126,17 @@ jobs:
run: |
tree /tmp/btop-plugin || true
mv btop btop.exe
mv btop btop.com
sudo mkdir -p /zip/x86_64/linux
sudo cp /tmp/btop-plugin/libbtop-Linux-x86_64.so /zip/x86_64/linux/libbtop.so
sudo mkdir -p /zip/x86_64/macos
sudo mkdir -p /zip/x86_64/windows
sudo mkdir -p /zip/x86_64/freebsd
sudo mkdir -p /zip/x86_64/openbsd
sudo mkdir -p /zip/x86_64/netbsd
sudo mkdir -p /zip/aarch64/linux
sudo cp /tmp/btop-plugin/libbtop-Linux-aarch64.so /zip/aarch64/linux/libbtop.so
sudo mkdir -p /zip/aarch64/macos
sudo mkdir -p /zip/aarch64/windows
sudo mkdir -p /zip/aarch64/freebsd
sudo mkdir -p /zip/aarch64/openbsd
sudo mkdir -p /zip/aarch64/netbsd
sudo mkdir -p /zip/
sudo cp /tmp/btop-plugin/btop-linux-x86_64.so /zip/
sudo cp /tmp/btop-plugin/btop-linux-aarch64.so /zip/
cd /zip
zip -qr ${{ github.workspace }}/btop.exe *
zip ${{ github.workspace }}/btop.com *
cd ${{ github.workspace }}
mv btop.com btop.exe
- name: Upload artifacts
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ stage/
# Compiled man page
btop.1

build
build*/
bin
btop
/obj/
Expand Down
47 changes: 24 additions & 23 deletions src/btop_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,39 +267,39 @@ namespace Runner {
PluginHost* pluginHost = nullptr;

void create_plugin_host() {
std::stringstream ziposPluginPath("/zip/");
if (IsAarch64()) {
ziposPluginPath << "aarch64/";
} else {
ziposPluginPath << "x86_64/";
}
std::stringstream pluginName;
pluginName << "btop-";
if (IsLinux()) {
ziposPluginPath << "linux/";
pluginName << "linux";
} else if (IsXnu()) {
ziposPluginPath << "macos/";
pluginName << "darwin";
} else if (IsWindows()) {
ziposPluginPath << "windows/";
pluginName << "windows";
} else if (IsFreebsd()) {
ziposPluginPath << "freebsd/";
pluginName << "freebsd";
} else if (IsOpenbsd()) {
ziposPluginPath << "openbsd/";
pluginName << "openbsd";
} else if (IsNetbsd()) {
ziposPluginPath << "netbsd/";
pluginName << "netbsd";
}
if (IsAarch64()) {
pluginName << "-aarch64";
} else {
pluginName << "-x86_64";
}

std::string pluginName = "invalid_platform";
if (IsLinux() || IsFreebsd()) {
pluginName = "libbtop.so";
pluginName << ".so";
} else if (IsXnu()) {
if (IsXnuSilicon()) {
pluginName = "libbtop.dylib";
pluginName << ".dylib";
} else {
pluginName = "libbtop.exe";
pluginName << ".exe";
}
} else if (IsWindows()) {
pluginName = "btop.dll";
pluginName << ".dll";
} else if (IsOpenbsd() || IsNetbsd()) {
pluginName = "libbtop.exe";
pluginName << ".exe";
}

// Create temp directory for btop plugin
Expand All @@ -309,12 +309,13 @@ void create_plugin_host() {
}

// Extract btop plugin from zipos
auto pluginPath = tmpdir / pluginName;
if (!std::filesystem::exists(ziposPluginPath.str() + pluginName)) {
std::cerr << "Plugin not found in zipos: " << ziposPluginPath.str() + pluginName << std::endl;
auto pluginPath = tmpdir / pluginName.str();
auto ziposPath = std::filesystem::path("/zip/") / pluginName.str();
if (!std::filesystem::exists(ziposPath)) {
std::cerr << "Plugin not found in zipos: " << ziposPath << std::endl;
} else {
std::filesystem::copy_file(ziposPluginPath.str() + pluginName, pluginPath);
chmod(pluginPath.c_str(), 0700);
std::filesystem::copy_file(ziposPath, pluginPath);
chmod(pluginPath.c_str(), 0400);
}

pluginHost = new PluginHost(pluginPath.string());
Expand Down

0 comments on commit 4823898

Please sign in to comment.