Skip to content

Commit

Permalink
feat: bundle wireguard-go binary on macOS (#35)
Browse files Browse the repository at this point in the history
* add wireguard-go to current path

* upload artifact

* test setting permissions

* test packaging to preserve permissions

* disable GH release for now

* archive linux bundle

* include only necessary files

---------

Co-authored-by: Maciej Wójcik <[email protected]>
Co-authored-by: teonite <[email protected]>
  • Loading branch information
3 people authored Oct 11, 2023
1 parent 2a59e0b commit c445d7b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 21 deletions.
67 changes: 53 additions & 14 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,28 @@ on:
- dev

jobs:
build-wireguard-go:
runs-on: [self-hosted, macOS]
steps:
- uses: actions/checkout@v4
with:
repository: WireGuard/wireguard-go
ref: master
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Build wireguard-go binary
run: make
- name: Upload binary artifact
uses: actions/upload-artifact@v3
with:
name: wireguard-go
path: wireguard-go

build:
needs: build-wireguard-go
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -54,25 +75,43 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf libssl-dev
- uses: tauri-apps/tauri-action@v0
- name: Download wireguard-go binary
if: matrix.platform == 'macOS'
uses: actions/download-artifact@v3
with:
name: wireguard-go
path: src-tauri/binaries/wireguard-go-x86_64-apple-darwin

- name: Build packages
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/upload-artifact@v3
if: matrix.platform == 'Linux'
with:
name: linux
path: |
src-tauri/target/release/bundle/deb/*.deb
src-tauri/target/release/bundle/appimage/*.AppImage
retention-days: 1
- name: Make sure wireguard-go binary is executable
if: matrix.platform == 'macOS'
run: chmod +x src-tauri/target/release/bundle/macos/Defguard.app/Contents/MacOS/wireguard-go

- name: Tar macOS files
if: matrix.platform == 'macOS'
run: tar -cvf bundle.tar -C src-tauri/target/release/bundle .

- name: Upload macOS artifacts
if: matrix.platform == 'macOS'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: macos.tar
path: bundle.tar
retention-days: 1

- name: Tar Linux files
if: matrix.platform == 'Linux'
run: find 'src-tauri/target/release/bundle' -name '*.AppImage' -printf '%P\0' -o -name '*.deb' -printf '%P\0' | tar --null -C 'src-tauri/target/release/bundle' -cvf bundle.tar --files-from=-

- name: Upload Linux artifacts
if: matrix.platform == 'Linux'
uses: actions/upload-artifact@v3
with:
name: macos
path: |
src-tauri/target/release/bundle/dmg/*.dmg
src-tauri/target/release/bundle/macos/*.app
name: linux.tar
path: bundle.tar
retention-days: 1
33 changes: 26 additions & 7 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ pub mod appstate;
pub mod commands;
pub mod database;
pub mod error;
mod tray;
pub mod utils;

use appstate::AppState;
use tauri::{Manager, State};
use tauri::{api::process, Env, Manager, State, SystemTrayEvent};
use tauri_plugin_log::LogTarget;

use tauri::SystemTrayEvent;
mod tray;
use crate::commands::{
active_connection, all_connections, all_instances, all_locations, connect, disconnect,
last_connection, location_stats, save_device_config, update_instance,
use crate::{
commands::{
active_connection, all_connections, all_instances, all_locations, connect, disconnect,
last_connection, location_stats, save_device_config, update_instance,
},
tray::create_tray_menu,
};
use crate::tray::create_tray_menu;
use std::env;
use utils::IS_MACOS;

#[derive(Clone, serde::Serialize)]
struct Payload {
Expand All @@ -34,6 +37,22 @@ const LOG_TARGETS: [LogTarget; 3] = [LogTarget::Stdout, LogTarget::LogDir, LogTa
// TODO: Refactor later
#[allow(clippy::single_match)]
fn main() {
// add bundled `wireguard-go` binary to PATH
if IS_MACOS {
debug!("Adding bundled wireguard-go binary to PATH");
let current_bin_path =
process::current_binary(&Env::default()).expect("Failed to get current binary path");
let current_bin_dir = current_bin_path
.parent()
.expect("Failed to get current binary directory");
let current_path = env::var("PATH").expect("Failed to get current PATH variable");
env::set_var(
"PATH",
format! {"{current_path}:{}", current_bin_dir.to_str().unwrap()},
);
debug!("Added binary dir {current_bin_dir:?} to PATH");
}

let tray_menu = create_tray_menu();
let system_tray = tauri::SystemTray::new().with_menu(tray_menu);

Expand Down
9 changes: 9 additions & 0 deletions src-tauri/tauri.macos.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tauri": {
"bundle": {
"externalBin": [
"binaries/wireguard-go"
]
}
}
}

0 comments on commit c445d7b

Please sign in to comment.