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 c3c853d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 80 deletions.
63 changes: 9 additions & 54 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -374,56 +374,7 @@ jobs:
cache-to: type=gha,mode=max
file: Dockerfile-client

build-macos-x86_64:
runs-on: macos-13
permissions:
contents: read
packages: write
id-token: write



steps:
- uses: actions/checkout@v3
with:
submodules: recursive


- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 'stable'

- name: package-gt
run: |-
sudo mkdir -pv /opt/homebrew/opt
brew install make llvm@16 binutils ninja
pip3 install --upgrade setuptools
curl -LOJ https://chrome-infra-packages.appspot.com/dl/gn/gn/mac-amd64/+/latest
unzip gn-mac-amd64.zip
chmod +x gn && mv gn /usr/local/opt/llvm@16/bin/
sudo ln -s /usr/local/opt/llvm@16 /opt/homebrew/opt/llvm
ln -s /usr/local/opt/llvm@16 /usr/local/opt/llvm
echo 'export PATH="/usr/local/opt/llvm@16/bin:$PATH"' >> ~/.bash_profile
export PATH="/usr/local/opt/make/libexec/gnubin:$PATH"
echo 'export PATH="/usr/local/opt/binutils/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
mv /usr/local/opt/llvm/bin/llvm-libtool-darwin /usr/local/opt/llvm/bin/libtool
rustup target add x86_64-apple-darwin aarch64-apple-darwin
cd ./libcs && TARGET=x86_64-apple-darwin GOOS=darwin GOARCH=amd64 arch -arch x86_64 make release_lib
cargo build --target x86_64-apple-darwin -r
cd ..
mkdir -p release
cp target/x86_64-apple-darwin/release/gt release/gt-macos-x86_64
- name: Archive GT artifacts
uses: actions/upload-artifact@v3
with:
name: gt-macos-x86_64
path: |
release/*
build-macos-arm64:
build-macos:
runs-on: macos-14
permissions:
contents: read
Expand Down Expand Up @@ -451,7 +402,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,15 +413,19 @@ 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
cp target/x86_64-apple-darwin/release/gt release/gt-macos-x86_64
- name: Archive GT artifacts
uses: actions/upload-artifact@v3
with:
name: gt-macos-aarch64
name: gt-macos
path: |
release/*
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
26 changes: 13 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,15 @@ impl Manager {
loop {
info!("restarting {sub_cmd} ({config:?}) in {wait_time:?}");
tokio::time::sleep(wait_time).await;
let mut cmd = Command::new(&program);
let exe = match env::current_exe() {
Ok(exe) => exe,
Err(e) => {
wait_time = Duration::from_secs(3 * 60);
error!("failed to restart {sub_cmd} ({config:?}): {:?}", e);
continue;
}
};
let mut cmd = Command::new(exe);
cmd.arg(sub_cmd);
cmd_config!(cmd, config);
match cmd.spawn() {
Expand Down Expand Up @@ -426,7 +428,6 @@ impl Manager {
}
if !server_config.is_empty() {
Self::run(
self.program.clone(),
self.cmds.clone(),
server_config,
"sub-server",
Expand All @@ -437,7 +438,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 c3c853d

Please sign in to comment.