From 13b82e81310ff33999a4d7d3a7deb207d71d3ad2 Mon Sep 17 00:00:00 2001 From: mango <2321544262@qq.com> Date: Sat, 22 Jul 2023 12:09:34 +0800 Subject: [PATCH] feat: export client to dynamic lib --- Makefile | 4 +++- Makefile.cross-compiles | 2 +- cmd/frpc/main.go | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d94e7c36..6fd0f3e1 100644 --- a/Makefile +++ b/Makefile @@ -27,9 +27,11 @@ vet: frps: env CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -o bin/frps ./cmd/frps +# go build -trimpath -ldflags "-s -w" -o bin/frps ./cmd/frps frpc: - env CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -o bin/frpc ./cmd/frpc + env CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -buildmode=c-shared -o bin/frpc ./cmd/frpc +#env CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -buildmode=c-shared -o bin/frpc ./cmd/frpc test: gotest diff --git a/Makefile.cross-compiles b/Makefile.cross-compiles index 515a3c26..6ac23c4d 100644 --- a/Makefile.cross-compiles +++ b/Makefile.cross-compiles @@ -15,7 +15,7 @@ app: gomips=$(shell echo "$(n)" | cut -d : -f 3);\ target_suffix=$${os}_$${arch};\ echo "Build $${os}-$${arch}...";\ - env CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} GOMIPS=$${gomips} go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frpc_$${target_suffix} ./cmd/frpc;\ + env CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} GOMIPS=$${gomips} go build -trimpath -ldflags "$(LDFLAGS)" -buildmode=c-shared -o ./release/frpc_$${target_suffix} ./cmd/frpc;\ env CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} GOMIPS=$${gomips} go build -trimpath -ldflags "$(LDFLAGS)" -o ./release/frps_$${target_suffix} ./cmd/frps;\ echo "Build $${os}-$${arch} done";\ ) diff --git a/cmd/frpc/main.go b/cmd/frpc/main.go index f9a6c252..a7198f03 100644 --- a/cmd/frpc/main.go +++ b/cmd/frpc/main.go @@ -14,11 +14,25 @@ package main +import "C" import ( + "fmt" _ "github.com/fatedier/frp/assets/frpc" "github.com/fatedier/frp/cmd/frpc/sub" + "os" + "time" ) func main() { - sub.Execute() + //sub.Execute() +} + +func frpstart(charargs *C.char) { + var stringargs string + stringargs = C.GoString(charargs) + err := sub.runMultipleClients(stringargs) + if err != nil { + fmt.Println(err) + os.Exit(1) + } }