Skip to content

Commit 32ae3b2

Browse files
author
yiguo
committed
update Xray-core to v26.5.9
1 parent b19e33d commit 32ae3b2

5 files changed

Lines changed: 35 additions & 60 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ Compile script. It is recommended to always use this script to compile libXray.
4040

4141
depends on git and go.
4242

43-
By default, the build script clones [Xray-core](https://github.com/XTLS/Xray-core) to `../Xray-core-libXray` and checks out `v26.5.9`.
44-
Pass the optional `local` argument to use an existing local checkout at `../Xray-core` instead of cloning.
43+
By default, the build script does not clone [Xray-core](https://github.com/XTLS/Xray-core). It uses Go modules and pins Xray-core to tag `v26.5.9` (recorded by Go as the matching pseudo-version).
44+
Pass the optional `local` argument to use an existing local checkout at `../Xray-core` through a Go module `replace`.
4545

4646
### Usage
4747

build/app/build.py

Lines changed: 28 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
)
1111

1212
LIBXRAY_MOD_NAME = "github.com/xtls/libxray"
13-
XRAY_CORE_REPO = "https://github.com/XTLS/Xray-core.git"
13+
XRAY_CORE_MOD_NAME = "github.com/xtls/xray-core"
1414
DEFAULT_XRAY_CORE_TAG = "v26.5.9"
15-
CLONED_XRAY_CORE_DIR_NAME = "Xray-core-libXray"
15+
# Xray-core CalVer tags cannot be used directly as Go module versions because
16+
# its module path does not include /v26. This pseudo-version points to the tag above.
17+
DEFAULT_XRAY_CORE_VERSION = "v1.260327.1-0.20260509173629-1bdb488c9ec0"
1618
LOCAL_XRAY_CORE_DIR_NAME = "Xray-core"
1719

1820

@@ -22,12 +24,7 @@ def __init__(self, build_dir: str, use_local_xray_core: bool = False):
2224
self.lib_dir = os.path.abspath(os.path.join(self.build_dir, ".."))
2325
self.bin_file = "xray"
2426
self.use_local_xray_core = use_local_xray_core
25-
xray_core_dir_name = (
26-
LOCAL_XRAY_CORE_DIR_NAME
27-
if self.use_local_xray_core
28-
else CLONED_XRAY_CORE_DIR_NAME
29-
)
30-
self.xray_core_replace_path = f"../{xray_core_dir_name}"
27+
self.xray_core_replace_path = f"../{LOCAL_XRAY_CORE_DIR_NAME}"
3128
self.xray_core_dir = os.path.abspath(
3229
os.path.join(self.lib_dir, self.xray_core_replace_path)
3330
)
@@ -46,41 +43,6 @@ def prepare_xray_core(self):
4643
if self.use_local_xray_core:
4744
if not os.path.isdir(self.xray_core_dir):
4845
raise Exception(f"local Xray-core dir not found: {self.xray_core_dir}")
49-
return
50-
51-
if not os.path.exists(self.xray_core_dir):
52-
ret = subprocess.run(
53-
[
54-
"git",
55-
"clone",
56-
"--branch",
57-
DEFAULT_XRAY_CORE_TAG,
58-
"--depth",
59-
"1",
60-
XRAY_CORE_REPO,
61-
self.xray_core_dir,
62-
]
63-
)
64-
if ret.returncode != 0:
65-
raise Exception("clone Xray-core failed")
66-
return
67-
68-
if not os.path.isdir(self.xray_core_dir):
69-
raise Exception(f"Xray-core path is not a dir: {self.xray_core_dir}")
70-
71-
git_dir = os.path.join(self.xray_core_dir, ".git")
72-
if not os.path.isdir(git_dir):
73-
raise Exception(f"Xray-core path is not a git repo: {self.xray_core_dir}")
74-
75-
ret = subprocess.run(["git", "-C", self.xray_core_dir, "fetch", "--tags"])
76-
if ret.returncode != 0:
77-
raise Exception("fetch Xray-core tags failed")
78-
79-
ret = subprocess.run(
80-
["git", "-C", self.xray_core_dir, "checkout", DEFAULT_XRAY_CORE_TAG]
81-
)
82-
if ret.returncode != 0:
83-
raise Exception(f"checkout Xray-core tag {DEFAULT_XRAY_CORE_TAG} failed")
8446

8547
def init_go_env(self):
8648
os.chdir(self.lib_dir)
@@ -89,16 +51,29 @@ def init_go_env(self):
8951
if ret.returncode != 0:
9052
raise Exception("go mod init failed")
9153

92-
ret = subprocess.run(
93-
[
94-
"go",
95-
"mod",
96-
"edit",
97-
f"-replace=github.com/xtls/xray-core={self.xray_core_replace_path}",
98-
]
99-
)
100-
if ret.returncode != 0:
101-
raise Exception("go mod edit replace failed")
54+
if self.use_local_xray_core:
55+
ret = subprocess.run(
56+
[
57+
"go",
58+
"mod",
59+
"edit",
60+
f"-replace={XRAY_CORE_MOD_NAME}={self.xray_core_replace_path}",
61+
]
62+
)
63+
if ret.returncode != 0:
64+
raise Exception("go mod edit replace failed")
65+
else:
66+
ret = subprocess.run(
67+
["go", "mod", "edit", f"-dropreplace={XRAY_CORE_MOD_NAME}"]
68+
)
69+
if ret.returncode != 0:
70+
raise Exception("go mod edit dropreplace failed")
71+
72+
ret = subprocess.run(
73+
["go", "get", f"{XRAY_CORE_MOD_NAME}@{DEFAULT_XRAY_CORE_VERSION}"]
74+
)
75+
if ret.returncode != 0:
76+
raise Exception("go get xray-core failed")
10277

10378
ret = subprocess.run(
10479
[

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ module github.com/xtls/libxray
22

33
go 1.26.3
44

5-
replace github.com/xtls/xray-core => ../Xray-core-libXray
6-
75
require (
86
github.com/stretchr/testify v1.11.1
97
github.com/vishvananda/netlink v1.3.1
10-
github.com/xtls/xray-core v0.0.0-00010101000000-000000000000
8+
github.com/xtls/xray-core v1.260327.1-0.20260509173629-1bdb488c9ec0
119
google.golang.org/protobuf v1.36.11
1210
gopkg.in/yaml.v3 v3.0.1
1311
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ github.com/vishvananda/netns v0.0.5 h1:DfiHV+j8bA32MFM7bfEunvT8IAqQ/NzSJHtcmW5zd
6464
github.com/vishvananda/netns v0.0.5/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
6565
github.com/xtls/reality v0.0.0-20260322125925-9234c772ba8f h1:iy2JRioxmUpoJ3SzbFPyTxHZMbR/rSHP7dOOgYaq1O8=
6666
github.com/xtls/reality v0.0.0-20260322125925-9234c772ba8f/go.mod h1:DsJblcWDGt76+FVqBVwbwRhxyyNJsGV48gJLch0OOWI=
67+
github.com/xtls/xray-core v1.260327.1-0.20260509173629-1bdb488c9ec0 h1:ft6HiTHelF1z9i3zZVPG9Q1LcLcvEB5jzBxky/+wljk=
68+
github.com/xtls/xray-core v1.260327.1-0.20260509173629-1bdb488c9ec0/go.mod h1:LWadz6mFBKGPHAe0KscKjugHjmQeyDt5Na6J86ol/hY=
6769
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
6870
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
6971
go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I=

readme/README.zh_CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
依赖 git 和 go。
1818

19-
默认情况下,编译脚本会将 [Xray-core](https://github.com/XTLS/Xray-core) clone 到 `../Xray-core-libXray`,并 checkout `v26.5.9`
20-
传入可选参数 `local` 时,会跳过 clone,改用已有的本地仓库 `../Xray-core`
19+
默认情况下,编译脚本不会 clone [Xray-core](https://github.com/XTLS/Xray-core),而是通过 Go modules 将 Xray-core 固定到 tag `v26.5.9`(Go 会记录为对应的 pseudo-version)
20+
传入可选参数 `local` 时,会通过 Go module `replace` 改用已有的本地仓库 `../Xray-core`
2121

2222
### 使用方式
2323

0 commit comments

Comments
 (0)