Add linux stubs for rust functions

This commit is contained in:
caesay
2024-01-09 16:40:56 +00:00
parent d42c3a5f67
commit 57e7a00906
11 changed files with 224 additions and 24 deletions

View File

@@ -0,0 +1,34 @@
#!/bin/bash
# Find the absolute path of the script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Check if version parameter is provided
if [ "$#" -ne 1 ]; then
echo "Please provide a version number."
echo "Usage: ./build.sh version_number"
exit 1
fi
echo "Building Velopack"
cd "$SCRIPT_DIR/../../src/Rust"
cargo build
cd "$SCRIPT_DIR/../.."
dotnet build src/Velopack.Vpk/Velopack.Vpk.csproj
cd "$SCRIPT_DIR"
version="$1"
releasesDir="$SCRIPT_DIR/releases"
# Write to Const.cs
echo "class Const { public const string RELEASES_DIR = @\"$releasesDir\"; } " > "$(dirname "$0")/Const.cs"
echo "Const.cs file updated with releases directory ($releasesDir)."
echo "Compiling AvaloniaCrossPlat with dotnet..."
dotnet publish -c Release --self-contained -r linux-x64 -o "$(dirname "$0")/publish"
echo "class Const { public const string RELEASES_DIR = @\"{REPLACE_ME}\"; } " > "$(dirname "$0")/Const.cs"
echo "Const.cs file reset"
echo "Building Velopack Release v$version"
"$(dirname "$0")/../../build/Debug/net8.0/vpk" pack -u AvaloniaCrossPlat -v "$version" -o "$releasesDir" -p "$(dirname "$0")/publish" -i Velopack.icns

107
src/Rust/Cargo.lock generated
View File

