-
Notifications
You must be signed in to change notification settings - Fork 1
fix: add cross-platform build support for darwin and windows #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| //go:build !linux | ||
|
|
||
| package bootstrap | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "runtime" | ||
| ) | ||
|
|
||
| func addUserToGroup(_ *Context, userName, groupName string) error { | ||
| return fmt.Errorf("adding user %s to group %s is not supported on %s", userName, groupName, runtime.GOOS) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package diags | ||
|
|
||
| import ( | ||
| "archive/tar" | ||
| "io/fs" | ||
| "syscall" | ||
| "time" | ||
| ) | ||
|
|
||
| func fillPlatformStatFields(th *tar.Header, fi fs.FileInfo) { | ||
| st, ok := fi.Sys().(*syscall.Stat_t) | ||
| if !ok { | ||
| return | ||
| } | ||
| th.Uid, th.Gid = int(st.Uid), int(st.Gid) | ||
| th.AccessTime = time.Unix(st.Atim.Unix()) | ||
| th.ChangeTime = time.Unix(st.Ctim.Unix()) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| //go:build !linux | ||
|
|
||
| package diags | ||
|
|
||
| import ( | ||
| "archive/tar" | ||
| "io/fs" | ||
| ) | ||
|
|
||
| func fillPlatformStatFields(_ *tar.Header, _ fs.FileInfo) { | ||
| // On non-Linux platforms, Uid, Gid, AccessTime, and ChangeTime | ||
| // are left at their zero values. Darwin uses different syscall.Stat_t | ||
| // field names (Atimespec/Ctimespec) and Windows has no syscall.Stat_t. | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package server | ||
|
|
||
| import ( | ||
| "os/exec" | ||
| "syscall" | ||
| ) | ||
|
|
||
| // setProcGroup configures the command to start in a new process group, | ||
| // enabling group-wide signal delivery via negative PID. | ||
| func setProcGroup(cmd *exec.Cmd) { | ||
| cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} | ||
| } | ||
|
|
||
| // terminateProcessGroup sends SIGTERM to the entire process group. | ||
| func terminateProcessGroup(pid int) error { | ||
| return syscall.Kill(-pid, syscall.SIGTERM) | ||
| } | ||
|
|
||
| // killProcessGroup sends SIGKILL to the entire process group. | ||
| func killProcessGroup(pid int) error { | ||
| return syscall.Kill(-pid, syscall.SIGKILL) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| //go:build !linux | ||
|
|
||
| package server | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os/exec" | ||
| "runtime" | ||
| ) | ||
|
|
||
| func setProcGroup(_ *exec.Cmd) {} | ||
|
|
||
| func terminateProcessGroup(_ int) error { | ||
| return fmt.Errorf("process group termination not supported on %s", runtime.GOOS) | ||
| } | ||
|
|
||
| func killProcessGroup(_ int) error { | ||
| return fmt.Errorf("process group kill not supported on %s", runtime.GOOS) | ||
| } | ||
|
Comment on lines
+13
to
+19
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't the process group thing work on Darwin?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was failing when I tried cross-compiling, but I'll dig into it more to try to get a true/proper fix. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,12 +8,28 @@ import ( | |
|
|
||
| var info = sync.OnceValue(loadVersionInfo) | ||
|
|
||
| // versionOverride, if non-empty, replaces MainVersion from build info. | ||
| var versionOverride string | ||
|
|
||
| // SetVersion overrides the main version string reported by Version() and | ||
| // VersionInfo(). Call before any use of the version functions. | ||
| func SetVersion(v string) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain the use case for this? The normal Go build process should put your VCS info into the binary, right?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I need to pull that out, I pushed on the wrong branch, I was trying to fix an issue where the VCS would show in 2 different ways depending on how it was set and it was confusing because sometimes it would show mine, and sometimes it would show the gdev one. The override I tried doing didn't resolve it, but there's probably a better way to handle it regardless, it shouldn't be upstream.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main module info should definitely only ever show yours, unless you're building e.g. the "gdev" example :) |
||
| versionOverride = v | ||
| } | ||
|
|
||
| func Version() string { | ||
| if versionOverride != "" { | ||
| return versionOverride | ||
| } | ||
| return info().MainVersion | ||
| } | ||
|
|
||
| func VersionInfo() versionInfo { | ||
| return info() | ||
| vi := info() | ||
| if versionOverride != "" { | ||
| vi.MainVersion = versionOverride | ||
| } | ||
| return vi | ||
| } | ||
|
|
||
| type versionInfo struct { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,12 @@ import ( | |
| "runtime" | ||
| ) | ||
|
|
||
| // FallbackLogFileEnv is an environment variable that can be set to provide | ||
| // a fallback log file path for daemons started without systemd support. | ||
| // | ||
| // This will not be passed to the actual daemon. | ||
| const FallbackLogFileEnv = "__FALLBACK_LOG_FILE" | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably just go into |
||
|
|
||
| func StartDaemon( | ||
| ctx context.Context, | ||
| name string, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should at least be able to put together a reasonable implementation for Darwin? I don't know off the top of my head what the "Sys" stat structure is for Windows though