Skip to content

Commit 630adfa

Browse files
authored
Merge pull request grafana#6068 from fg2it/cross
Cross build support
2 parents ec452dd + 699c515 commit 630adfa

File tree

5 files changed

+77
-41
lines changed

5 files changed

+77
-41
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ grunt karma:dev
1212

1313
### Run tests for backend assets before commit
1414
```
15-
test -z "$(gofmt -s -l . | grep -v vendor/src/ | tee /dev/stderr)"
15+
test -z "$(gofmt -s -l . | grep -v -E 'vendor/(github.com|golang.org|gopkg.in)' | tee /dev/stderr)"
1616
```
1717

1818
### Run tests for frontend assets before commit

Gruntfile.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ module.exports = function (grunt) {
99
genDir: 'public_gen',
1010
destDir: 'dist',
1111
tempDir: 'tmp',
12-
arch: os.arch(),
1312
platform: process.platform.replace('win32', 'windows'),
1413
};
1514

1615
if (process.platform.match(/^win/)) {
1716
config.arch = process.env.hasOwnProperty('ProgramFiles(x86)') ? 'x64' : 'x86';
1817
}
1918

19+
config.arch = grunt.option('arch') || os.arch();
20+
21+
config.phjs = grunt.option('phjsToRelease');
22+
2023
config.pkg.version = grunt.option('pkgVer') || config.pkg.version;
2124
console.log('Version', config.pkg.version);
2225

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ easily the grafana repository you want to build.
9696
```bash
9797
go get github.com/*your_account*/grafana
9898
mkdir $GOPATH/src/github.com/grafana
99-
ln -s github.com/*your_account*/grafana $GOPATH/src/github.com/grafana/grafana
99+
ln -s $GOPATH/src/github.com/*your_account*/grafana $GOPATH/src/github.com/grafana/grafana
100100
```
101101

102102
### Building the backend

