Fix build issues on BSDs in pkg/cpu (#7116)

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.
This commit is contained in:
Harshavardhana 2019-01-22 09:27:23 +05:30 committed by Nitish Tiwari
parent 5353edcc38
commit 8e0910ab3e
9 changed files with 53 additions and 40 deletions

View File

@ -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 ..

View File

@ -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:

35
buildscripts/cross-compile.sh Executable file
View File

@ -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 "$@"

View File

@ -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

View File

@ -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
@ -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)

View File

@ -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.

View File

@ -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) {
@ -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)
}

View File

@ -1,3 +1,5 @@
// +build darwin freebsd openbsd netbsd dragonfly windows
/*
* Minio Cloud Storage, (C) 2019 Minio, Inc.
*
@ -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 {

View File

@ -1,30 +0,0 @@
/*
* Minio Cloud Storage, (C) 2019 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cpu
import (
"errors"
"time"
)
func newCounter() (counter, error) {
return counter{}, errors.New("cpu metrics not implemented for windows platform")
}
func (c counter) now() time.Time {
return time.Time{}
}