Skip to content

Commit

Permalink
redo the build process entirely, so that it does not depend on some o…
Browse files Browse the repository at this point in the history
…ther fork
  • Loading branch information
mmmray committed Sep 21, 2024
1 parent 7fec852 commit d2834be
Show file tree
Hide file tree
Showing 9 changed files with 689 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ jobs:
go-version: '1.23'
check-latest: true
- run: make build
- run: mkdir public && cp index.html main.wasm wasm_exec.js public
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: ./
path: public/

# Deployment job
deploy:
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.wasm
*.dat
wasm_exec.js
*.js
assets
32 changes: 27 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
geoip.dat:
wget https://github.com/v2fly/geoip/releases/latest/download/geoip.dat
build: main.wasm wasm_exec.js
.PHONY: build

geosite.dat:
wget https://github.com/v2fly/domain-list-community/releases/latest/download/dlc.dat -O geosite.dat
dev-lite:
wget -nc https://mmmray.github.io/xray-online/main.wasm
wget -nc https://mmmray.github.io/xray-online/wasm_exec.js
.PHONY: build-lite

build: geoip.dat geosite.dat
assets/xray-patched: xray-version.txt
rm -rf assets/xray-core assets/xray-patched
mkdir -p assets
cd assets && \
git clone https://github.com/xtls/xray-core && \
cd xray-core && \
git checkout -f $$(cat ../../xray-version.txt)
cat xray-wasm.patch | (cd assets/xray-core && git apply)
mv assets/xray-core assets/xray-patched

assets/geoip.dat:
mkdir -p assets
cd assets && wget https://github.com/v2fly/geoip/releases/latest/download/geoip.dat

assets/geosite.dat:
mkdir -p assets
cd assets && wget https://github.com/v2fly/domain-list-community/releases/latest/download/dlc.dat -O geosite.dat

wasm_exec.js:
cp "$$(go env GOROOT)/misc/wasm/wasm_exec.js" .

main.wasm: assets/geoip.dat assets/geosite.dat assets/xray-patched main.go go.mod xray-wasm.patch
GOARCH=wasm GOOS=js go build -o main.wasm main.go

serve:
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ jsonlint.com.

[Try it out here](https://mmmray.github.io/xray-online/)

This uses a fork of xray that has been refactored so it can (partially) compile
to wasm. Your config is not sent to any server.

Because some configuration validation happens after parsing, some mistakes are
not caught, only most typing mistakes. If you find an obvious gap that bothers
you, raise an issue.

## Contributing

xray-online uses a patched version of xray-core compiled to WASM. The build process is entirely driven through the `Makefile`. A POSIX shell is recommended, WSL is probably mandatory on Windows.

* `make build` to build the WASM module from scratch.
* `make dev-lite` to download the WASM module from GitHub instead.
* `make serve` to launch the development server.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/mmmray/xray-online

go 1.22.4

require github.com/xtls/xray-core v1.8.25-0.20240907003027-3d9137cb6fdd
require github.com/xtls/xray-core v0.0.0

require (
github.com/andybalholm/brotli v1.1.0 // indirect
Expand Down Expand Up @@ -46,4 +46,4 @@ require (
lukechampine.com/blake3 v1.3.0 // indirect
)

replace github.com/xtls/xray-core v1.8.25-0.20240907003027-3d9137cb6fdd => github.com/mmmray/xray-core v0.0.0-20240918112546-ebefcef53543
replace github.com/xtls/xray-core => ./assets/xray-patched/
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuV
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/miekg/dns v1.1.62 h1:cN8OuEF1/x5Rq6Np+h1epln8OiyPWV+lROx9LxcGgIQ=
github.com/miekg/dns v1.1.62/go.mod h1:mvDlcItzm+br7MToIKqkglaGhlFMHJ9DTNNWONWXbNQ=
github.com/mmmray/xray-core v0.0.0-20240918112546-ebefcef53543 h1:5z2hYixAtGyCyNXQEAMu0SuGjmaKfwSQmxASN/f74K0=
github.com/mmmray/xray-core v0.0.0-20240918112546-ebefcef53543/go.mod h1:l03adDk7IwHvIoRHNKQWI3SGIq/96RFP95/rDHk++30=
github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA=
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
json_reader "github.com/xtls/xray-core/infra/conf/json"
)

//go:embed geoip.dat
//go:embed assets/geoip.dat
var geoipRaw []byte

//go:embed geosite.dat
//go:embed assets/geosite.dat
var geositeRaw []byte

func main() {
Expand Down
1 change: 1 addition & 0 deletions xray-version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v24.9.19
Loading

0 comments on commit d2834be

Please sign in to comment.