Skip to content

Commit

Permalink
fix: enable unwinding on Windows release builds (#2286)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Feb 4, 2025
1 parent 7f1e9b8 commit 64a9bf2
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ jobs:
uses: mozilla-actions/[email protected]

- name: Build
run: cargo build --release --locked --target ${{ matrix.target }}
run: cargo build --profile release-windows --locked --target ${{ matrix.target }}

- name: Pack artifact
env:
TARGET_NAME: yazi-${{ matrix.target }}
run: |
New-Item -ItemType Directory -Path ${env:TARGET_NAME}
Copy-Item -Path "target\${{ matrix.target }}\release\ya.exe" -Destination ${env:TARGET_NAME}
Copy-Item -Path "target\${{ matrix.target }}\release\yazi.exe" -Destination ${env:TARGET_NAME}
Copy-Item -Path "target\${{ matrix.target }}\release-windows\ya.exe" -Destination ${env:TARGET_NAME}
Copy-Item -Path "target\${{ matrix.target }}\release-windows\yazi.exe" -Destination ${env:TARGET_NAME}
Copy-Item -Path "yazi-boot\completions" -Destination ${env:TARGET_NAME} -Recurse
Copy-Item -Path "README.md", "LICENSE" -Destination ${env:TARGET_NAME}
Compress-Archive -Path ${env:TARGET_NAME} -DestinationPath "${env:TARGET_NAME}.zip"
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ lto = true
panic = "abort"
strip = true

[profile.release-windows]
inherits = "release"
panic = "unwind"

[workspace.dependencies]
ansi-to-tui = "7.0.0"
anyhow = "1.0.95"
Expand Down
8 changes: 5 additions & 3 deletions yazi-core/src/manager/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use parking_lot::RwLock;
use tokio::{fs, pin, sync::{mpsc::{self, UnboundedReceiver}, watch}};
use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream};
use tracing::error;
use yazi_dds::Pubsub;
use yazi_fs::{Cha, File, Files, FilesOp, mounts::PARTITIONS, realname_unchecked};
use yazi_fs::{Cha, File, Files, FilesOp, realname_unchecked};
use yazi_proxy::WATCHER;
use yazi_shared::{RoCell, url::Url};

Expand Down Expand Up @@ -44,7 +43,10 @@ impl Watcher {
}

#[cfg(any(target_os = "linux", target_os = "macos"))]
yazi_fs::mounts::Partitions::monitor(PARTITIONS.clone(), Pubsub::pub_from_mount);
yazi_fs::mounts::Partitions::monitor(
yazi_fs::mounts::PARTITIONS.clone(),
yazi_dds::Pubsub::pub_from_mount,
);

tokio::spawn(Self::fan_out(out_rx));
Self { in_tx, out_tx }
Expand Down
13 changes: 13 additions & 0 deletions yazi-fm/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use std::{env::var_os, error::Error};

fn main() -> Result<(), Box<dyn Error>> {
if var_os("CARGO_CFG_TARGET_FAMILY").unwrap() != "windows"
|| var_os("PROFILE").unwrap() != "release"
{
return Ok(());
}

panic!(
"Unwinding must be enabled for Windows. Please use `cargo build --profile release-windows --locked` instead to build Yazi."
);
}
4 changes: 2 additions & 2 deletions yazi-fs/src/cha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ impl Cha {
}

