mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 14:51:03 +00:00
fix: get rid of the Cargo curse (#3952)
This commit is contained in:
parent
22fb9e0d09
commit
247f925e53
16 changed files with 219 additions and 105 deletions
|
|
@ -1069,7 +1069,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
|
||||||
[v25.12.29]: https://github.com/sxyazi/yazi/compare/v25.5.31...v25.12.29
|
[v25.12.29]: https://github.com/sxyazi/yazi/compare/v25.5.31...v25.12.29
|
||||||
[v26.1.4]: https://github.com/sxyazi/yazi/compare/v25.12.29...v26.1.4
|
[v26.1.4]: https://github.com/sxyazi/yazi/compare/v25.12.29...v26.1.4
|
||||||
[v26.1.22]: https://github.com/sxyazi/yazi/compare/v26.1.4...v26.1.22
|
[v26.1.22]: https://github.com/sxyazi/yazi/compare/v26.1.4...v26.1.22
|
||||||
[v26.5.6]: https://github.com/sxyazi/yazi/compare/v26.5.6...v26.5.6
|
[v26.5.6]: https://github.com/sxyazi/yazi/compare/v26.1.22...v26.5.6
|
||||||
[#4]: https://github.com/sxyazi/yazi/pull/4
|
[#4]: https://github.com/sxyazi/yazi/pull/4
|
||||||
[#5]: https://github.com/sxyazi/yazi/pull/5
|
[#5]: https://github.com/sxyazi/yazi/pull/5
|
||||||
[#6]: https://github.com/sxyazi/yazi/pull/6
|
[#6]: https://github.com/sxyazi/yazi/pull/6
|
||||||
|
|
|
||||||
5
Cargo.lock
generated
5
Cargo.lock
generated
|
|
@ -5892,8 +5892,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yazi-build"
|
name = "yazi-build"
|
||||||
version = "26.5.6"
|
version = "26.5.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"yazi-tty",
|
"yazi-tty",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -6345,7 +6346,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yazi-tty"
|
name = "yazi-tty"
|
||||||
version = "26.5.6"
|
version = "26.5.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ yazi-scheduler = { path = "../yazi-scheduler", version = "26.5.6" }
|
||||||
yazi-shared = { path = "../yazi-shared", version = "26.5.6" }
|
yazi-shared = { path = "../yazi-shared", version = "26.5.6" }
|
||||||
yazi-shim = { path = "../yazi-shim", version = "26.5.6" }
|
yazi-shim = { path = "../yazi-shim", version = "26.5.6" }
|
||||||
yazi-term = { path = "../yazi-term", version = "26.5.6" }
|
yazi-term = { path = "../yazi-term", version = "26.5.6" }
|
||||||
yazi-tty = { path = "../yazi-tty", version = "26.5.6" }
|
yazi-tty = { path = "../yazi-tty", version = "26.5.9" }
|
||||||
yazi-vfs = { path = "../yazi-vfs", version = "26.5.6" }
|
yazi-vfs = { path = "../yazi-vfs", version = "26.5.6" }
|
||||||
yazi-watcher = { path = "../yazi-watcher", version = "26.5.6" }
|
yazi-watcher = { path = "../yazi-watcher", version = "26.5.6" }
|
||||||
yazi-widgets = { path = "../yazi-widgets", version = "26.5.6" }
|
yazi-widgets = { path = "../yazi-widgets", version = "26.5.6" }
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ yazi-fs = { path = "../yazi-fs", version = "26.5.6" }
|
||||||
yazi-macro = { path = "../yazi-macro", version = "26.5.6" }
|
yazi-macro = { path = "../yazi-macro", version = "26.5.6" }
|
||||||
yazi-shared = { path = "../yazi-shared", version = "26.5.6" }
|
yazi-shared = { path = "../yazi-shared", version = "26.5.6" }
|
||||||
yazi-shim = { path = "../yazi-shim", version = "26.5.6" }
|
yazi-shim = { path = "../yazi-shim", version = "26.5.6" }
|
||||||
yazi-tty = { path = "../yazi-tty", version = "26.5.6" }
|
yazi-tty = { path = "../yazi-tty", version = "26.5.9" }
|
||||||
|
|
||||||
# External dependencies
|
# External dependencies
|
||||||
ansi-to-tui = { workspace = true }
|
ansi-to-tui = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "yazi-build"
|
name = "yazi-build"
|
||||||
description = "Yazi build system"
|
description = "Yazi build system"
|
||||||
version.workspace = true
|
version = "26.5.9"
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|
@ -12,14 +12,9 @@ rust-version.workspace = true
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
codegen-units = 1
|
|
||||||
lto = true
|
|
||||||
panic = "abort"
|
|
||||||
strip = true
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
yazi-tty = { path = "../yazi-tty", version = "26.5.6" }
|
anyhow = { workspace = true }
|
||||||
|
yazi-tty = { path = "../yazi-tty", version = "26.5.9" }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "yazi-build"
|
name = "yazi-build"
|
||||||
|
|
|
||||||
|
|
@ -1,70 +1,140 @@
|
||||||
use std::{env, error::Error, io::{BufRead, BufReader, Read, Write}, process::{Command, Stdio}, thread};
|
use std::{env, fs, io::Write, path::{Path, PathBuf}, process::{self, Command, Stdio}, time::{SystemTime, UNIX_EPOCH}};
|
||||||
|
|
||||||
|
use anyhow::{Context, Result, bail, ensure};
|
||||||
use yazi_tty::TTY;
|
use yazi_tty::TTY;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<()> {
|
||||||
yazi_tty::init();
|
yazi_tty::init();
|
||||||
|
|
||||||
let manifest = env::var_os("CARGO_MANIFEST_DIR").unwrap().to_string_lossy().replace(r"\", "/");
|
let manifest = env::var_os("CARGO_MANIFEST_DIR")
|
||||||
let crates = if manifest.contains("/git/checkouts/yazi-") {
|
.context("missing CARGO_MANIFEST_DIR")?
|
||||||
&["--git", "https://github.com/sxyazi/yazi.git", "yazi-fm", "yazi-cli"]
|
.to_string_lossy()
|
||||||
} else if manifest.contains("/registry/src/index.crates.io-") {
|
.replace(r"\", "/");
|
||||||
&["yazi-fm", "yazi-cli"][..]
|
|
||||||
|
let rev = if manifest.contains("/registry/src/index.crates.io-") {
|
||||||
|
Some("shipped")
|
||||||
|
} else if manifest.contains("/git/checkouts/yazi-") {
|
||||||
|
None
|
||||||
} else {
|
} else {
|
||||||
|
println!("cargo::warning=Unexpected manifest dir: {manifest}");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
let target = env::var("TARGET").unwrap();
|
let os = env::var("CARGO_CFG_TARGET_OS").context("missing CARGO_CFG_TARGET_OS")?;
|
||||||
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
|
let tmp = temp_repo_dir()?;
|
||||||
unsafe {
|
|
||||||
env::set_var("CARGO_TARGET_DIR", "target");
|
|
||||||
env::set_var("VERGEN_GIT_SHA", "Crates.io");
|
|
||||||
env::set_var("YAZI_CRATE_BUILD", "1");
|
|
||||||
|
|
||||||
env::set_var("JEMALLOC_SYS_WITH_LG_PAGE", "16");
|
TTY.writer().write_all(b"\nCloning Yazi repository...\n")?;
|
||||||
env::set_var("JEMALLOC_SYS_WITH_MALLOC_CONF", "narenas:1");
|
clone_repo(&tmp, rev).context("Failed to clone the Yazi repository")?;
|
||||||
|
|
||||||
env::set_var(
|
TTY.writer().write_all(b"\nBuilding Yazi binaries...\n")?;
|
||||||
"MACOSX_DEPLOYMENT_TARGET",
|
build_repo(&tmp, &os).context("Failed to build Yazi from the cloned repository")?;
|
||||||
if target == "aarch64-apple-darwin" { "11.0" } else { "10.12" },
|
|
||||||
);
|
|
||||||
if target == "aarch64-apple-darwin" {
|
|
||||||
env::set_var("RUSTFLAGS", "-Ctarget-cpu=apple-m1");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let profile = if target_os == "windows" { &["--profile", "release-windows"][..] } else { &[] };
|
TTY.writer().write_all(b"\nInstalling yazi and ya into cargo bin...\n")?;
|
||||||
let mut child = Command::new(env::var_os("CARGO").unwrap())
|
install_bins(&tmp, &os).context("Failed to install `yazi` and `ya` into cargo bin")?;
|
||||||
.args(["install", "--force", "--locked"])
|
|
||||||
.args(profile)
|
|
||||||
.args(crates)
|
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.stderr(Stdio::piped())
|
|
||||||
.spawn()?;
|
|
||||||
|
|
||||||
let out = flash(child.stdout.take().unwrap());
|
|
||||||
let err = flash(child.stderr.take().unwrap());
|
|
||||||
|
|
||||||
child.wait()?;
|
|
||||||
out.join().ok();
|
|
||||||
err.join().ok();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flash<R: Read + Send + 'static>(src: R) -> thread::JoinHandle<()> {
|
fn temp_repo_dir() -> Result<PathBuf> {
|
||||||
thread::spawn(move || {
|
let nonce = SystemTime::now()
|
||||||
let reader = BufReader::new(src);
|
.duration_since(UNIX_EPOCH)
|
||||||
for part in reader.split(b'\n') {
|
.map(|d| d.as_nanos())
|
||||||
match part {
|
.context("Time went backwards")?;
|
||||||
Ok(mut bytes) => {
|
|
||||||
bytes.push(b'\n');
|
Ok(env::temp_dir().join(format!("yazi-build-{}-{nonce}", process::id())))
|
||||||
let mut out = TTY.lockout();
|
}
|
||||||
out.write_all(&bytes).ok();
|
|
||||||
out.flush().ok();
|
fn clone_repo(tmp: &Path, rev: Option<&str>) -> Result<()> {
|
||||||
}
|
let mut cmd = Command::new("git");
|
||||||
Err(_) => break,
|
cmd.args(["-c", "advice.detachedHead=false", "clone", "--depth", "1"]);
|
||||||
}
|
|
||||||
}
|
if let Some(rev) = rev {
|
||||||
})
|
cmd.args(["--branch", rev]);
|
||||||
|
}
|
||||||
|
|
||||||
|
run_streamed(cmd.arg("https://github.com/sxyazi/yazi.git").arg(tmp))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_repo(tmp: &Path, target_os: &str) -> Result<()> {
|
||||||
|
let cargo = env::var_os("CARGO").unwrap_or_else(|| "cargo".into());
|
||||||
|
|
||||||
|
let mut cmd = Command::new(cargo);
|
||||||
|
cmd.current_dir(tmp).arg("build").env("CARGO_TARGET_DIR", "target").arg("--locked");
|
||||||
|
|
||||||
|
if target_os == "windows" {
|
||||||
|
cmd.args(["--profile", "release-windows"]);
|
||||||
|
} else {
|
||||||
|
cmd.arg("--release");
|
||||||
|
}
|
||||||
|
|
||||||
|
run_streamed(&mut cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn install_bins(tmp: &Path, target_os: &str) -> Result<()> {
|
||||||
|
let profile = if target_os == "windows" { "release-windows" } else { "release" };
|
||||||
|
let ext = if target_os == "windows" { ".exe" } else { "" };
|
||||||
|
let bin_dir = cargo_bin_dir()?;
|
||||||
|
|
||||||
|
fs::create_dir_all(&bin_dir)?;
|
||||||
|
install_bin(
|
||||||
|
&tmp.join("target").join(profile).join(format!("yazi{ext}")),
|
||||||
|
&bin_dir.join(format!("yazi{ext}")),
|
||||||
|
)?;
|
||||||
|
install_bin(
|
||||||
|
&tmp.join("target").join(profile).join(format!("ya{ext}")),
|
||||||
|
&bin_dir.join(format!("ya{ext}")),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn install_bin(from: &Path, to: &Path) -> Result<()> {
|
||||||
|
ensure!(from.is_file(), "Built binary not found: {}", from.display());
|
||||||
|
|
||||||
|
if to.exists() {
|
||||||
|
fs::remove_file(to)
|
||||||
|
.with_context(|| format!("failed to remove existing binary: {}", to.display()))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::copy(from, to)
|
||||||
|
.with_context(|| format!("failed to copy {} to {}", from.display(), to.display()))?;
|
||||||
|
fs::set_permissions(to, fs::metadata(from)?.permissions())
|
||||||
|
.with_context(|| format!("failed to preserve permissions on {}", to.display()))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cargo_bin_dir() -> Result<PathBuf> {
|
||||||
|
if let Some(root) = env::var_os("CARGO_INSTALL_ROOT") {
|
||||||
|
return Ok(PathBuf::from(root).join("bin"));
|
||||||
|
}
|
||||||
|
if let Some(home) = env::var_os("CARGO_HOME") {
|
||||||
|
return Ok(PathBuf::from(home).join("bin"));
|
||||||
|
}
|
||||||
|
if let Some(home) = env::var_os("HOME") {
|
||||||
|
return Ok(PathBuf::from(home).join(".cargo/bin"));
|
||||||
|
}
|
||||||
|
if let Some(home) = env::var_os("USERPROFILE") {
|
||||||
|
return Ok(PathBuf::from(home).join(".cargo/bin"));
|
||||||
|
}
|
||||||
|
bail!("Failed to determine cargo bin directory")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_streamed(cmd: &mut Command) -> Result<()> {
|
||||||
|
let stdin = {
|
||||||
|
let input = TTY.lockin();
|
||||||
|
Stdio::from(input.try_clone()?)
|
||||||
|
};
|
||||||
|
|
||||||
|
let (stdout, stderr) = {
|
||||||
|
let mut output = TTY.lockout();
|
||||||
|
output.flush()?;
|
||||||
|
|
||||||
|
(Stdio::from(output.get_ref().try_clone()?), Stdio::from(output.get_ref().try_clone()?))
|
||||||
|
};
|
||||||
|
|
||||||
|
let status =
|
||||||
|
cmd.stdin(stdin).stdout(stdout).stderr(stderr).status().context("failed to spawn process")?;
|
||||||
|
|
||||||
|
ensure!(status.success(), "process exited with status {status}");
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,16 +12,6 @@ rust-version.workspace = true
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
codegen-units = 1
|
|
||||||
lto = true
|
|
||||||
panic = "abort"
|
|
||||||
strip = true
|
|
||||||
|
|
||||||
[profile.release-windows]
|
|
||||||
inherits = "release"
|
|
||||||
panic = "unwind"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
yazi-boot = { path = "../yazi-boot", version = "26.5.6" }
|
yazi-boot = { path = "../yazi-boot", version = "26.5.6" }
|
||||||
yazi-dds = { path = "../yazi-dds", version = "26.5.6" }
|
yazi-dds = { path = "../yazi-dds", version = "26.5.6" }
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,11 @@ use vergen_gitcl::{BuildBuilder, Emitter, GitclBuilder};
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let manifest = env::var_os("CARGO_MANIFEST_DIR").unwrap().to_string_lossy().replace(r"\", "/");
|
let manifest = env::var_os("CARGO_MANIFEST_DIR").unwrap().to_string_lossy().replace(r"\", "/");
|
||||||
if env::var_os("YAZI_CRATE_BUILD").is_none()
|
if manifest.contains("/git/checkouts/yazi-")
|
||||||
&& (manifest.contains("/git/checkouts/yazi-")
|
|| manifest.contains("/registry/src/index.crates.io-")
|
||||||
|| manifest.contains("/registry/src/index.crates.io-"))
|
|
||||||
{
|
{
|
||||||
panic!(
|
panic!(
|
||||||
"Due to Cargo's limitations, the `yazi-fm` and `yazi-cli` crates on crates.io must be built with `cargo install --force yazi-build`"
|
"Due to Cargo's limitations, Yazi on crates.io must be built with `cargo install --force yazi-build`"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ yazi-fs = { path = "../yazi-fs", version = "26.5.6" }
|
||||||
yazi-macro = { path = "../yazi-macro", version = "26.5.6" }
|
yazi-macro = { path = "../yazi-macro", version = "26.5.6" }
|
||||||
yazi-shared = { path = "../yazi-shared", version = "26.5.6" }
|
yazi-shared = { path = "../yazi-shared", version = "26.5.6" }
|
||||||
yazi-shim = { path = "../yazi-shim", version = "26.5.6" }
|
yazi-shim = { path = "../yazi-shim", version = "26.5.6" }
|
||||||
yazi-tty = { path = "../yazi-tty", version = "26.5.6" }
|
yazi-tty = { path = "../yazi-tty", version = "26.5.9" }
|
||||||
|
|
||||||
# External dependencies
|
# External dependencies
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ workspace = true
|
||||||
yazi-macro = { path = "../yazi-macro", version = "26.5.6" }
|
yazi-macro = { path = "../yazi-macro", version = "26.5.6" }
|
||||||
yazi-shared = { path = "../yazi-shared", version = "26.5.6" }
|
yazi-shared = { path = "../yazi-shared", version = "26.5.6" }
|
||||||
yazi-shim = { path = "../yazi-shim", version = "26.5.6" }
|
yazi-shim = { path = "../yazi-shim", version = "26.5.6" }
|
||||||
yazi-tty = { path = "../yazi-tty", version = "26.5.6" }
|
yazi-tty = { path = "../yazi-tty", version = "26.5.9" }
|
||||||
|
|
||||||
# External dependencies
|
# External dependencies
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -12,16 +12,6 @@ rust-version.workspace = true
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
codegen-units = 1
|
|
||||||
lto = true
|
|
||||||
panic = "abort"
|
|
||||||
strip = true
|
|
||||||
|
|
||||||
[profile.release-windows]
|
|
||||||
inherits = "release"
|
|
||||||
panic = "unwind"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [ "vendored-lua" ]
|
default = [ "vendored-lua" ]
|
||||||
vendored-lua = [ "mlua/vendored" ]
|
vendored-lua = [ "mlua/vendored" ]
|
||||||
|
|
@ -45,7 +35,7 @@ yazi-scheduler = { path = "../yazi-scheduler", version = "26.5.6" }
|
||||||
yazi-shared = { path = "../yazi-shared", version = "26.5.6" }
|
yazi-shared = { path = "../yazi-shared", version = "26.5.6" }
|
||||||
yazi-shim = { path = "../yazi-shim", version = "26.5.6" }
|
yazi-shim = { path = "../yazi-shim", version = "26.5.6" }
|
||||||
yazi-term = { path = "../yazi-term", version = "26.5.6" }
|
yazi-term = { path = "../yazi-term", version = "26.5.6" }
|
||||||
yazi-tty = { path = "../yazi-tty", version = "26.5.6" }
|
yazi-tty = { path = "../yazi-tty", version = "26.5.9" }
|
||||||
yazi-vfs = { path = "../yazi-vfs", version = "26.5.6" }
|
yazi-vfs = { path = "../yazi-vfs", version = "26.5.6" }
|
||||||
yazi-watcher = { path = "../yazi-watcher", version = "26.5.6" }
|
yazi-watcher = { path = "../yazi-watcher", version = "26.5.6" }
|
||||||
yazi-widgets = { path = "../yazi-widgets", version = "26.5.6" }
|
yazi-widgets = { path = "../yazi-widgets", version = "26.5.6" }
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let manifest = env::var_os("CARGO_MANIFEST_DIR").unwrap().to_string_lossy().replace(r"\", "/");
|
let manifest = env::var_os("CARGO_MANIFEST_DIR").unwrap().to_string_lossy().replace(r"\", "/");
|
||||||
if env::var_os("YAZI_CRATE_BUILD").is_none()
|
if manifest.contains("/git/checkouts/yazi-")
|
||||||
&& (manifest.contains("/git/checkouts/yazi-")
|
|| manifest.contains("/registry/src/index.crates.io-")
|
||||||
|| manifest.contains("/registry/src/index.crates.io-"))
|
|
||||||
{
|
{
|
||||||
panic!(
|
panic!(
|
||||||
"Due to Cargo's limitations, the `yazi-fm` and `yazi-cli` crates on crates.io must be built with `cargo install --force yazi-build`"
|
"Due to Cargo's limitations, Yazi on crates.io must be built with `cargo install --force yazi-build`"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ yazi-config = { path = "../yazi-config", version = "26.5.6" }
|
||||||
yazi-emulator = { path = "../yazi-emulator", version = "26.5.6" }
|
yazi-emulator = { path = "../yazi-emulator", version = "26.5.6" }
|
||||||
yazi-macro = { path = "../yazi-macro", version = "26.5.6" }
|
yazi-macro = { path = "../yazi-macro", version = "26.5.6" }
|
||||||
yazi-shim = { path = "../yazi-shim", version = "26.5.6" }
|
yazi-shim = { path = "../yazi-shim", version = "26.5.6" }
|
||||||
yazi-tty = { path = "../yazi-tty", version = "26.5.6" }
|
yazi-tty = { path = "../yazi-tty", version = "26.5.9" }
|
||||||
|
|
||||||
# External dependencies
|
# External dependencies
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "yazi-tty"
|
name = "yazi-tty"
|
||||||
description = "Yazi TTY access layer"
|
description = "Yazi TTY access layer"
|
||||||
version.workspace = true
|
version = "26.5.9"
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{io::{Error, ErrorKind, Read, Write}, time::Duration};
|
use std::{io::{Error, ErrorKind, Read, Write}, ptr, time::Duration};
|
||||||
|
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
|
|
@ -27,6 +27,24 @@ impl Drop for Handle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
impl From<Handle> for std::process::Stdio {
|
||||||
|
fn from(value: Handle) -> Self {
|
||||||
|
use std::os::fd::{FromRawFd, IntoRawFd, OwnedFd};
|
||||||
|
|
||||||
|
Self::from(unsafe { OwnedFd::from_raw_fd(value.into_raw_fd()) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
impl From<Handle> for std::process::Stdio {
|
||||||
|
fn from(value: Handle) -> Self {
|
||||||
|
use std::os::windows::io::{FromRawHandle, IntoRawHandle, OwnedHandle};
|
||||||
|
|
||||||
|
Self::from(unsafe { OwnedHandle::from_raw_handle(value.into_raw_handle()) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Read for Handle {
|
impl Read for Handle {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
|
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
|
@ -75,6 +93,22 @@ impl Write for Handle {
|
||||||
fn flush(&mut self) -> std::io::Result<()> { Ok(()) }
|
fn flush(&mut self) -> std::io::Result<()> { Ok(()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
impl std::os::fd::IntoRawFd for Handle {
|
||||||
|
fn into_raw_fd(mut self) -> std::os::fd::RawFd {
|
||||||
|
self.close = false;
|
||||||
|
self.inner
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
impl std::os::windows::io::IntoRawHandle for Handle {
|
||||||
|
fn into_raw_handle(mut self) -> std::os::windows::io::RawHandle {
|
||||||
|
self.close = false;
|
||||||
|
self.inner
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
impl Handle {
|
impl Handle {
|
||||||
pub(super) fn new(out: bool) -> Self {
|
pub(super) fn new(out: bool) -> Self {
|
||||||
|
|
@ -106,7 +140,7 @@ impl Handle {
|
||||||
let mut set: libc::fd_set = std::mem::zeroed();
|
let mut set: libc::fd_set = std::mem::zeroed();
|
||||||
libc::FD_ZERO(&mut set);
|
libc::FD_ZERO(&mut set);
|
||||||
libc::FD_SET(self.inner, &mut set);
|
libc::FD_SET(self.inner, &mut set);
|
||||||
libc::select(self.inner + 1, &mut set, std::ptr::null_mut(), std::ptr::null_mut(), &mut tv)
|
libc::select(self.inner + 1, &mut set, ptr::null_mut(), ptr::null_mut(), &mut tv)
|
||||||
};
|
};
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
|
|
@ -124,6 +158,13 @@ impl Handle {
|
||||||
_ => Ok(b),
|
_ => Ok(b),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn try_clone(&self) -> std::io::Result<Self> {
|
||||||
|
match unsafe { libc::dup(self.inner) } {
|
||||||
|
-1 => Err(Error::last_os_error()),
|
||||||
|
fd => Ok(Self { inner: fd, close: true }),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
|
@ -139,10 +180,10 @@ impl Handle {
|
||||||
name.as_ptr(),
|
name.as_ptr(),
|
||||||
GENERIC_READ | GENERIC_WRITE,
|
GENERIC_READ | GENERIC_WRITE,
|
||||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
std::ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
OPEN_EXISTING,
|
OPEN_EXISTING,
|
||||||
0,
|
0,
|
||||||
std::ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -184,7 +225,7 @@ impl Handle {
|
||||||
|
|
||||||
let mut buf = 0;
|
let mut buf = 0;
|
||||||
let mut bytes = 0;
|
let mut bytes = 0;
|
||||||
let success = unsafe { ReadFile(self.inner, &mut buf, 1, &mut bytes, std::ptr::null_mut()) };
|
let success = unsafe { ReadFile(self.inner, &mut buf, 1, &mut bytes, ptr::null_mut()) };
|
||||||
|
|
||||||
if success == 0 {
|
if success == 0 {
|
||||||
return Err(Error::last_os_error());
|
return Err(Error::last_os_error());
|
||||||
|
|
@ -193,4 +234,33 @@ impl Handle {
|
||||||
}
|
}
|
||||||
Ok(buf)
|
Ok(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn try_clone(&self) -> std::io::Result<Self> {
|
||||||
|
use windows_sys::Win32::{Foundation::{DUPLICATE_SAME_ACCESS, DuplicateHandle, HANDLE}, System::Threading::GetCurrentProcess};
|
||||||
|
|
||||||
|
let proc = unsafe { GetCurrentProcess() };
|
||||||
|
let mut handle = ptr::null_mut();
|
||||||
|
let status = unsafe {
|
||||||
|
DuplicateHandle(
|
||||||
|
proc,
|
||||||
|
self.inner,
|
||||||
|
proc,
|
||||||
|
&mut handle as *mut HANDLE,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
DUPLICATE_SAME_ACCESS,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
if status == 0 {
|
||||||
|
Err(Error::last_os_error())
|
||||||
|
} else {
|
||||||
|
Ok(Self {
|
||||||
|
inner: handle,
|
||||||
|
close: true,
|
||||||
|
out_utf8: self.out_utf8,
|
||||||
|
incomplete_utf8: Default::default(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ yazi-config = { path = "../yazi-config", version = "26.5.6" }
|
||||||
yazi-macro = { path = "../yazi-macro", version = "26.5.6" }
|
yazi-macro = { path = "../yazi-macro", version = "26.5.6" }
|
||||||
yazi-shared = { path = "../yazi-shared", version = "26.5.6" }
|
yazi-shared = { path = "../yazi-shared", version = "26.5.6" }
|
||||||
yazi-shim = { path = "../yazi-shim", version = "26.5.6" }
|
yazi-shim = { path = "../yazi-shim", version = "26.5.6" }
|
||||||
yazi-tty = { path = "../yazi-tty", version = "26.5.6" }
|
yazi-tty = { path = "../yazi-tty", version = "26.5.9" }
|
||||||
|
|
||||||
# External dependencies
|
# External dependencies
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue