Skip to content
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

Ensure tbot compiles on windows #43877

Merged
merged 8 commits into from
Jul 9, 2024
Merged

Conversation

hugoShaka
Copy link
Contributor

@hugoShaka hugoShaka commented Jul 5, 2024

Tbot was not compiling on windows, this was not an issue because we never tried to. Now that tctl can run an embedded tbot (tctl terraform env) we need lib/tbot to compile on windows.

This PR splits the fs implementations for 3 OS variants:

  • linux: no functional change, all features supported including ownership check and secure symlinks
  • unix (except linux): no functional change, best effort ownership check, no secure symlink support
  • windows: now compiles, no ownership check nor secure symlink support

This PR potentially breaks compiling tbot on non unix systems that are not windows. However I think this was never a thing to begin with as compilation was very likely broken (non unix systems don't have *syscall.Stat_t).

After this PR tbot should now build on windows, and even be able to write files. However, as it is not able to verify ownership I don't think we want to officially support it yet.

Changelog: Make tbot compilable on Windows.

Copy link

github-actions bot commented Jul 5, 2024

The PR changelog entry failed validation: Changelog entry not found in the PR body. Please add a "no-changelog" label to the PR, or changelog lines starting with changelog: followed by the changelog entries for the PR.

lib/tbot/botfs/fs_linux.go Outdated Show resolved Hide resolved
Copy link
Contributor

@strideynet strideynet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but @timothyb89 should deffo review this as well.

@zmb3
Copy link
Collaborator

zmb3 commented Jul 5, 2024

You could also add tbot to the build-windows workflow to prevent this from regressing

lib/tbot/botfs/fs_unix.go Outdated Show resolved Hide resolved
lib/tbot/botfs/fs_linux.go Outdated Show resolved Hide resolved
@hugoShaka hugoShaka added this pull request to the merge queue Jul 8, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 8, 2024
@hugoShaka hugoShaka enabled auto-merge July 8, 2024 16:15
@hugoShaka hugoShaka added this pull request to the merge queue Jul 8, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 8, 2024
@hugoShaka
Copy link
Contributor Author

I struggled to get tbot to compile on windows as io and syscall bits were spread across tbot's codebase. @strideynet or @timothyb89 please take another look as the PR significantly changed since you reviewed it.

Cross-compilation now works:

# install cross-compiler
brew install mingw-w64

# build for windows
GOOS=windows GOARCH=amd64 make build/tbot -B
  GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build -tags " kustomize_disable_go_plugin_support" -o build/tbot  -ldflags '-w -s ' -trimpath  -buildmode=pie ./tool/tbot

# build for darwin
make build/tbot -B
  GOOS=darwin GOARCH=arm64  go build -tags " kustomize_disable_go_plugin_support" -o build/tbot  -ldflags '-w -s  -extldflags=-ld_classic' -trimpath  ./tool/tbot

# build for linux
GOOS=linux GOARCH=amd64 make build/tbot -B
  GOOS=linux GOARCH=amd64  go build -tags " kustomize_disable_go_plugin_support" -o build/tbot  -ldflags '-w -s ' -trimpath  ./tool/tbot

Copy link
Contributor

@timothyb89 timothyb89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me, and worked without any trouble on my Windows box

@hugoShaka hugoShaka added this pull request to the merge queue Jul 9, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 9, 2024
@hugoShaka hugoShaka added this pull request to the merge queue Jul 9, 2024
Merged via the queue into master with commit 7de9a98 Jul 9, 2024
39 checks passed
@hugoShaka hugoShaka deleted the hugo/tbot-compile-on-windows branch July 9, 2024 14:11
@public-teleport-github-review-bot

@hugoShaka See the table below for backport results.

Branch Result
branch/v15 Failed
branch/v16 Create PR

hugoShaka added a commit that referenced this pull request Jul 11, 2024
* Ensure tbot compiles on windows

* Restore unix tbot support

* fixup! Restore unix tbot support

* address feedback

* Fix tbot build on windows, use CGO for this OS

* Move unix-specific syscalls and file descriptors out of os-agnostic files

* fixup! Move unix-specific syscalls and file descriptors out of os-agnostic files

* lint
github-merge-queue bot pushed a commit that referenced this pull request Jul 12, 2024
* Ensure tbot compiles on windows

* Restore unix tbot support

* fixup! Restore unix tbot support

* address feedback

* Fix tbot build on windows, use CGO for this OS

* Move unix-specific syscalls and file descriptors out of os-agnostic files

* fixup! Move unix-specific syscalls and file descriptors out of os-agnostic files

* lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants