Skip to content

Commit

Permalink
perf(gt): improve compatibility
Browse files Browse the repository at this point in the history
ci(macos): improve details
  • Loading branch information
vyloy committed Mar 21, 2024
1 parent e605986 commit 884888b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 29 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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
Expand Down
8 changes: 1 addition & 7 deletions bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 5 additions & 13 deletions bin/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,14 @@ enum ProcessConfigEnum {
}

pub struct Manager {
program: String,
args: ManagerArgs,
cmds: Arc<Mutex<HashMap<ProcessConfigEnum, Cmd>>>,
configs: Arc<Mutex<Option<Vec<ProcessConfigEnum>>>>,
}

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)),
Expand Down Expand Up @@ -184,12 +182,11 @@ impl Manager {
}

fn sync_run(
program: String,
cmd_map: Arc<Mutex<HashMap<ProcessConfigEnum, Cmd>>>,
configs: Vec<ProcessConfigEnum>,
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(
Expand Down Expand Up @@ -265,7 +262,6 @@ impl Manager {
}

async fn run(
program: String,
cmd_map: Arc<Mutex<HashMap<ProcessConfigEnum, Cmd>>>,
configs: Vec<ProcessConfigEnum>,
sub_cmd: &'static str,
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -426,7 +420,6 @@ impl Manager {
}
if !server_config.is_empty() {
Self::run(
self.program.clone(),
self.cmds.clone(),
server_config,
"sub-server",
Expand All @@ -437,7 +430,6 @@ impl Manager {

if !client_config.is_empty() {
Self::run(
self.program.clone(),
self.cmds.clone(),
client_config,
"sub-client",
Expand Down
6 changes: 5 additions & 1 deletion libcs/client/peerproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions libcs/web/server/util/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions libcs/web/server/util/system_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 884888b

Please sign in to comment.