Skip to content

Commit

Permalink
refactor: use debug_assertions instead of bundled feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tymmesyde committed Oct 7, 2023
1 parent 9017d3a commit a68d1bd
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
target/debian/*.deb
# Builds the rpm linux package
- name: Build release
run: cargo build --release --features=bundled
run: cargo build --release
- name: Strip debug symbols
run: strip -s target/release/stremio-service
- name: Build rpm package
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
brew install graphicsmagick imagemagick
npm -g install appdmg
- name: Build
run: cargo build --release --features=bundled
run: cargo build --release
- name: Bundle
run: |
cargo run --bin bundle-macos
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
toolchain: stable
- name: Build
run: cargo build --release --features=bundled
run: cargo build --release
- name: Sign executables
run: |
& 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x86\signtool.exe' sign /f "resources\certificates\smartcode-20211118-20241118.pfx" /p ${{ secrets.WIN_CERT_PASSWORD }} /v ".\target\release\stremio-service.exe"
Expand Down
8 changes: 0 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ version = "v4.20.2"

[features]
default = []
# Wheather or not we're running the app in a bundled (installed) mode.
#
# The binary location for "bundled" is system-wide, while non-bundled
# is locally inside `target/` and binaries paths will be based on
# the Cargo.toml location.
bundled = []
# Will not download anything while building
offline-build = []

Expand Down Expand Up @@ -130,7 +124,6 @@ assets = [
["resources/com.stremio.service.metainfo.xml", "/usr/share/metainfo/com.stremio.service.metainfo.xml", "644"],
["resources/com.stremio.service.svg", "/usr/share/icons/hicolor/scalable/apps/com.stremio.service.svg", "644"],
]
features = ["bundled"]

[package.metadata.generate-rpm]
# post_install_script = "gnome_version=$(gnome-shell --version | awk '{print $NF}') && echo https://extensions.gnome.org/extension-data/appindicatorsupportrgcjonas.gmail.com.GNOME_VERSION.shell-extension.zip | sed -e s/GNOME_VERSION/$gnome_version/g"
Expand All @@ -147,7 +140,6 @@ assets = [
{ source = "resources/com.stremio.service.svg", dest = "/usr/share/icons/hicolor/scalable/apps/com.stremio.service.svg", mode = "644" },
]
# depends = "$auto, ffprobe (>=4.2.7)"
features = ["bundled"]

[package.metadata.generate-rpm.requires]
libappindicator-gtk3 = "*"
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Features

- `default` features - none
- `bundled` - uses binaries location for an installed(and bundled) application.
- `offline-build` - prevent the build script from downloading the server.js file

## Download

Expand Down Expand Up @@ -74,10 +74,8 @@ cargo build --release

#### Windows

Build the binaries on Windows in release using the `bundled` feature.

```
cargo build --release --features=bundled
cargo build --release
```

Run the Inno Setup compiler `ISCC` command inside `Command Prompt` or `PowerShell` against the `StremioService.iss` script. Depending on your installation the path to `IISC` may vary. Here is an example with the default installation path, presuming your current working directory is the project's root:
Expand All @@ -97,10 +95,10 @@ A new executable should be produced - `StremioServiceSetup.exe`
rustup target add x86_64-pc-windows-gnu
```

2. And build the binary using the `bundled` feature:
2. And build the binary:

```
cargo build --release --target x86_64-pc-windows-gnu --features=bundled
cargo build --release --target x86_64-pc-windows-gnu
```

**NOTE:** The Windows installed can **not** be built on other platforms, only **Windows**.
Expand All @@ -115,10 +113,10 @@ cargo deb

`cargo-generate-rpm` does not not build the binary nor strips debugging symbols as of version `0.9.1`.

This is why we need to first build the release (with the `bundled` feature):
This is why we need to first build the release:

```
cargo build --release --features=bundled
cargo build --release
```

Strip the debugging symbols:
Expand Down
2 changes: 1 addition & 1 deletion com.stremio.Service.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"build-commands": [
"cargo --offline fetch --manifest-path Cargo.toml --verbose",
"cargo --offline build --release --features=bundled,offline-build --verbose"
"cargo --offline build --release --features=offline-build --verbose"
],
"post-install": [
"install -Dm755 ./flatpak/stremio-service -t /app/bin/",
Expand Down
8 changes: 4 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use fslock::LockFile;
use log::{error, info};
use rand::Rng;
use rust_embed::RustEmbed;
#[cfg(all(feature = "bundled", any(target_os = "linux", target_os = "macos")))]
#[cfg(all(not(debug_assertions), any(target_os = "linux", target_os = "macos")))]
use std::path::Path;
use std::path::PathBuf;
use tao::{
Expand Down Expand Up @@ -49,7 +49,7 @@ pub struct Application {
pub struct Config {
/// The Home directory of the user running the service
/// used to make the application an autostart one (on `*nix` systems)
#[cfg_attr(any(not(feature = "bundled"), target_os = "windows"), allow(dead_code))]
#[cfg_attr(any(debug_assertions, target_os = "windows"), allow(dead_code))]
home_dir: PathBuf,

/// The lockfile that guards against running multiple instances of the service.
Expand Down Expand Up @@ -123,7 +123,7 @@ impl Application {
return Ok(());
}

#[cfg(all(feature = "bundled", any(target_os = "linux", target_os = "macos")))]
#[cfg(all(not(debug_assertions), any(target_os = "linux", target_os = "macos")))]
make_it_autostart(self.config.home_dir.clone());

// NOTE: we do not need to run the Fruitbasket event loop but we do need to keep `app` in-scope for the full lifecycle of the app
Expand Down Expand Up @@ -221,7 +221,7 @@ fn open_stremio_web(addon_manifest_url: Option<String>) {
}

/// Only for Linux and MacOS
#[cfg(all(feature = "bundled", any(target_os = "linux", target_os = "macos")))]
#[cfg(all(not(debug_assertions), any(target_os = "linux", target_os = "macos")))]
fn make_it_autostart(home_dir: impl AsRef<Path>) {
#[cfg(target_os = "linux")]
{
Expand Down
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2017-2023 Smart code 203358507

#![cfg_attr(
all(target_os = "windows", feature = "bundled"),
all(target_os = "windows", not(debug_assertions)),
windows_subsystem = "windows"
)]
use std::error::Error;
Expand All @@ -28,11 +28,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
let home_dir = dirs::home_dir().context("Failed to get home dir")?;
let cache_dir = dirs::cache_dir().context("Failed to get cache dir")?;

#[cfg(feature = "bundled")]
// use the installed dir if we've built the app with `bundled` feature.
// use current exe directory
#[cfg(not(debug_assertions))]
let service_bins_dir = stremio_service::util::get_current_exe_dir();
#[cfg(not(feature = "bundled"))]

// use the `resources/bin/{linux|windows|macos}` directory
#[cfg(debug_assertions)]
let service_bins_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("resources")
.join("bin")
Expand Down

0 comments on commit a68d1bd

Please sign in to comment.