Skip to content

Commit

Permalink
Merge pull request #230 from ferrouswheel/xgo
Browse files Browse the repository at this point in the history
Support cross compilation with xgo
  • Loading branch information
anandrgitnirman authored Mar 21, 2019
2 parents 2caefe0 + f7abef5 commit 4d0c885
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ $ go get -u google.golang.org/grpc
$ sudo apt-get install golint
```

* If you want to cross-compile you will also need Docker

### Installing

* Clone the git repository to the following path $GOPATH/src/github.com/singnet/
Expand All @@ -57,7 +59,7 @@ $ cd snet-daemon
$ ./scripts/install
```

* Build snet-daemon (on Linux amd64 platform)
* Build snet-daemon (on Linux amd64 platform), see below section if you want to cross compile instead.
```bash
$ ./scripts/build linux amd64
```
Expand All @@ -68,14 +70,18 @@ $ ./build/snetd-linux-amd64 init
```
**** Please update the registry address in daemon config based on the test network used

#### Cross-compiling

If you want to build snetd for platforms other than the one you are on, run `./scripts/build-xgo` instead of `./scripts/build`.

You can edit the script to choose a specific platform, but by default it will build for Linux, OSX, and Windows (amd64 for all, except Linux which will also build for arm6)

#### Run Deamon
```bash
$ ../build/snetd-linux-amd64
```




### Main commands


Expand Down
2 changes: 1 addition & 1 deletion ratelimit/rateLimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func NewRateLimiter() rate.Limiter {
//By Default set the maximum value possible for the Burst Size ( assuming rate was defined ,but burst was not defined)
burstSize := config.GetInt(config.BurstSize)
if burstSize == 0 {
burstSize = math.MaxInt64
burstSize = math.MaxInt32
}
limiter := rate.NewLimiter(getLimit(), burstSize)
return *limiter
Expand Down
29 changes: 29 additions & 0 deletions scripts/build-xgo
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set -ex

PARENT_PATH=$(dirname $(cd $(dirname $0); pwd -P))
pushd $PARENT_PATH

# Make sure we have xgo
go get -u github.com/karalabe/xgo

# Apply patch for OSX, Go 1.10 and old notify version
# https://stackoverflow.com/questions/54064293/cannot-use-nil-as-type-ctype-cfallocatorref-in-argument-to-func-literal
# Can be removed if we upgrade notify (which probably requires upgrading go-ethereum etc.)
pushd vendor/github.com/rjeczalik/notify
patch -N < $PARENT_PATH/scripts/watcher_fsevents_cgo.go.patch || true
popd

mkdir -p build

# Stuck on Go 1.10.x until https://github.com/singnet/snet-daemon/issues/201 is resolved.
GO_VERSION=1.10.x

# All targets compiled when Joel tried (2019-March), but we probably don't want to build them all!
#TARGETS=*/*

# See here for details
# https://github.com/karalabe/xgo#limit-build-targets
TARGETS=linux/amd64,linux/arm-6,darwin-10.6/amd64,windows/amd64
xgo -dest build -go $GO_VERSION -targets=$TARGETS ./snetd
22 changes: 22 additions & 0 deletions scripts/watcher_fsevents_cgo.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- /home/joel/Downloads/watcher_fsevents_cgo.go 2019-03-20 13:14:12.643748593 +1300
+++ watcher_fsevents_cgo.go 2019-03-20 12:49:33.489170174 +1300
@@ -48,7 +48,7 @@
// started and is ready via the wg. It also serves purpose of a dummy source,
// thanks to it the runloop does not return as it also has at least one source
// registered.
-var source = C.CFRunLoopSourceCreate(nil, 0, &C.CFRunLoopSourceContext{
+var source = C.CFRunLoopSourceCreate(C.kCFAllocatorDefault, 0, &C.CFRunLoopSourceContext{
perform: (C.CFRunLoopPerformCallBack)(C.gosource),
})

@@ -162,8 +162,8 @@
return nil
}
wg.Wait()
- p := C.CFStringCreateWithCStringNoCopy(nil, C.CString(s.path), C.kCFStringEncodingUTF8, nil)
- path := C.CFArrayCreate(nil, (*unsafe.Pointer)(unsafe.Pointer(&p)), 1, nil)
+ p := C.CFStringCreateWithCStringNoCopy(C.kCFAllocatorDefault, C.CString(s.path), C.kCFStringEncodingUTF8, C.kCFAllocatorDefault)
+ path := C.CFArrayCreate(C.kCFAllocatorDefault, (*unsafe.Pointer)(unsafe.Pointer(&p)), 1, nil)
ctx := C.FSEventStreamContext{}
ref := C.EventStreamCreate(&ctx, C.uintptr_t(s.info), path, C.FSEventStreamEventId(atomic.LoadUint64(&since)), latency, flags)
if ref == nilstream {
3 changes: 2 additions & 1 deletion snetd/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/singnet/snet-daemon/metrics"
"google.golang.org/grpc/health/grpc_health_v1"
"math"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -172,7 +173,7 @@ func (d daemon) start() {

if config.GetString(config.DaemonTypeKey) == "grpc" {
// set the maximum that the server can receive to 4GB. It is set to for 4GB because of issue here https://github.com/grpc/grpc-go/issues/1590
maxsizeOpt := grpc.MaxRecvMsgSize(4000000000)
maxsizeOpt := grpc.MaxRecvMsgSize(math.MaxInt32)
d.grpcServer = grpc.NewServer(
grpc.UnknownServiceHandler(handler.NewGrpcHandler(d.components.ServiceMetaData())),
grpc.StreamInterceptor(d.components.GrpcInterceptor()),
Expand Down

0 comments on commit 4d0c885

Please sign in to comment.