Skip to content

Commit

Permalink
Fix build issues on BSDs in pkg/cpu (#7116)
Browse files Browse the repository at this point in the history
Also add a cross compile script to test always cross
compilation for some well known platforms and architectures
, we support out of box compilation of these platforms even
if we don't make an official release build.

This script is to avoid regressions in this area when we
add platform dependent code.
  • Loading branch information
harshavardhana authored and nitisht committed Jan 22, 2019
1 parent 5353edc commit 8e0910a
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ matrix:
- diff -au <(gofmt -s -d cmd) <(printf "")
- diff -au <(gofmt -s -d pkg) <(printf "")
- for d in $(go list ./... | grep -v browser); do CGO_ENABLED=1 go test -v -race --timeout 15m "$d"; done
- make verifiers
- make crosscompile
- make verify
- make coverage
- cd browser && yarn && yarn test && cd ..
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ getdeps:
@echo "Installing misspell" && go get -u github.com/client9/misspell/cmd/misspell
@echo "Installing ineffassign" && go get -u github.com/gordonklaus/ineffassign

crosscompile:
@(env bash $(PWD)/buildscripts/cross-compile.sh)

verifiers: getdeps vet fmt lint cyclo deadcode spelling

vet:
Expand Down
35 changes: 35 additions & 0 deletions buildscripts/cross-compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Enable tracing if set.
[ -n "$BASH_XTRACEFD" ] && set -ex

function _init() {
## All binaries are static make sure to disable CGO.
export CGO_ENABLED=0

## List of architectures and OS to test coss compilation.
SUPPORTED_OSARCH="linux/ppc64le linux/arm64 linux/s390x darwin/amd64 freebsd/amd64"
}

function _build_and_sign() {
local osarch=$1
IFS=/ read -r -a arr <<<"$osarch"
os="${arr[0]}"
arch="${arr[1]}"
package=$(go list -f '{{.ImportPath}}')
printf -- "--> %15s:%s\n" "${osarch}" "${package}"

# Go build to build the binary.
export GOOS=$os
export GOARCH=$arch
go build -tags kqueue -o /dev/null
}

function main() {
echo "Testing builds for OS/Arch: ${SUPPORTED_OSARCH}"
for each_osarch in ${SUPPORTED_OSARCH}; do
_build_and_sign "${each_osarch}"
done
}

_init && main "$@"
2 changes: 1 addition & 1 deletion cmd/bitrot.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
SHA256 BitrotAlgorithm = 1 + iota
// HighwayHash256 represents the HighwayHash-256 hash function
HighwayHash256
// HighwayHash256 represents the Streaming HighwayHash-256 hash function
// HighwayHash256S represents the Streaming HighwayHash-256 hash function
HighwayHash256S
// BLAKE2b512 represents the BLAKE2b-512 hash function
BLAKE2b512
Expand Down
3 changes: 3 additions & 0 deletions cmd/erasure.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ func (e *Erasure) DecodeDataAndParityBlocks(ctx context.Context, data [][]byte)
return nil
}

// ShardSize - returns actual shared size from erasure blockSize.
func (e *Erasure) ShardSize() int64 {
return ceilFrac(e.blockSize, int64(e.dataBlocks))
}

// ShardFileSize - returns final erasure size from original size.
func (e *Erasure) ShardFileSize(totalLength int64) int64 {
if totalLength == 0 {
return 0
Expand All @@ -107,6 +109,7 @@ func (e *Erasure) ShardFileSize(totalLength int64) int64 {
return numShards*e.ShardSize() + lastShardSize
}

// ShardFileTillOffset - returns the effectiv eoffset where erasure reading begins.
func (e *Erasure) ShardFileTillOffset(startOffset, length, totalLength int64) int64 {
shardSize := e.ShardSize()
shardFileSize := e.ShardFileSize(totalLength)
Expand Down
2 changes: 1 addition & 1 deletion cmd/posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ func (s *posix) ReadFileStream(volume, path string, offset, length int64) (io.Re
if _, err = file.Seek(offset, io.SeekStart); err != nil {
return nil, err
}
return &posixLimitedReader{io.LimitedReader{file, length}}, nil
return &posixLimitedReader{io.LimitedReader{R: file, N: length}}, nil
}

// CreateFile - creates the file.
Expand Down
9 changes: 3 additions & 6 deletions pkg/cpu/counter_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ import (
"syscall"
"time"
"unsafe"
)

const (
// ProcessClock corresponds to the High-resolution per-process
// timer from the CPU represented in stdlib as CLOCK_PROCESS_CPUTIME_ID
processClock = 2
"golang.org/x/sys/unix"
)

func newCounter() (counter, error) {
Expand All @@ -34,7 +30,8 @@ func newCounter() (counter, error) {

func (c counter) now() time.Time {
var ts syscall.Timespec
syscall.Syscall(syscall.SYS_CLOCK_GETTIME, processClock, uintptr(unsafe.Pointer(&ts)), 0)
// Retrieve Per-process CPU-time clock
syscall.Syscall(syscall.SYS_CLOCK_GETTIME, unix.CLOCK_PROCESS_CPUTIME_ID, uintptr(unsafe.Pointer(&ts)), 0)
sec, nsec := ts.Unix()
return time.Unix(sec, nsec)
}
7 changes: 5 additions & 2 deletions pkg/cpu/counter_darwin.go → pkg/cpu/counter_other.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build darwin freebsd openbsd netbsd dragonfly windows

/*
* Minio Cloud Storage, (C) 2019 Minio, Inc.
*
Expand All @@ -17,12 +19,13 @@
package cpu

import (
"errors"
"fmt"
"runtime"
"time"
)

func newCounter() (counter, error) {
return counter{}, errors.New("cpu metrics not implemented for darwin platform")
return counter{}, fmt.Errorf("cpu metrics not implemented for %s platform", runtime.GOOS)
}

func (c counter) now() time.Time {
Expand Down
30 changes: 0 additions & 30 deletions pkg/cpu/counter_windows.go

This file was deleted.

0 comments on commit 8e0910a

Please sign in to comment.