fix: windows compilation #1101

Merged
earl-warren merged 6 commits from :fix-windows-compilation into main 2025-10-24 07:00:43 +00:00
Contributor

Original pull request: #987
Fixes #1032

  • bug fixes
    • PR: fix: windows compilation
Original pull request: https://code.forgejo.org/forgejo/runner/pulls/987 Fixes https://code.forgejo.org/forgejo/runner/issues/1032 <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/1101): <!--number 1101 --><!--line 0 --><!--description Zml4OiB3aW5kb3dzIGNvbXBpbGF0aW9u-->fix: windows compilation<!--description--> <!--end release-notes-assistant-->
Moved suicide code out to platform specific files
Some checks failed
issue-labels / release-notes (pull_request_target) Successful in 5s
checks / runner exec tests (pull_request) Has been cancelled
checks / integration tests (pull_request) Has been cancelled
checks / runner integration tests (pull_request) Has been cancelled
checks / validate mocks (pull_request) Has been cancelled
checks / validate pre-commit-hooks file (pull_request) Has been cancelled
checks / build and test (pull_request) Has been cancelled
080b8ecaff
Merge branch 'main' into fix-windows-compilation
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 9s
checks / build and test (pull_request) Has been cancelled
checks / runner exec tests (pull_request) Has been cancelled
checks / integration tests (pull_request) Has been cancelled
checks / runner integration tests (pull_request) Has been cancelled
checks / validate mocks (pull_request) Has been cancelled
checks / validate pre-commit-hooks file (pull_request) Has been cancelled
384188353d
Contributor

thanks for picking it up 😁

before I suggest things, how familiar are you with Go?

thanks for picking it up 😁 before I suggest things, how familiar are you with Go?
Author
Contributor

just enough to compile a project, but I'm ready to learn

just enough to compile a project, but I'm ready to learn
Author
Contributor

I read your comments from the original pull request, but unfortunately, I only just now looked at util.go. I'll try to adjust the code accordingly.

I read your comments from the original pull request, but unfortunately, I only just now looked at util.go. I'll try to adjust the code accordingly.
Author
Contributor

I'm stuck at the same point as AnsisMalins. Since build tags seem to be file level only, I don't know how to handle this without creating a new utils.go in artifactscache containing only the suicide function. otherwise I have to duplicate all non platform specific code of handler.go to handler_windows.go. and as I understand it you said no to both options.

I'm stuck at the same point as AnsisMalins. Since build tags seem to be file level only, I don't know how to handle this without creating a new utils.go in artifactscache containing only the suicide function. otherwise I have to duplicate all non platform specific code of handler.go to handler_windows.go. and as I understand it you said no to both options.
First-time contributor

The way I understand @earl-warren comment is that they want to end with this situation:

act/artifactcache/util.go

//go:build !windows

package artifactcache

import "syscall"

func suicide() error {
	return syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
}

act/artifactcache/util_windows.go

package artifactcache

import "syscall"

func suicide() error {
	handle, err := syscall.GetCurrentProcess()
	if err != nil {
		return err
	}

	return syscall.TerminateProcess(handle, uint32(syscall.SIGTERM))
}
The way I understand @earl-warren comment is that they want to end with this situation: `act/artifactcache/util.go` ```go //go:build !windows package artifactcache import "syscall" func suicide() error { return syscall.Kill(syscall.Getpid(), syscall.SIGTERM) } ``` `act/artifactcache/util_windows.go` ```go package artifactcache import "syscall" func suicide() error { handle, err := syscall.GetCurrentProcess() if err != nil { return err } return syscall.TerminateProcess(handle, uint32(syscall.SIGTERM)) } ```
First-time contributor

That being said, I have some questions regarding original design here: Is the intention really to kill entire runner when cache servers encounters fatal error? Somehow that feels a bit extreme, though, as we are failing hard on conditions such as unable to read cache.

Imagine situation where artifact cache is mounted to NFS volume that is temporarily unavailable - I wouldn't want it to kill runner, just gracefully handle the fact that cache doesn't exist and pretend we didn't get hit instead, while logging error for operator.

That being said, I have some questions regarding original design here: Is the intention really to kill entire runner when cache servers encounters fatal error? Somehow that feels a bit extreme, though, as we are failing hard on conditions such as unable to read cache. Imagine situation where artifact cache is mounted to NFS volume that is temporarily unavailable - I wouldn't want it to kill runner, just gracefully handle the fact that cache doesn't exist and pretend we didn't get hit instead, while logging error for operator.
Contributor

@proton-ab wrote in #1101 (comment):

The way I understand @earl-warren comment is that they want to end with this situation:

Exactly!

The policy is to failing hard in case an error is not recoverable, i.e. there is no way to ensure the runner will keep working as it should. If you think it could be done differently could you please open a feature request or a discussion? This a design question that has a wider scope than this pull request.

