mirror of
https://github.com/yggdrasil-network/yggstack.git
synced 2025-04-28 14:15:07 +03:00
added an option to build a dynamic library
fixes https://github.com/yggdrasil-network/yggstack/issues/17
This commit is contained in:
parent
83bc9a2eec
commit
6c55383019
4 changed files with 57 additions and 12 deletions
23
build
23
build
|
@ -8,8 +8,9 @@ PKGVER=${PKGVER:-$(sh contrib/semver/version.sh --bare)}
|
||||||
|
|
||||||
LDFLAGS="-X $PKGSRC.buildName=$PKGNAME -X $PKGSRC.buildVersion=$PKGVER"
|
LDFLAGS="-X $PKGSRC.buildName=$PKGNAME -X $PKGSRC.buildVersion=$PKGVER"
|
||||||
ARGS="-v"
|
ARGS="-v"
|
||||||
|
DLL=false
|
||||||
|
|
||||||
while getopts "utc:l:dro:ps" option
|
while getopts "utc:l:dro:psk" option
|
||||||
do
|
do
|
||||||
case "$option"
|
case "$option"
|
||||||
in
|
in
|
||||||
|
@ -22,6 +23,7 @@ do
|
||||||
o) ARGS="$ARGS -o $OPTARG";;
|
o) ARGS="$ARGS -o $OPTARG";;
|
||||||
p) ARGS="$ARGS -buildmode=pie";;
|
p) ARGS="$ARGS -buildmode=pie";;
|
||||||
s) ARGS="$ARGS -tags netgo,osusersgo,static" LDFLAGS="$LDFLAGS -extldflags '-static'" CGO_ENABLED=0;;
|
s) ARGS="$ARGS -tags netgo,osusersgo,static" LDFLAGS="$LDFLAGS -extldflags '-static'" CGO_ENABLED=0;;
|
||||||
|
k) DLL=true;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -29,11 +31,16 @@ if [ -z $TABLES ] && [ -z $DEBUG ]; then
|
||||||
LDFLAGS="$LDFLAGS -s -w"
|
LDFLAGS="$LDFLAGS -s -w"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for CMD in yggstack ; do
|
if [ "$DLL" = true ]; then
|
||||||
echo "Building: $CMD"
|
echo "Building: shared library"
|
||||||
go build $ARGS -ldflags="$LDFLAGS" -gcflags="$GCFLAGS" ./cmd/$CMD
|
CGO_ENABLED=1 go build $ARGS -buildmode=c-shared -ldflags="$LDFLAGS" -gcflags="$GCFLAGS" -o yggstack ./pkg/yggstack
|
||||||
|
else
|
||||||
|
for CMD in yggstack ; do
|
||||||
|
echo "Building: $CMD"
|
||||||
|
go build $ARGS -ldflags="$LDFLAGS" -gcflags="$GCFLAGS" ./cmd/$CMD
|
||||||
|
|
||||||
if [ $UPX ]; then
|
if [ $UPX ]; then
|
||||||
upx --brute $CMD
|
upx --brute $CMD
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
|
11
cmd/yggstack/program.go
Normal file
11
cmd/yggstack/program.go
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/yggdrasil-network/yggstack/src/driver"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
driver.Run(os.Args[1:])
|
||||||
|
}
|
28
pkg/yggstack/lib.go
Normal file
28
pkg/yggstack/lib.go
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
//go:build cgo
|
||||||
|
// +build cgo
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <stdlib.h>
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/yggdrasil-network/yggstack/src/driver"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {}
|
||||||
|
|
||||||
|
//export YggstackMain
|
||||||
|
func YggstackMain(argc C.int, argv **C.char) {
|
||||||
|
length := int(argc)
|
||||||
|
args := make([]string, length)
|
||||||
|
argvPtr := unsafe.Pointer(argv)
|
||||||
|
for i := 0; i < length; i++ {
|
||||||
|
arg := *(**C.char)(unsafe.Add(argvPtr, uintptr(i)*unsafe.Sizeof((*C.char)(nil))))
|
||||||
|
args[i] = C.GoString(arg)
|
||||||
|
}
|
||||||
|
driver.Run(args)
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package driver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -47,8 +47,7 @@ type UDPSession struct {
|
||||||
remoteAddr net.Addr
|
remoteAddr net.Addr
|
||||||
}
|
}
|
||||||
|
|
||||||
// The main function is responsible for configuring and starting Yggdrasil.
|
func Run(args []string) {
|
||||||
func main() {
|
|
||||||
var localtcp types.TCPLocalMappings
|
var localtcp types.TCPLocalMappings
|
||||||
var localudp types.UDPLocalMappings
|
var localudp types.UDPLocalMappings
|
||||||
var remotetcp types.TCPRemoteMappings
|
var remotetcp types.TCPRemoteMappings
|
||||||
|
@ -72,7 +71,7 @@ func main() {
|
||||||
flag.Var(&localudp, "local-udp", "UDP ports to forward to the remote Yggdrasil node, e.g. 22:[a:b:c:d]:2022, 127.0.0.1:[a:b:c:d]:22")
|
flag.Var(&localudp, "local-udp", "UDP ports to forward to the remote Yggdrasil node, e.g. 22:[a:b:c:d]:2022, 127.0.0.1:[a:b:c:d]:22")
|
||||||
flag.Var(&remotetcp, "remote-tcp", "TCP ports to expose to the network, e.g. 22, 2022:22, 22:192.168.1.1:2022")
|
flag.Var(&remotetcp, "remote-tcp", "TCP ports to expose to the network, e.g. 22, 2022:22, 22:192.168.1.1:2022")
|
||||||
flag.Var(&remoteudp, "remote-udp", "UDP ports to expose to the network, e.g. 22, 2022:22, 22:192.168.1.1:2022")
|
flag.Var(&remoteudp, "remote-udp", "UDP ports to expose to the network, e.g. 22, 2022:22, 22:192.168.1.1:2022")
|
||||||
flag.Parse()
|
flag.CommandLine.Parse(args)
|
||||||
|
|
||||||
// Catch interrupts from the operating system to exit gracefully.
|
// Catch interrupts from the operating system to exit gracefully.
|
||||||
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
Loading…
Add table
Add a link
Reference in a new issue