Skip to content

Commit

Permalink
fix(build): utpm-ci compile with shadow-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Thumuss committed Aug 19, 2024
1 parent 92d73d7 commit 82f6332
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ shadow-rs = "0.31.1"
[[bin]]
name = "utpm"
path = "src/main.rs"
build = "build.rs"

[[bin]]
name = "utpm-ci"
path = "src/ci.rs"
build = "build.rs"

[features]
ci = []
Expand Down
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use shadow_rs;

fn main() -> shadow_rs::SdResult<()> {
println!("cargo:rerun-if-changed=build.rs");
shadow_rs::new()
}
3 changes: 2 additions & 1 deletion src/ci.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;

use shadow_rs::shadow;
shadow!(build);
use commands::InstallArgs;

#[allow(unused)]
Expand Down
42 changes: 23 additions & 19 deletions src/commands/clone.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use tracing::{debug, info, instrument, warn};
use tracing::{debug, error, info, instrument, warn};
use typst_kit::{
download::{Downloader, ProgressSink},
package::PackageStorage,
};

use crate::{build, utils::ProgressPrint};

use crate::utils::{
copy_dir_all,
paths::{c_packages, check_path_dir, d_packages, get_current_dir, has_content},
Expand Down Expand Up @@ -37,30 +39,27 @@ pub fn run(cmd: &CloneArgs) -> Result<bool> {
let val = format!(
"{}/{namespace}/{package}/{major}.{minor}.{patch}",
if namespace == "preview" {
info!("preview found, cache dir use");
c_packages()?
} else {
info!("no preview found, data dir use");
d_packages()?
}
);
if check_path_dir(&val) {
//todo: trace
if cmd.download_only {
info!("download only, nothing to do.");
return Ok(true);
}
if !cmd.redownload || namespace != "preview" {
info!(
namespace = namespace,
redownload = cmd.redownload,
"Skip download..."
);
let string = format!("{}/{package}:{major}.{minor}.{patch}", get_current_dir()?);
if cmd.symlink {
symlink_all(
val,
get_current_dir()?
+ "/"
+ package
+ ":"
+ major
+ "."
+ minor
+ "."
+ patch,
)?;
symlink_all(val, string)?;
info!("symlinked!");
} else {
copy_dir_all(val, get_current_dir()?)?;
Expand All @@ -70,8 +69,12 @@ pub fn run(cmd: &CloneArgs) -> Result<bool> {
}
}

let pkg_sto = PackageStorage::new(None, None, Downloader::new("utpm/latest"));
let sink = &mut ProgressSink {};
let pkg_sto = PackageStorage::new(
None,
None,
Downloader::new(format!("utpm/{}", build::COMMIT_HASH)),
);
let printer = &mut ProgressPrint {};
return match pkg_sto.prepare_package(
&PackageSpec {
namespace: namespace.into(),
Expand All @@ -82,10 +85,10 @@ pub fn run(cmd: &CloneArgs) -> Result<bool> {
patch: patch.parse::<u32>().unwrap(),
},
},
sink,
printer,
) {
Ok(val) => {
info!("package downloaded");
info!(path = val.to_str().unwrap(), "package downloaded");
if cmd.download_only {
debug!("download complete, nothing to do");
return Ok(true);
Expand All @@ -104,11 +107,12 @@ pub fn run(cmd: &CloneArgs) -> Result<bool> {
Err(_) => {
return Err(Error::new(
ErrorKind::PackageNotExist,
"This package doesn't exist. Verify on https://typst.app/universe to see if the package exist and/or the version is correct.", //todo
"This package doesn't exist. Verify on https://typst.app/universe to see if the package exist and/or the version is correct.",
));
}
};
} else {
error!("package not found, input: {}", package);
return Err(Error::new(
ErrorKind::PackageNotValid,
"Can't extract your package. Example of a package: @namespace/package:1.0.0",
Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use shadow_rs::shadow;
shadow!(build);

pub mod commands;
pub mod utils;

Expand All @@ -14,9 +17,7 @@ use utils::state::Error;
use tracing::{error, instrument, level_filters::LevelFilter};
use tracing_subscriber::{self, layer::SubscriberExt, util::SubscriberInitExt, Layer};

use shadow_rs::shadow;

shadow!(build);

#[instrument]
fn main() {
Expand Down
21 changes: 20 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::{fs, path::Path};

use std::io;

use typst_kit::download::Progress;

pub mod macros;
pub mod paths;
pub mod specs;
Expand Down Expand Up @@ -36,7 +38,24 @@ pub fn symlink_all(

/// Implementing a symlink function for all platform (windows version)
#[cfg(windows)]
pub fn symlink_all(origin: impl AsRef<Path>, new_path: impl AsRef<Path>) -> Result<(), std::io::Error> {
pub fn symlink_all(
origin: impl AsRef<Path>,
new_path: impl AsRef<Path>,
) -> Result<(), std::io::Error> {
use std::os::windows::fs::symlink_dir;
symlink_dir(origin, new_path)
}

pub struct ProgressPrint {}

impl Progress for ProgressPrint {
fn print_start(&mut self) {
println!("Starting download");
}

fn print_progress(&mut self, state: &typst_kit::download::DownloadState) {}

fn print_finish(&mut self, state: &typst_kit::download::DownloadState) {
todo!()
}
}

0 comments on commit 82f6332

Please sign in to comment.