@proton-ab wrote in https://code.forgejo.org/forgejo/runner/pulls/1101#issuecomment-64145: > The way I understand @earl-warren comment is that they want to end with this situation: Exactly! The policy is to failing hard in case an error is not recoverable, i.e. there is no way to ensure the runner will keep working as it should. If you think it could be done differently could you please open a feature request or a discussion? This a design question that has a wider scope than this pull request.
Move suicide function to utils.go
Some checks failed
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 5s
checks / build and test (pull_request) Has been cancelled
checks / runner exec tests (pull_request) Has been cancelled
checks / integration tests (pull_request) Has been cancelled
checks / runner integration tests (pull_request) Has been cancelled
checks / validate mocks (pull_request) Has been cancelled
checks / validate pre-commit-hooks file (pull_request) Has been cancelled
/ example-lxc-systemd (pull_request) Has been cancelled
0c26c71e4f
Author
Contributor

Alright, then I misunderstood the comment in the original pull request.
Code has been changed as requested.

Alright, then I misunderstood the comment in the original pull request. Code has been changed as requested.
Merge branch 'main' into fix-windows-compilation
All checks were successful
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 5s
checks / validate pre-commit-hooks file (pull_request) Successful in 40s
checks / validate mocks (pull_request) Successful in 55s
checks / build and test (pull_request) Successful in 1m17s
checks / runner exec tests (pull_request) Successful in 30s
checks / runner integration tests (pull_request) Successful in 6m27s
checks / integration tests (pull_request) Successful in 12m34s
88b770c5ce
earl-warren requested changes 2025-10-21 06:36:14 +00:00
Dismissed
Contributor

//go:build windows

otherwise it will have suicide() defined twice

`//go:build windows` otherwise it will have suicide() defined twice
Author
Contributor

I just tested it and it's defined twice with 'windows'

# code.forgejo.org/forgejo/runner/v11/act/artifactcache
act\artifactcache\utils_windows.go:5:6: suicide redeclared in this block
        act\artifactcache\utils.go:7:6: other declaration of suicide
act\artifactcache\utils.go:8:17: undefined: syscall.Kill
I just tested it and it's defined twice with 'windows' ``` # code.forgejo.org/forgejo/runner/v11/act/artifactcache act\artifactcache\utils_windows.go:5:6: suicide redeclared in this block act\artifactcache\utils.go:7:6: other declaration of suicide act\artifactcache\utils.go:8:17: undefined: syscall.Kill ```
Author
Contributor

sorry missed the file name. but in container utils_windows.go there is no such declaration. and it compiles fine without.

sorry missed the file name. but in container utils_windows.go there is no such declaration. and it compiles fine without.
Contributor

I'm very confused now. It passed CI but... how can it compile when the function is effectively declared twice if not on windows.

There is something trivial I don't see. 🤔

I'm very confused now. It passed CI but... how can it compile when the function is effectively declared twice if not on windows. There is something trivial I don't see. 🤔
Author
Contributor

I'm not used to Go, but my wild guess was that '_windows' in the file name must be interpreted as build tag automaticaly.

I'm not used to Go, but my wild guess was that '_windows' in the file name must be interpreted as build tag automaticaly.
Author
Contributor

@earl-warren so do you still want me to add the build tag to the file content or is it fine via file name?

@earl-warren so do you still want me to add the build tag to the file content or is it fine via file name?
Contributor

I have to say I absolutely do not understand how that works as it is. I would need to research why it compiles before I can give an opinion. If you find the answer this can move on. Otherwise it is a mystery blocking my review I'm afraid. I will eventually take the time to figure it out but not right now.

I have to say I absolutely do not understand how that works as it is. I would need to research why it compiles before I can give an opinion. If you find the answer this can move on. Otherwise it is a mystery blocking my review I'm afraid. I will eventually take the time to figure it out but not right now.
Owner

If a file's name, after stripping the extension and a possible _test suffix, matches any of the following patterns:

*_GOOS
*_GOARCH
*_GOOS_GOARCH

(example: source_windows_amd64.go) where GOOS and GOARCH represent any known operating system and architecture values respectively, then the file is considered to have an implicit build constraint requiring those terms (in addition to any explicit constraints in the file).

https://pkg.go.dev/cmd/go#hdr-Build_constraints

> If a file's name, after stripping the extension and a possible _test suffix, matches any of the following patterns: > > *_GOOS > *_GOARCH > *_GOOS_GOARCH > > (example: source_windows_amd64.go) where GOOS and GOARCH represent any known operating system and architecture values respectively, then the file is considered to have an implicit build constraint requiring those terms (in addition to any explicit constraints in the file). https://pkg.go.dev/cmd/go#hdr-Build_constraints >
Contributor

thanks!

thanks!
Contributor

So... having one file named act/artifactcache/utils_windows.go and the other act/artifactcache/utils_linux.go with no //go:build ... should work fine, right?

