Skip to content

Commit

Permalink
Fix cfgs
Browse files Browse the repository at this point in the history
  • Loading branch information
atlanticaccent committed Oct 9, 2024
1 parent fa81f3c commit 0212d2e
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 59 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions moss-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,9 @@ gtk = { version = "0.18.1" }
[target.'cfg(not(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))'.dependencies]
rfd = "0.15"

[target.'cfg(mac)'.dependencies]
[target.'cfg(target_os = "macos")'.dependencies]
metal = "0.29"

[build-dependencies]
cfg_aliases = "0.2.1"

[[example]]
name = "dim_constraints"
required-features = ["leaky-api"]
8 changes: 0 additions & 8 deletions moss-sys/build.rs

This file was deleted.

4 changes: 2 additions & 2 deletions moss-sys/examples/macos.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(mac)]
#[cfg(target_os = "macos")]
fn main() {
use std::ops::Div;

Expand All @@ -16,7 +16,7 @@ fn main() {
);
}

#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
fn main() {
println!("This example does nothing outside macOS")
}
12 changes: 6 additions & 6 deletions moss-sys/src/app/app_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ impl Delegate<App> for AppDelegate {
let sink = ctx.get_external_handle();
if *is_file {
data.runtime.spawn_blocking(move || {
#[cfg(not(linux))]
#[cfg(not(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))]
let res = rfd::FileDialog::new()
.add_filter("Archives", &[
"zip", "7z", "7zip", "rar", "rar4", "rar5", "tar",
])
.pick_files();
#[cfg(linux)]
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
let res = native_dialog::FileDialog::new()
.add_filter("Archives", &[
"zip", "7z", "7zip", "rar", "rar4", "rar5", "tar",
Expand All @@ -84,9 +84,9 @@ impl Delegate<App> for AppDelegate {
});
} else {
data.runtime.spawn_blocking(move || {
#[cfg(not(linux))]
#[cfg(not(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))]
let res = rfd::FileDialog::new().pick_folder();
#[cfg(linux)]
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
let res = native_dialog::FileDialog::new()
.show_open_single_dir()
.ok()
Expand Down Expand Up @@ -311,9 +311,9 @@ impl Delegate<App> for AppDelegate {
data.browser.inner = None;
}
let _ = std::fs::remove_dir_all(PROJECT.cache_dir());
#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
ctx.submit_command(druid::commands::QUIT_APP);
#[cfg(mac)]
#[cfg(target_os = "macos")]
std::process::exit(0);
}
_ => {}
Expand Down
12 changes: 6 additions & 6 deletions moss-sys/src/app/browser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ impl Browser {
}

fn init_webview(ctx: &mut druid::EventCtx, data: &mut Browser) -> Result<Rc<WebView>, wry::Error> {
#[cfg(linux)]
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
let res = {
use gtk::{
glib::translate::{FromGlibPtrFull, ToGlibPtr},
Expand Down Expand Up @@ -393,7 +393,7 @@ fn init_webview(ctx: &mut druid::EventCtx, data: &mut Browser) -> Result<Rc<WebV

webview_subsystem::init_webview(data.url.clone(), builder, ctx.get_external_handle())
};
#[cfg(not(linux))]
#[cfg(not(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))]
let res = webview_subsystem::init_webview_with_handle(
data.url.clone(),
ctx.window(),
Expand Down Expand Up @@ -562,9 +562,9 @@ impl BrowserInner {
fn set_bounds(&self, ctx: &mut (impl LaidOutCtx + AnyCtx)) {
let window_origin = ctx.window_origin();
let size = ctx.size();
#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
let position = (window_origin.x, window_origin.y - 7.);
#[cfg(mac)]
#[cfg(target_os = "macos")]
let position = {
let actual_y = ctx.window().get_size().height - (ctx.window_origin().y + ctx.size().height);
(window_origin.x, actual_y - 35.0)
Expand All @@ -579,7 +579,7 @@ impl BrowserInner {
}

fn screenshot(&self, ext_ctx: ExtEventSink) {
#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
if self.is_visible()
&& !*self.screenshow_wip()
&& self
Expand All @@ -602,7 +602,7 @@ impl BrowserInner {
{
*self.screenshow_wip() = true;
}
#[cfg(mac)]
#[cfg(target_os = "macos")]
drop(ext_ctx)
}

Expand Down
2 changes: 1 addition & 1 deletion moss-sys/src/app/controllers/app_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<W: Widget<App>> Controller<App, W> for AppController {
let ext_ctx = ctx.get_external_handle();
ctx.set_disabled(true);
data.runtime.spawn_blocking(move || {
#[cfg(mac)]
#[cfg(target_os = "macos")]
let res = rfd::FileDialog::new()
.add_filter("*.app", &["app"])
.pick_file();
Expand Down
8 changes: 4 additions & 4 deletions moss-sys/src/app/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ fn managed_starsector_launch(app: &mut App, ctx: &mut druid::EventCtx) {
}
}

#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
async fn launch(
install_dir: &Path,
direct_launch: bool,
Expand All @@ -602,7 +602,7 @@ async fn launch(
true => "Miko_R3.txt",
#[cfg(target_os = "windows")]
false => "vmparams",
#[cfg(linux)]
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
false => "starsector.sh",
});

Expand Down Expand Up @@ -650,7 +650,7 @@ async fn launch(
(miko || direct_launch).then(|| install_dir.join("starsector-core")),
);

#[cfg(linux)]
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
let (exe, working_dir) = (
install_dir.join(match direct_launch {
true if miko => "jdk-23+9/bin/java",
Expand Down Expand Up @@ -780,7 +780,7 @@ fn format_command(
commands.collect()
}

#[cfg(mac)]
#[cfg(target_os = "macos")]
async fn launch(
install_dir: &Path,
experimental_launch: bool,
Expand Down
4 changes: 2 additions & 2 deletions moss-sys/src/app/overlays/select_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use crate::{
pub struct SelectInstall;

impl SelectInstall {
#[cfg(mac)]
#[cfg(target_os = "macos")]
const HEADING: &'static str = "Please select the Starsector app.";
#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
const HEADING: &'static str = "Please select your Starsector installation directory.";

pub fn view() -> impl Widget<App> {
Expand Down
28 changes: 14 additions & 14 deletions moss-sys/src/app/tools/jre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Swapper {
let table = FlexTable::new()
.with_row(Self::swapper_row(Flavour::Original, "Original (Java 7)"));

#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
let table = table.with_row(Self::swapper_row(
Flavour::Miko,
"Java 23 by Mikohime (New!)",
Expand Down Expand Up @@ -346,7 +346,7 @@ impl Swapper {
})
.collect();

#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
if install_dir.join("Miko_R3.txt").exists() && install_dir.join(consts::MIKO_JDK_VER).exists() {
available.push(Flavour::Miko);
}
Expand Down Expand Up @@ -406,7 +406,7 @@ impl Swapper {
strum_macros::FromRepr,
)]
pub enum Flavour {
#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
Miko,
Coretto,
Hotspot,
Expand All @@ -421,7 +421,7 @@ const JRE_BACKUP: &str = "jre.bak";
impl Flavour {
async fn download(self, install_dir: PathBuf) -> Result<(), anyhow::Error> {
let cached_jre = install_dir.join(match self {
#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
Flavour::Miko => consts::MIKO_JDK_VER.to_owned(),
_ => format!("jre_{self}"),
});
Expand All @@ -444,7 +444,7 @@ impl Flavour {
std::fs::rename(jre_8, &cached_jre)?;
}

#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
if self.is_miko() && !install_dir.join("mikohime").exists() {
let miko_dir = Flavour::get_miko_kit(&install_dir).await?;

Expand Down Expand Up @@ -502,7 +502,7 @@ impl Flavour {
Flavour::Hotspot => consts::HOTSPOT,
Flavour::Wisp => consts::WISP,
Flavour::Azul => consts::AZUL,
#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
Flavour::Miko => consts::MIKO_JDK,
Flavour::Original => unimplemented!(),
}
Expand Down Expand Up @@ -579,7 +579,7 @@ impl Flavour {
.with_context(|| "Could not find JRE in given folder")
}

#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
async fn get_miko_kit(root: &Path) -> anyhow::Result<TempDir> {
let url = consts::MIKO_KIT;

Expand All @@ -602,7 +602,7 @@ impl Flavour {
Ok(tempdir)
}

#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
async fn move_miko_kit(miko_download: &Path) -> anyhow::Result<()> {
let root_dir = miko_download
.parent()
Expand Down Expand Up @@ -642,9 +642,9 @@ impl Flavour {
}

fn is_miko(self) -> bool {
#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
return matches!(self, Flavour::Miko);
#[cfg(mac)]
#[cfg(target_os = "macos")]
return false;
}
}
Expand Down Expand Up @@ -732,7 +732,7 @@ mod consts {

pub const JRE_PATH: &str = "jre";
}
#[cfg(linux)]
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
mod consts {
use super::FindBy;

Expand All @@ -753,7 +753,7 @@ mod consts {

pub const JRE_PATH: &str = "jre_linux";
}
#[cfg(mac)]
#[cfg(target_os = "macos")]
mod consts {
use super::FindBy;

Expand Down Expand Up @@ -806,7 +806,7 @@ mod test {
std::fs::write(target_path.join("release"), r#"JAVA_VERSION="1.7.0""#)
.expect("Write test release");
}
} else if cfg!(mac) {
} else if cfg!(target_os = "macos") {
let parent = target_path.parent().expect("Get path parent");
std::fs::create_dir_all(parent).expect("Create parent folder");
}
Expand Down Expand Up @@ -943,7 +943,7 @@ mod test {
let test_dir = TempDir::new().expect("Create tempdir");
let target_path = test_dir.path().join(consts::JRE_PATH);

#[cfg(mac)]
#[cfg(target_os = "macos")]
std::fs::create_dir_all(target_path.parent().expect("Get path parent"))
.expect("Create parent dir");

Expand Down
4 changes: 2 additions & 2 deletions moss-sys/src/app/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ impl Tools {
|data: &InstallDirInverseTools, _| Swapper::get_cached_jres(data.install_dir.clone()),
SizedBox::empty(),
|res, _data, _| {
#[cfg_attr(mac, allow(unused_mut))]
#[cfg_attr(target_os = "macos", allow(unused_mut))]
let (mut current_flavour, cached_flavours) = *res;
let cached_flavours: druid::im::Vector<_> = cached_flavours.into();
#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
if _data.jre_23 && cached_flavours.contains(&jre::Flavour::Miko) {
current_flavour = jre::Flavour::Miko;
}
Expand Down
6 changes: 3 additions & 3 deletions moss-sys/src/app/tools/vmparams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl VMParamsPath for VMParamsPathDefault {
fn path() -> &'static str {
#[cfg(target_os = "windows")]
return "vmparams";
#[cfg(mac)]
#[cfg(target_os = "macos")]
return "Contents/MacOS/starsector_mac.sh";
#[cfg(any(
target_os = "linux",
Expand Down Expand Up @@ -497,9 +497,9 @@ impl<T: VMParamsPath> VMParams<T> {
.next_chunk::<3>()
.map_or_else(std::iter::Iterator::collect, |arr| arr.iter().collect());
if rem.eq_ignore_ascii_case("ver") {
#[cfg(mac)]
#[cfg(target_os = "macos")]
output.push_str(r"Xverify:none \\n\t-");
#[cfg(not(mac))]
#[cfg(not(target_os = "macos"))]
output.push_str("Xverify:none -");
}

Expand Down
8 changes: 4 additions & 4 deletions moss-sys/src/app/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ impl Deref for Release {
}
}

// const SUPPORT_SELF_UPDATE: bool = cfg!(not(mac));
// const SUPPORT_SELF_UPDATE: bool = cfg!(not(target_os = "macos"));
const TARGET: &str = if cfg!(target_os = "windows") {
"MOSS.exe"
} else if cfg!(linux) {
} else if cfg!(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")) {
"MOSS.AppImage"
} else {
"MOSS.app"
Expand Down Expand Up @@ -137,9 +137,9 @@ fn update(_: Box<dyn ReleaseUpdate>, release: Release) -> anyhow::Result<()> {
use cargo_packager_updater::{Config, Update, UpdateFormat};
use self_update::Download;

const FORMAT: UpdateFormat = if cfg!(mac) {
const FORMAT: UpdateFormat = if cfg!(target_os = "macos") {
UpdateFormat::App
} else if cfg!(linux) {
} else if cfg!(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")) {
UpdateFormat::AppImage
} else {
UpdateFormat::Wix
Expand Down
4 changes: 2 additions & 2 deletions moss-sys/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,11 @@ pub async fn get_starsector_version(ext_ctx: ExtEventSink, install_dir: PathBuf)
use regex::bytes::Regex;
use tokio::{fs, task};

#[cfg(linux)]
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
let obf_jar = install_dir.join("starfarer_obf.jar");
#[cfg(target_os = "windows")]
let obf_jar = install_dir.join("starsector-core/starfarer_obf.jar");
#[cfg(mac)]
#[cfg(target_os = "macos")]
let obf_jar = install_dir.join("Contents/Resources/Java/starfarer_obf.jar");

let mut res = task::spawn_blocking(move || {
Expand Down

0 comments on commit 0212d2e

Please sign in to comment.