2 Commits

Author SHA1 Message Date
Alexandr Bogomyakov
adb0d4bdb9 Add options to run xray-core and specify binary path 2025-11-29 01:16:28 +02:00
Alexandr Bogomyakov
cb52c3d912 Merge pull request #1 from house-of-vanity/parse_and_run
Added --run mode to run xray with a parsed config.
2025-11-29 01:15:44 +02:00
6 changed files with 26 additions and 184 deletions

View File

@@ -1,44 +0,0 @@
name: CI
on:
push:
branches: [main, master, develop]
pull_request:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo test --locked
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --all-targets --all-features -- -D warnings
fmt:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- run: cargo fmt --all -- --check

View File

@@ -1,134 +0,0 @@
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
permissions:
contents: write
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
use_cross: false
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
use_cross: false
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
use_cross: true
- os: macos-latest
target: x86_64-apple-darwin
use_cross: false
- os: macos-latest
target: aarch64-apple-darwin
use_cross: false
- os: windows-latest
target: x86_64-pc-windows-msvc
use_cross: false
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install musl tools
if: matrix.target == 'x86_64-unknown-linux-musl'
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Install cross
if: matrix.use_cross
run: cargo install cross --git https://github.com/cross-rs/cross
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build
run: |
if [ "${{ matrix.use_cross }}" == "true" ]; then
cross build --release --locked --target ${{ matrix.target }}
else
cargo build --release --locked --target ${{ matrix.target }}
fi
shell: bash
- name: Get binary name
id: binary
run: |
name=$(grep '^name = ' Cargo.toml | head -1 | cut -d'"' -f2)
if [ "${{ runner.os }}" == "Windows" ]; then
echo "name=${name}.exe" >> $GITHUB_OUTPUT
else
echo "name=${name}" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Strip binary
if: runner.os != 'Windows' && !matrix.use_cross
run: strip target/${{ matrix.target }}/release/${{ steps.binary.outputs.name }}
- name: Package
id: package
run: |
name=$(grep '^name = ' Cargo.toml | head -1 | cut -d'"' -f2)
target="${{ matrix.target }}"
binary="${{ steps.binary.outputs.name }}"
cd target/${target}/release
if [ "${{ runner.os }}" == "Windows" ]; then
archive="${name}-${target}.zip"
7z a ../../../${archive} ${binary}
echo "archive=${archive}" >> $GITHUB_OUTPUT
else
archive="${name}-${target}.tar.gz"
tar czf ../../../${archive} ${binary}
echo "archive=${archive}" >> $GITHUB_OUTPUT
fi
shell: bash
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: ${{ steps.package.outputs.archive }}
release:
name: Release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
path: artifacts
- name: Generate changelog
run: |
if [ -n "$(git tag --sort=-creatordate | head -n 2 | tail -n 1)" ]; then
prev_tag=$(git tag --sort=-creatordate | head -n 2 | tail -n 1)
git log ${prev_tag}..HEAD --pretty=format:"- %s" > CHANGELOG.md
else
echo "Initial release" > CHANGELOG.md
fi
- uses: softprops/action-gh-release@v2
with:
body_path: CHANGELOG.md
files: artifacts/**/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

2
Cargo.lock generated
View File

@@ -609,7 +609,7 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "v2parser"
version = "0.4.0"
version = "0.3.1"
dependencies = [
"base64",
"clap",

View File

@@ -1,7 +1,7 @@
[package]
name = "v2parser"
version = "0.4.0"
edition = "2024"
version = "0.3.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -15,9 +15,7 @@ serde = { version = "1.0.189", features = ["derive"] }
serde_json = "1.0.107"
urlencoding = "2"
tokio = { version = "1.0", features = ["full"] }
tempfile = "3"
[target.'cfg(unix)'.dependencies]
signal-hook = "0.3"
signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] }
tempfile = "3"
futures = "0.3"

View File

@@ -16,6 +16,8 @@ Options:
--socksport <PORT> Optional SOCKS5 proxy port for inbound
--httpport <PORT> Optional HTTP proxy port for inbound
--get-metadata Only print config meta data
--run Run xray-core with the generated config
--xray-binary <PATH> Path to xray-core binary (default: xray from PATH)
-h, --help Print help
-V, --version Print version
```

View File

@@ -64,6 +64,26 @@ impl XrayRunner {
Ok(())
}
pub fn is_running(&mut self) -> bool {
if let Some(process) = &mut self.process {
match process.try_wait() {
Ok(Some(_)) => {
// Process has exited
self.process = None;
false
}
Ok(None) => true, // Process is still running
Err(_) => {
// Error checking status, assume not running
self.process = None;
false
}
}
} else {
false
}
}
}
impl Drop for XrayRunner {