So... having one file named `act/artifactcache/utils_windows.go` and the other `act/artifactcache/utils_linux.go` with no ` //go:build ...` should work fine, right?
Owner

Usually _unix is the opposite of _windows, I think. Keeps the BSDs happy. Otherwise, yes.

Usually `_unix` is the opposite of `_windows`, I think. Keeps the BSDs happy. Otherwise, yes.
Contributor

Right... my head is elsewhere, I'm a poor reviewer right now, thanks for fixing my mistakes.

//go:build !windows

and

//go:build windows

is what I had in memory. I now understand the build tag and the special name termination are redundant, reason why it worked here, with the right mixture of name termination and build tag.

Right... my head is elsewhere, I'm a poor reviewer right now, thanks for fixing my mistakes. https://code.forgejo.org/f3/gof3/src/commit/8962fd5c4110bff78f0482afcb9e5d5b5e2029e9/util/exec_unix.go#L8 and https://code.forgejo.org/f3/gof3/src/commit/8962fd5c4110bff78f0482afcb9e5d5b5e2029e9/util/exec_windows.go#L8 is what I had in memory. I now understand the build tag and the special name termination are redundant, reason why it worked here, with the right mixture of name termination and build tag.
Author
Contributor

I think it is best how it is done (and done in container/utils.go).
You need different file names anyway but if you would use only file names you have to create one for every platform. So having a default file which excludes by comment and other files which include by name makes sense to me.
If it's done with comments to always do it the same way I would't use _windows in the file name. But that's just my opinion.

I think it is best how it is done (and done in container/utils.go). You need different file names anyway but if you would use only file names you have to create one for every platform. So having a default file which excludes by comment and other files which include by name makes sense to me. If it's done with comments to always do it the same way I would't use _windows in the file name. But that's just my opinion.
Contributor

The mixture of build tags and file name extension confused me. Please choose one or the other. If I was confused... others will I'm sure.

The mixture of build tags and file name extension confused me. Please choose one or the other. If I was confused... others will I'm sure.
First-time contributor

Do you want separate PR to change it in container/utils.go too?

Do you want separate PR to change it in `container/utils.go` too?
Author
Contributor

Alright, I added the built tag comment to utils_windows.go

Alright, I added the built tag comment to utils_windows.go
volkmnv marked this conversation as resolved
Add windows build tag to artifactcache/utils_windows.go
All checks were successful
cascade / forgejo (pull_request_target) Has been skipped
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Has been skipped
issue-labels / release-notes (pull_request_target) Successful in 7s
checks / validate pre-commit-hooks file (pull_request) Successful in 48s
checks / validate mocks (pull_request) Successful in 1m30s
checks / build and test (pull_request) Successful in 3m48s
checks / runner exec tests (pull_request) Successful in 55s
checks / runner integration tests (pull_request) Successful in 9m31s
checks / integration tests (pull_request) Successful in 18m36s
bd32eb86b4
Merge branch 'main' into fix-windows-compilation
All checks were successful
checks / validate pre-commit-hooks file (pull_request) Successful in 1m8s
checks / validate mocks (pull_request) Successful in 1m30s
checks / build and test (pull_request) Successful in 4m0s
checks / runner exec tests (pull_request) Successful in 1m7s
checks / runner integration tests (pull_request) Successful in 9m19s
checks / integration tests (pull_request) Successful in 18m27s
issue-labels / release-notes (pull_request_target) Successful in 8s
cascade / debug (pull_request_target) Has been skipped
cascade / end-to-end (pull_request_target) Successful in 7s
cascade / forgejo (pull_request_target) Successful in 3m11s
ff1dd918d0
Contributor

Thanks everyone for your patience. I learned something valuable 😁

Thanks everyone for your patience. I learned something valuable 😁
earl-warren referenced this pull request from a commit 2025-10-24 07:00:44 +00:00
earl-warren deleted branch fix-windows-compilation 2025-10-24 07:00:44 +00:00
Author
Contributor

I can only agree with that 😃
Thanks for having this merged even though Windows isn't officially supported here.

I can only agree with that 😃 Thanks for having this merged even though Windows isn't officially supported here.
Contributor

The general idea is that windows specific (or other proprietary OS) can be included as long as they are sandboxed in a clear way.

It would be very useful if you could you weigh in on the request to make room to prepare for such patches in a windows dedicated repository https://github.com/Crown0815/Forgejo-runner-windows-builder/issues/5 🙏

@Crown0815 FYI

The general idea is that windows specific (or other proprietary OS) can be included as long as they are sandboxed in a clear way. It would be very useful if you could you weigh in on the request to make room to prepare for such patches in a windows dedicated repository https://github.com/Crown0815/Forgejo-runner-windows-builder/issues/5 🙏 @Crown0815 FYI
vadiml1024 referenced this pull request from a commit 2025-10-25 14:35:55 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
forgejo/runner!1101
No description provided.