@@ -183,6 +183,12 @@ dependencies = [
"libc",
]
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
@@ -351,7 +357,7 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@@ -360,7 +366,7 @@ version = "0.8.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3a430a770ebd84726f584a90ee7f020d28db52c6d02138900f22341f866d39c"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@@ -369,7 +375,7 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2ae9bf77fbf2d39ef573205d554d87e86c12f1994e9ea335b0651b9b278bcf1"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
]
[[package]]
@@ -392,6 +398,16 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "dialog"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "736bab36d647d14c985725a57a4110a1182c6852104536cd42f1c97e96d29bf0"
dependencies = [
"dirs",
"rpassword",
]
[[package]]
name = "digest"
version = "0.9.0"
@@ -401,16 +417,37 @@ dependencies = [
"generic-array",
]
[[package]]
name = "dirs"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3"
dependencies = [
"cfg-if 0.1.10",
"dirs-sys",
]
[[package]]
name = "dirs-next"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"dirs-sys-next",
]
[[package]]
name = "dirs-sys"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
dependencies = [
"libc",
"redox_users",
"winapi 0.3.9",
]
[[package]]
name = "dirs-sys-next"
version = "0.1.2"
@@ -419,7 +456,7 @@ checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
dependencies = [
"libc",
"redox_users",
"winapi",
"winapi 0.3.9",
]
[[package]]
@@ -548,7 +585,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "982f82cc75107eef84f417ad6c53ae89bf65b561937ca4a3b3b0fd04d0aa2425"
dependencies = [
"aligned",
"cfg-if",
"cfg-if 1.0.0",
"cvt",
"libc",
"nix",
@@ -577,7 +614,7 @@ version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
]
@@ -717,6 +754,16 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
dependencies = [
"winapi 0.2.8",
"winapi-build",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
@@ -812,7 +859,7 @@ dependencies = [
"versions",
"wfd",
"which",
"winapi",
"winapi 0.3.9",
]
[[package]]
@@ -840,7 +887,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b"
dependencies = [
"bitflags 1.3.2",
"cfg-if",
"cfg-if 1.0.0",
"libc",
]
@@ -983,7 +1030,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cde4d2d9200ad5909f8dac647e29482e07c3a35de8a13fce7c9c7747ad9f671"
dependencies = [
"bitflags 2.4.1",
"cfg-if",
"cfg-if 1.0.0",
"foreign-types 0.3.2",
"libc",
"once_cell",
@@ -1193,7 +1240,7 @@ name = "remove_dir_all"
version = "0.8.2"
source = "git+https://github.com/caesay/remove_dir_all.git#c98142b9150c53e6c5f56e752d2bf93433f2e207"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"cvt",
"fs_at",
"libc",
@@ -1203,6 +1250,17 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "rpassword"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d37473170aedbe66ffa3ad3726939ba677d83c646ad4fd99e5b4bc38712f45ec"
dependencies = [
"kernel32-sys",
"libc",
"winapi 0.2.8",
]
[[package]]
name = "runas"
version = "1.1.0"
@@ -1308,7 +1366,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6"
dependencies = [
"block-buffer",
"cfg-if",
"cfg-if 1.0.0",
"cpufeatures",
"digest",
"opaque-debug",
@@ -1327,7 +1385,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800"
dependencies = [
"block-buffer",
"cfg-if",
"cfg-if 1.0.0",
"cpufeatures",
"digest",
"opaque-debug",
@@ -1421,7 +1479,7 @@ version = "3.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"fastrand",
"redox_syscall",
"rustix",
@@ -1465,7 +1523,7 @@ checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
"winapi 0.3.9",
]
[[package]]
@@ -1614,6 +1672,7 @@ dependencies = [
"clap",
"codesign-verify",
"derivative",
"dialog",
"enum-flags",
"file-rotate",
"fs_extra",
@@ -1703,7 +1762,7 @@ version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"wasm-bindgen-macro",
]
@@ -1764,7 +1823,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e713040b67aae5bf1a0ae3e1ebba8cc29ab2b90da9aa1bff6e09031a8a41d7a8"
dependencies = [
"libc",
"winapi",
"winapi 0.3.9",
]
[[package]]
@@ -1779,6 +1838,12 @@ dependencies = [
"rustix",
]
[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
[[package]]
name = "winapi"
version = "0.3.9"
@@ -1789,6 +1854,12 @@ dependencies = [
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
@@ -1801,7 +1872,7 @@ version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
dependencies = [
"winapi",
"winapi 0.3.9",
]
[[package]]

View File

@@ -76,10 +76,11 @@ zstd = "0.13"
sha1_smol = "1.0"
runas = "1.1"
[target.'cfg(target_os = "macos")'.dependencies]
[target.'cfg(unix)'.dependencies]
native-dialog = "0.7"
waitpid-any = "0.2"
bindet = "0.3"
dialog = "0.3"
[target.'cfg(windows)'.dependencies]
fs_extra = "1.2"

View File

@@ -389,6 +389,19 @@ impl Manifest {
}
}
#[cfg(target_os = "linux")]
impl Manifest {
pub fn get_packages_path(&self, _root_path: &PathBuf) -> String {
todo!();
}
pub fn get_current_path(&self, root_path: &PathBuf) -> String {
todo!();
}
pub fn get_nuspec_path(&self, root_path: &PathBuf) -> String {
todo!();
}
}
pub fn read_manifest_from_string(xml: &str) -> Result<Manifest> {
let mut obj: Manifest = Default::default();
let cursor = Cursor::new(xml);

View File

@@ -55,6 +55,7 @@ fn test_no_dialogs_show_if_silent() {
#[test]
#[ignore]
fn test_show_all_dialogs() {
set_silent(false);
show_error("Error", None, "This is an error.");
show_warn("Warning", None, "This is a warning.");
show_info("Information", None, "This is information.");

View File

@@ -0,0 +1,30 @@
use dialog::{DialogBox, Choice};
use super::dialogs_const::*;
use anyhow::{Result, anyhow};
pub fn generate_alert(title: &str, header: Option<&str>, body: &str, _ok_text: Option<&str>, _btns: DialogButton, _ico: DialogIcon) -> Result<()> {
let mut body = body.to_string();
if let Some(h) = header {
body = format!("{}\n{}", h, body);
}
dialog::Message::new(body).title(title).show()
.map_err(|e| anyhow!("Failed to open dialog ({})", e))?;
Ok(())
}
pub fn generate_confirm(title: &str, header: Option<&str>, body: &str, _ok_text: Option<&str>, _btns: DialogButton, _ico: DialogIcon) -> Result<DialogResult> {
let mut body = body.to_string();
if let Some(h) = header {
body = format!("{}\n{}", h, body);
}
let result = dialog::Question::new(body).title(title).show()
.map_err(|e| anyhow!("Failed to open dialog ({})", e))?;
Ok(match result {
Choice::Cancel => DialogResult::Cancel,
Choice::No => DialogResult::No,
Choice::Yes => DialogResult::Yes,
})
}

View File

@@ -6,6 +6,8 @@ mod dialogs_common;
mod dialogs_windows;
#[cfg(target_os = "macos")]
mod dialogs_osx;
#[cfg(target_os = "linux")]
mod dialogs_linux;
pub mod dialogs {
pub use super::dialogs_const::*;
@@ -14,6 +16,8 @@ pub mod dialogs {
pub use super::dialogs_windows::*;
#[cfg(target_os = "macos")]
pub use super::dialogs_osx::*;
#[cfg(target_os = "linux")]
pub use super::dialogs_linux::*;
}
mod util_common;
@@ -28,3 +32,8 @@ pub use util_windows::*;
mod util_osx;
#[cfg(target_os = "macos")]
pub use util_osx::*;
#[cfg(target_os = "linux")]
mod util_linux;
#[cfg(target_os = "linux")]
pub use util_linux::*;

View File

@@ -0,0 +1,37 @@
use crate::shared::bundle;
use super::bundle::Manifest;
use anyhow::{anyhow, bail, Result};
use std::{path::Path, path::PathBuf, process::Command as Process, time::Duration};
pub fn wait_for_parent_to_exit(ms_to_wait: u32) -> Result<()> {
let id = std::os::unix::process::parent_id();
info!("Attempting to wait for parent process ({}) to exit.", id);
if id >= 1 {
let id: i32 = id.try_into()?;
let mut handle = waitpid_any::WaitHandle::open(id)?;
let result = handle.wait_timeout(Duration::from_millis(ms_to_wait as u64))?;
if result.is_some() {
info!("Parent process exited.");
} else {
bail!("Parent process timed out.");
}
}
Ok(())
}
pub fn force_stop_package<P: AsRef<Path>>(root_dir: P) -> Result<()> {
todo!();
}
pub fn start_package<P: AsRef<Path>>(_app: &Manifest, root_dir: P, exe_args: Option<Vec<&str>>, set_env: Option<&str>) -> Result<()> {
todo!();
}
pub fn detect_manifest_from_update_path(update_exe: &PathBuf) -> Result<(PathBuf, Manifest)> {
todo!();
}
pub fn detect_current_manifest() -> Result<(PathBuf, Manifest)> {
todo!();
}

View File

@@ -67,9 +67,9 @@ fn parse_command_line_matches(input_args: Vec<String>) -> ArgMatches {
}
fn main() -> Result<()> {
#[cfg(target_os = "windows")]
#[cfg(windows)]
let matches = parse_command_line_matches(env::args().collect());
#[cfg(target_os = "macos")]
#[cfg(unix)]
let matches = root_command().get_matches();
let verbose = matches.get_flag("verbose");
@@ -168,14 +168,14 @@ fn uninstall(_matches: &ArgMatches) -> Result<()> {
}
pub fn default_logging(verbose: bool, nocolor: bool) -> Result<()> {
#[cfg(target_os = "windows")]
#[cfg(windows)]
let default_log_file = {
let mut my_dir = env::current_exe().unwrap();
my_dir.pop();
my_dir.join("Velopack.log")
};
#[cfg(target_os = "macos")]
#[cfg(unix)]
let default_log_file = {
let (_root, manifest) = shared::detect_current_manifest().expect("Unable to load app manfiest.");
std::path::Path::new(format!("/tmp/velopack/{}.log", manifest.id).as_str()).to_path_buf()

View File

@@ -18,8 +18,11 @@ public class HelperFile
#if DEBUG
public string UpdateMacPath => FindHelperFile("update", MachO.IsMachOImage);
public string UpdateNixPath => FindHelperFile("update");
#else
public string UpdateMacPath => FindHelperFile("UpdateMac", MachO.IsMachOImage);
public string UpdateNixPath => FindHelperFile("UpdateNix");
#endif
private static List<string> _searchPaths = new List<string>();

View File

@@ -24,7 +24,8 @@
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<None Include="..\Rust\target\debug\update" CopyToOutputDirectory="Always" Condition="$([MSBuild]::IsOSPlatform('OSX'))" />
<None Include="..\Rust\target\debug\update" CopyToOutputDirectory="Always"
Condition="$([MSBuild]::IsOSPlatform('OSX')) or $([MSBuild]::IsOSPlatform('Linux'))" />
<None Include="..\Rust\target\debug\update.exe" CopyToOutputDirectory="Always" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
<None Include="..\Rust\target\debug\setup.exe" CopyToOutputDirectory="Always" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
<None Include="..\Rust\target\debug\stub.exe" CopyToOutputDirectory="Always" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />