|
@@ -12,16 +12,32 @@ import (
|
|
"github.com/sagernet/sing/common/rw"
|
|
"github.com/sagernet/sing/common/rw"
|
|
)
|
|
)
|
|
|
|
|
|
-var debugEnabled bool
|
|
|
|
|
|
+var (
|
|
|
|
+ debugEnabled bool
|
|
|
|
+ target string
|
|
|
|
+)
|
|
|
|
|
|
func init() {
|
|
func init() {
|
|
flag.BoolVar(&debugEnabled, "debug", false, "enable debug")
|
|
flag.BoolVar(&debugEnabled, "debug", false, "enable debug")
|
|
|
|
+ flag.StringVar(&target, "target", "android", "target platform")
|
|
}
|
|
}
|
|
|
|
|
|
func main() {
|
|
func main() {
|
|
- build_shared.FindSDK()
|
|
|
|
|
|
+ flag.Parse()
|
|
|
|
+
|
|
build_shared.FindMobile()
|
|
build_shared.FindMobile()
|
|
|
|
|
|
|
|
+ switch target {
|
|
|
|
+ case "android":
|
|
|
|
+ buildAndroid()
|
|
|
|
+ case "ios":
|
|
|
|
+ buildiOS()
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func buildAndroid() {
|
|
|
|
+ build_shared.FindSDK()
|
|
|
|
+
|
|
args := []string{
|
|
args := []string{
|
|
"bind",
|
|
"bind",
|
|
"-v",
|
|
"-v",
|
|
@@ -32,10 +48,10 @@ func main() {
|
|
if !debugEnabled {
|
|
if !debugEnabled {
|
|
args = append(args,
|
|
args = append(args,
|
|
"-trimpath", "-ldflags=-s -w -buildid=",
|
|
"-trimpath", "-ldflags=-s -w -buildid=",
|
|
- "-tags", "with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api,debug",
|
|
|
|
|
|
+ "-tags", "with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api",
|
|
)
|
|
)
|
|
} else {
|
|
} else {
|
|
- args = append(args, "-tags", "with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api")
|
|
|
|
|
|
+ args = append(args, "-tags", "with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api,debug")
|
|
}
|
|
}
|
|
|
|
|
|
args = append(args, "./experimental/libbox")
|
|
args = append(args, "./experimental/libbox")
|
|
@@ -59,3 +75,38 @@ func main() {
|
|
log.Info("copied to ", copyPath)
|
|
log.Info("copied to ", copyPath)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func buildiOS() {
|
|
|
|
+ args := []string{
|
|
|
|
+ "bind",
|
|
|
|
+ "-v",
|
|
|
|
+ "-target", "ios,iossimulator,macos",
|
|
|
|
+ "-libname=box",
|
|
|
|
+ }
|
|
|
|
+ if !debugEnabled {
|
|
|
|
+ args = append(args,
|
|
|
|
+ "-trimpath", "-ldflags=-s -w -buildid=",
|
|
|
|
+ )
|
|
|
|
+ } else {
|
|
|
|
+ args = append(args, "-tags", "debug")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ args = append(args, "./experimental/libbox")
|
|
|
|
+
|
|
|
|
+ command := exec.Command(build_shared.GoBinPath+"/gomobile", args...)
|
|
|
|
+ command.Stdout = os.Stdout
|
|
|
|
+ command.Stderr = os.Stderr
|
|
|
|
+ err := command.Run()
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ copyPath := filepath.Join("..", "sfi")
|
|
|
|
+ if rw.FileExists(copyPath) {
|
|
|
|
+ targetDir := filepath.Join(copyPath, "Libbox.xcframework")
|
|
|
|
+ targetDir, _ = filepath.Abs(targetDir)
|
|
|
|
+ os.RemoveAll(targetDir)
|
|
|
|
+ os.Rename("Libbox.xcframework", targetDir)
|
|
|
|
+ log.Info("copied to ", targetDir)
|
|
|
|
+ }
|
|
|
|
+}
|