fix(go): Compilation errors on GOOS=windows #1723
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
#1722
Description of changes:
Fixes #1722 by moving the implementation of
GetProcessCpuTimeMillis
to an os specificextern_{os}.go
file. The file naming and use of compiler directives are required for go programs that have dependencies on packages that do no provide the same types/function signatures, etc across build targets. Thesyscall
package is the main culprit here, which does not implement the same functions or types across unix-like and windows versions.Changed
GetProcessCpuTimeMillis
, that only works on unix-like build targets (unix,linux,darwin,freebsd,etc) out ofStandardLibrary/runtimes/go/ImplementationFromDafny-go/Time_/externs.go
to a file calledexterns_unix.go
in the same directory. This is because the current implementation uses thesyscall.Getrusage
function and thesyscall.Rusage
type which are only implemented in the unix-like versions of the syscall package. Adding the compiler directive//go:build !windows
along with the file name ensures this implementation will only be used on unix-like build targets and preserves backwards compatibility.Added
extern_windows.go
added with an implementation ofGetProcessCpuTimeMillis
that uses the .This file utilizes the
//go:build windows
compiler directive so only windows builds (GOOS=windows
or-tags=windows
) use this implementation. It uses theGetProcessTimes
function from the windows API to acquire the same information asGetRusage
windows-latest
as an os to test with in/library/.github/workflows/library_go_tests.yml
Squash/merge commit message, if applicable:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.