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 8f30789 commit ca314a3
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 83 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/*
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: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resolver = "2"

[workspace.package]
authors = ["Zhiyi Weng"]
version = "2.2.0"
version = "2.2.1"
edition = "2021"
description = "Fast WebSocket(s)/HTTP(s)/TCP relay proxy with WebRTC P2P supports."

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
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: 1 addition & 1 deletion libcs/web/front/src/languages/lang/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export namespace zh {
RemoteTCPRandom: "GT-Server TCP随机端口",
LocalURL: "本地 URL",
LocalTimeout: "本地连接超时时间",
UseLocalAsHTTPHost: "HTTP Header Host替换",
UseLocalAsHTTPHost: "替换 HTTP Header Host",
TcpForwardAddr: "TCP 转发地址",
TcpForwardHostPrefix: "TCP 转发主机前缀",
TcpForwardConnections: "TCP 转发连接数",
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 ca314a3

Please sign in to comment.