Skip to content

Commit

Permalink
feat(xtask): 添加 deploy 功能,将可执行文件拷贝到指定位置
Browse files Browse the repository at this point in the history
Signed-off-by: YdrMaster <[email protected]>
  • Loading branch information
YdrMaster committed Apr 25, 2024
1 parent 7057bfe commit e1e1607
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[alias]
xtask = "run --package xtask --release --"
debug = "run --package xtask --"
deploy = "xtask deploy"
generate = "xtask generate"
chat = "xtask chat"
cast = "xtask cast"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
!/.github/*

/target
/deploy
40 changes: 40 additions & 0 deletions xtask/src/deploy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use std::{
env, fs,
path::{Path, PathBuf},
process::Command,
str::from_utf8,
};

#[derive(Args, Default)]
pub struct DeployArgs {
#[clap(long, short)]
target: Option<PathBuf>,
}

impl DeployArgs {
pub fn deploy(self) {
let output = Command::new(env!("CARGO"))
.arg("locate-project")
.arg("--workspace")
.arg("--message-format=plain")
.output()
.unwrap()
.stdout;
let workspace = Path::new(from_utf8(&output).unwrap().trim())
.parent()
.unwrap();

let exe = env::current_exe().unwrap();
let target = self
.target
.unwrap_or_else(|| workspace.join("deploy"))
.join(exe.file_name().unwrap());
println!("Deploy");
println!(" from: {}", exe.display());
println!(" to: {}", target.display());

fs::create_dir_all(target.parent().unwrap()).unwrap();
fs::remove_file(&target).unwrap();
fs::copy(exe, target).unwrap();
}
}
5 changes: 5 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod cast;
mod chat;
mod deploy;
mod service;

use causal_lm::SampleArgs;
use clap::Parser;
use deploy::DeployArgs;
use service::ServiceArgs;
use std::{ffi::c_int, future::Future};

Expand All @@ -13,6 +15,7 @@ extern crate clap;
fn main() {
use Commands::*;
match Cli::parse().command {
Deploy(deploy) => deploy.deploy(),
Cast(cast) => cast.invode(),
// Generate(args) => block_on(args.inference.generate(&args.prompt)),
Chat(chat) => block_on(chat.chat()),
Expand Down Expand Up @@ -45,6 +48,8 @@ struct Cli {

#[derive(Subcommand)]
enum Commands {
/// Deploy binary
Deploy(DeployArgs),
/// Cast model
Cast(cast::CastArgs),
// /// Generate following text
Expand Down
2 changes: 1 addition & 1 deletion xtask/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use service::Service;
use web_api::start_infer_service;

#[derive(Args, Default)]
pub(crate) struct ServiceArgs {
pub struct ServiceArgs {
#[clap(flatten)]
pub inference: InferenceArgs,
/// Port to bind the service to
Expand Down

0 comments on commit e1e1607

Please sign in to comment.