build.go

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@ var (
2525
versionRe = regexp.MustCompile(`-[0-9]{1,3}-g[0-9a-f]{5,10}`)
2626
goarch string
2727
goos string
28+
gocc string
29+
gocxx string
30+
cgo string
31+
pkgArch string
2832
version string = "v1"
2933
// deb & rpm does not support semver so have to handle their version a little differently
3034
linuxPackageVersion string = "v1"
3135
linuxPackageIteration string = ""
3236
race bool
37+
phjsToRelease string
3338
workingDir string
3439
binaries []string = []string{"grafana-server", "grafana-cli"}
3540
)
@@ -47,6 +52,11 @@ func main() {
4752

4853
flag.StringVar(&goarch, "goarch", runtime.GOARCH, "GOARCH")
4954
flag.StringVar(&goos, "goos", runtime.GOOS, "GOOS")
55+
flag.StringVar(&gocc, "cc", "", "CC")
56+
flag.StringVar(&gocxx, "cxx", "", "CXX")
57+
flag.StringVar(&cgo, "cgo-enabled", "", "CGO_ENABLED")
58+
flag.StringVar(&pkgArch, "pkg-arch", "", "PKG ARCH")
59+
flag.StringVar(&phjsToRelease, "phjs", "", "PhantomJS binary")
5060
flag.BoolVar(&race, "race", race, "Use race detector")
5161
flag.Parse()
5262

@@ -73,15 +83,15 @@ func main() {
7383
grunt("test")
7484

7585
case "package":
76-
grunt("release", fmt.Sprintf("--pkgVer=%v-%v", linuxPackageVersion, linuxPackageIteration))
86+
grunt(gruntBuildArg("release")...)
7787
createLinuxPackages()
7888

7989
case "pkg-rpm":
80-
grunt("release")
90+
grunt(gruntBuildArg("release")...)
8191
createRpmPackages()
8292

8393
case "pkg-deb":
84-
grunt("release")
94+
grunt(gruntBuildArg("release")...)
8595
createDebPackages()
8696

8797
case "latest":
@@ -258,6 +268,10 @@ func createPackage(options linuxPackageOptions) {
258268
"-p", "./dist",
259269
}
260270

271+
if pkgArch != "" {
272+
args = append(args, "-a", pkgArch)
273+
}
274+
261275
if linuxPackageIteration != "" {
262276
args = append(args, "--iteration", linuxPackageIteration)
263277
}
@@ -307,9 +321,20 @@ func grunt(params ...string) {
307321
runPrint("./node_modules/.bin/grunt", params...)
308322
}
309323

324+
func gruntBuildArg(task string) []string {
325+
args := []string{task, fmt.Sprintf("--pkgVer=%v-%v", linuxPackageVersion, linuxPackageIteration)}
326+
if pkgArch != "" {
327+
args = append(args, fmt.Sprintf("--arch=%v", pkgArch))
328+
}
329+
if phjsToRelease != "" {
330+
args = append(args, fmt.Sprintf("--phjsToRelease=%v", phjsToRelease))
331+
}
332+
return args
333+
}
334+
310335
func setup() {
311336
runPrint("go", "get", "-v", "github.com/kardianos/govendor")
312-
runPrint("go", "get", "-v", "github.com/blang/semver")
337+
runPrint("go", "get", "-v", "github.com/blang/semver")
313338
runPrint("go", "get", "-v", "github.com/mattn/go-sqlite3")
314339
runPrint("go", "install", "-v", "github.com/mattn/go-sqlite3")
315340
}
@@ -382,6 +407,15 @@ func setBuildEnv() {
382407
if goarch == "386" {
383408
os.Setenv("GO386", "387")
384409
}
410+
if cgo != "" {
411+
os.Setenv("CGO_ENABLED", cgo)
412+
}
413+
if gocc != "" {
414+
os.Setenv("CC", gocc)
415+
}
416+
if gocxx != "" {
417+
os.Setenv("CXX", gocxx)
418+
}
385419
}
386420

387421
func getGitSha() string {

tasks/options/phantomjs.js

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
1-
module.exports = function(config,grunt) {
2-
'use strict';
3-
4-
grunt.registerTask('phantomjs', 'Copy phantomjs binary from node', function() {
5-
6-
var dest = './vendor/phantomjs/phantomjs';
7-
var confDir = './node_modules/phantomjs-prebuilt/lib/';
8-
9-
if (!grunt.file.exists(dest)){
10-
11-
var m=grunt.file.read(confDir+"location.js")
12-
var src=/= \"([^\"]*)\"/.exec(m)[1];
13-
14-
if (!grunt.file.isPathAbsolute(src)) {
15-
src = confDir+src;
16-
}
17-
18-
try {
19-
grunt.config('copy.phantom_bin', {
20-
src: src,
21-
dest: dest,
22-
options: { mode: true},
23-
});
24-
grunt.task.run('copy:phantom_bin');
25-
} catch (err) {
26-
grunt.verbose.writeln(err);
27-
grunt.fail.warn('No working Phantomjs binary available')
28-
}
29-
30-
} else {
31-
grunt.log.writeln('Phantomjs already imported from node');
32-
}
33-
});
34-
};
1+
module.exports = function(config,grunt) {
2+
'use strict';
3+
4+
grunt.registerTask('phantomjs', 'Copy phantomjs binary to vendor/', function() {
5+
6+
var dest = './vendor/phantomjs/phantomjs';
7+
var confDir = './node_modules/phantomjs-prebuilt/lib/';
8+
9+
src = config.phjs
10+
11+
if (!src){
12+
var m=grunt.file.read(confDir+"location.js")
13+
var src=/= \"([^\"]*)\"/.exec(m)[1];
14+
15+
if (!grunt.file.isPathAbsolute(src)) {
16+
src = confDir+src;
17+
}
18+
}
19+
20+
try {
21+
grunt.config('copy.phantom_bin', {
22+
src: src,
23+
dest: dest,
24+
options: { mode: true},
25+
});
26+
grunt.task.run('copy:phantom_bin');
27+
} catch (err) {
28+
grunt.verbose.writeln(err);
29+
grunt.fail.warn('No working Phantomjs binary available')
30+
}
31+
32+
});
33+
};

0 commit comments

Comments
 (0)