#[inline]
pub fn new_nofollow(path: &Path, meta: Metadata) -> Self {
pub fn new_nofollow(_path: &Path, meta: Metadata) -> Self {
let mut attached = ChaKind::empty();

#[cfg(unix)]
if yazi_shared::url::Urn::new(path).is_hidden() {
if yazi_shared::url::Urn::new(_path).is_hidden() {
attached |= ChaKind::HIDDEN;
}
#[cfg(windows)]
Expand Down
12 changes: 6 additions & 6 deletions yazi-fs/src/mounts/partition.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{ffi::{OsStr, OsString}, path::PathBuf};
use std::{ffi::OsString, path::PathBuf};

#[derive(Debug, Default)]
pub struct Partition {
Expand All @@ -19,14 +19,14 @@ impl Partition {

#[rustfmt::skip]
pub fn systemic(&self) -> bool {
let b: &[u8] = self.fstype.as_ref().map_or(b"", |s| s.as_encoded_bytes());
let _b: &[u8] = self.fstype.as_ref().map_or(b"", |s| s.as_encoded_bytes());
#[cfg(target_os = "linux")]
{
matches!(b, b"autofs" | b"binfmt_misc" | b"bpf" | b"cgroup2" | b"configfs" | b"debugfs" | b"devpts" | b"devtmpfs" | b"fuse.gvfsd-fuse" | b"fusectl" | b"hugetlbfs" | b"mqueue" | b"proc" | b"pstore" | b"ramfs" | b"securityfs" | b"sysfs" | b"tmpfs" | b"tracefs")
matches!(_b, b"autofs" | b"binfmt_misc" | b"bpf" | b"cgroup2" | b"configfs" | b"debugfs" | b"devpts" | b"devtmpfs" | b"fuse.gvfsd-fuse" | b"fusectl" | b"hugetlbfs" | b"mqueue" | b"proc" | b"pstore" | b"ramfs" | b"securityfs" | b"sysfs" | b"tmpfs" | b"tracefs")
}
#[cfg(target_os = "macos")]
{
b.is_empty()
_b.is_empty()
}
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
{
Expand All @@ -38,13 +38,13 @@ impl Partition {
impl Partition {
#[inline]
#[cfg(any(target_os = "linux", target_os = "macos"))]
pub(super) fn new(name: &OsStr) -> Self {
pub(super) fn new(name: &std::ffi::OsStr) -> Self {
Self { src: std::path::Path::new("/dev/").join(name).into(), ..Default::default() }
}

#[inline]
#[cfg(target_os = "linux")]
pub(super) fn dev_name(&self) -> Option<&OsStr> {
pub(super) fn dev_name(&self) -> Option<&std::ffi::OsStr> {
std::path::Path::new(&self.src).strip_prefix("/dev/").ok().map(|p| p.as_os_str())
}
}
4 changes: 2 additions & 2 deletions yazi-fs/src/mounts/partitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ impl Partitions {
self.inner.iter().find(|p| p.rdev == Some(dev))
}

pub fn heuristic(&self, cha: Cha) -> bool {
pub fn heuristic(&self, _cha: Cha) -> bool {
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
self.by_dev(cha.dev).is_none_or(|p| p.heuristic())
self.by_dev(_cha.dev).is_none_or(|p| p.heuristic())
}
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
{
Expand Down
3 changes: 2 additions & 1 deletion yazi-plugin/src/bindings/cha.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{ops::{Deref, Not}, time::{Duration, SystemTime, UNIX_EPOCH}};
use std::{ops::Deref, time::{Duration, SystemTime, UNIX_EPOCH}};

use mlua::{ExternalError, FromLua, IntoLua, Lua, Table, UserData, UserDataFields, UserDataMethods};
use yazi_fs::ChaKind;
Expand Down Expand Up @@ -74,6 +74,7 @@ impl UserData for Cha {

#[cfg(unix)]
{
use std::ops::Not;
fields.add_field_method_get("dev", |_, me| Ok(me.is_dummy().not().then_some(me.dev)));
fields.add_field_method_get("uid", |_, me| Ok(me.is_dummy().not().then_some(me.uid)));
fields.add_field_method_get("gid", |_, me| Ok(me.is_dummy().not().then_some(me.gid)));
Expand Down
1 change: 1 addition & 0 deletions yazi-plugin/src/utils/user.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(unix)]
use mlua::{Function, Lua};

use super::Utils;
Expand Down

0 comments on commit 64a9bf2

Please sign in to comment.