From 884888b9c363ee25ab1c70be0ffa91d9bca0c382 Mon Sep 17 00:00:00 2001 From: zhiyi Date: Thu, 21 Mar 2024 22:03:20 +0800 Subject: [PATCH] perf(gt): improve compatibility ci(macos): improve details --- .github/workflows/container.yml | 9 ++++++--- bin/src/main.rs | 8 +------- bin/src/manager.rs | 18 +++++------------- libcs/client/peerproc.go | 6 +++++- libcs/web/server/util/system.go | 2 -- libcs/web/server/util/system_win.go | 4 +--- 6 files changed, 18 insertions(+), 29 deletions(-) diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 63ba4c80..fa8f8698 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -451,7 +451,7 @@ jobs: - name: package-gt run: |- - brew install make llvm@16 binutils ninja + brew install llvm@16 ninja curl -LOJ https://chrome-infra-packages.appspot.com/dl/gn/gn/mac-amd64/+/latest unzip gn-mac-amd64.zip chmod +x gn && mv gn /opt/homebrew/opt/llvm@16/bin/ @@ -462,9 +462,12 @@ jobs: source ~/.bash_profile mv /opt/homebrew/opt/llvm/bin/llvm-libtool-darwin /opt/homebrew/opt/llvm/bin/libtool rustup target add x86_64-apple-darwin aarch64-apple-darwin - cd ./libcs && TARGET=aarch64-apple-darwin GOOS=darwin GOARCH=arm64 arch -arch arm64 make release_lib - cargo build --target aarch64-apple-darwin -r + cd ./libcs + TARGET=aarch64-apple-darwin GOOS=darwin GOARCH=arm64 arch -arch arm64 make release_lib + TARGET=x86_64-apple-darwin GOOS=darwin GOARCH=amd64 arch -arch x86_64 make release_lib cd .. + cargo build --target aarch64-apple-darwin -r + cargo build --target x86_64-apple-darwin -r mkdir -p release cp target/aarch64-apple-darwin/release/gt release/gt-macos-aarch64 diff --git a/bin/src/main.rs b/bin/src/main.rs index 1b8db683..72b850ad 100644 --- a/bin/src/main.rs +++ b/bin/src/main.rs @@ -102,13 +102,7 @@ fn main() { } } - let mut args = env::args(); - if args.len() == 0 { - error!("no program provided"); - return; - } - let program = args.next().unwrap(); - let m = manager::Manager::new(program, manager_args); + let m = manager::Manager::new(manager_args); info!("GT"); if let Err(e) = m.run_manager() { error!("GT Manager error: {:?}", e); diff --git a/bin/src/manager.rs b/bin/src/manager.rs index 87e4ad42..4007bae0 100644 --- a/bin/src/manager.rs +++ b/bin/src/manager.rs @@ -73,16 +73,14 @@ enum ProcessConfigEnum { } pub struct Manager { - program: String, args: ManagerArgs, cmds: Arc>>, configs: Arc>>>, } impl Manager { - pub fn new(program: String, args: ManagerArgs) -> Self { + pub fn new(args: ManagerArgs) -> Self { Self { - program, args, cmds: Arc::new(Mutex::new(HashMap::new())), configs: Arc::new(Mutex::new(None)), @@ -184,12 +182,11 @@ impl Manager { } fn sync_run( - program: String, cmd_map: Arc>>, configs: Vec, sub_cmd: &'static str, ) -> BoxFuture<'static, Result<()>> { - async move { Self::run(program, cmd_map, configs, sub_cmd).await }.boxed() + async move { Self::run(cmd_map, configs, sub_cmd).await }.boxed() } async fn handle_stdout( @@ -265,7 +262,6 @@ impl Manager { } async fn run( - program: String, cmd_map: Arc>>, configs: Vec, sub_cmd: &'static str, @@ -295,7 +291,7 @@ impl Manager { .into_iter() .map(|config| { info!("run {sub_cmd} config: {:?}", config); - let mut cmd = Command::new(program.clone()); + let mut cmd = Command::new(env::current_exe()?); cmd.arg(sub_cmd); cmd_config!(cmd, config); cmd.spawn() @@ -306,7 +302,6 @@ impl Manager { let ready_done_counter = Arc::new(AtomicUsize::new(cmds.len())); for (mut c, config) in cmds { - let program = program.clone(); let cmd_map = cmd_map.clone(); let ready_done_counter = ready_done_counter.clone(); tokio::spawn(async move { @@ -327,11 +322,10 @@ impl Manager { process_shutdown(config.clone(), cmd, send_graceful_shutdown).await; } let reconnect = async { - let program = program.clone(); let cmds = cmd_map.clone(); let config = config.clone(); if let Err(e) = - Self::sync_run(program, cmds, vec![config.clone()], sub_cmd).await + Self::sync_run(cmds, vec![config.clone()], sub_cmd).await { error!("{sub_cmd} ({config:?}) reconnect sync_run failed: {:?}", e); } @@ -387,7 +381,7 @@ impl Manager { loop { info!("restarting {sub_cmd} ({config:?}) in {wait_time:?}"); tokio::time::sleep(wait_time).await; - let mut cmd = Command::new(&program); + let mut cmd = Command::new(env::current_exe()?); cmd.arg(sub_cmd); cmd_config!(cmd, config); match cmd.spawn() { @@ -426,7 +420,6 @@ impl Manager { } if !server_config.is_empty() { Self::run( - self.program.clone(), self.cmds.clone(), server_config, "sub-server", @@ -437,7 +430,6 @@ impl Manager { if !client_config.is_empty() { Self::run( - self.program.clone(), self.cmds.clone(), client_config, "sub-client", diff --git a/libcs/client/peerproc.go b/libcs/client/peerproc.go index abf87309..de378594 100644 --- a/libcs/client/peerproc.go +++ b/libcs/client/peerproc.go @@ -75,7 +75,11 @@ type opGetOfferSDP struct { } func (pt *peerProcessTask) init() (err error) { - cmd := exec.Command(os.Args[0], "sub-p2p") + execPath, err := os.Executable() + if err != nil { + return + } + cmd := exec.Command(execPath, "sub-p2p") pt.stdin, err = cmd.StdinPipe() if err != nil { return diff --git a/libcs/web/server/util/system.go b/libcs/web/server/util/system.go index 175afb90..64c9d3a3 100644 --- a/libcs/web/server/util/system.go +++ b/libcs/web/server/util/system.go @@ -36,8 +36,6 @@ func SendSignal(signal string) (err error) { cmd = exec.Command(execPath, "-s", "restart") case "stop": cmd = exec.Command(execPath, "-s", "stop") - case "kill": - cmd = exec.Command(execPath, "-s", "kill") default: err = errors.New("unknown signal") return diff --git a/libcs/web/server/util/system_win.go b/libcs/web/server/util/system_win.go index ace9bcbc..17f06586 100644 --- a/libcs/web/server/util/system_win.go +++ b/libcs/web/server/util/system_win.go @@ -36,14 +36,12 @@ func SendSignal(signal string) (err error) { cmd = exec.Command(execPath, "-s", "restart") case "stop": cmd = exec.Command(execPath, "-s", "stop") - case "kill": - cmd = exec.Command(execPath, "-s", "kill") default: err = errors.New("unknown signal") return } cmd.SysProcAttr = &syscall.SysProcAttr{ - // Setpgid: true + CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP, } err = cmd.Start() if err != nil {