Skip to content

Conversation

@903174293
Copy link

Add Windows/Cygwin/MINGW64 support to generated Makefiles

Fix Kubebuilder to work correctly on Windows environments (CMD, PowerShell,
Cygwin, and Git Bash/MINGW64) by improving the generated Makefile to handle
path format differences.

Problem:

  • Cygwin/MINGW64 make provides Unix-style paths (/cygdrive/d/... or /d/...)
  • Windows Go tools require Windows-style paths (D:/...)
  • Setting GOBIN with Unix paths caused "go install" to fail
  • Binary execution failed due to path format mismatches

Solution:

  • Detect environment (Windows/Cygwin/MINGW64/Linux/macOS)
  • Convert paths between Unix and Windows formats as needed
  • Use Windows paths for GOBIN (Go tools)
  • Use Unix paths for shell execution (in Cygwin/MINGW64)
  • Handle .exe extensions on Windows
  • Use module paths instead of ./... for better compatibility

Changes:

  • Modified: pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go
  • Added path conversion functions (convert-to-windows-path, convert-to-mingw-path)
  • Added environment detection (UNAME_S, IS_MINGW, IS_CYGWIN)
  • Added dual path variables (LOCALBIN_FOR_GO, LOCALBIN_FOR_SHELL)
  • Updated tool binary paths to use correct format per platform
  • Improved go-install-tool function to handle all environments

Testing:

  • Tested on Windows CMD, PowerShell, Cygwin, Git Bash (MINGW64), and Linux
  • All environments pass: kubebuilder init && kubebuilder create api
  • Verified generated files: bin/controller-gen.exe, api/v1/zz_generated.deepcopy.go
  • No breaking changes to Linux/macOS behavior

Backward Compatibility:

  • No breaking changes
  • Existing projects continue to work
  • Graceful degradation if tools unavailable
  • No API changes

Fixes: #[issue-number]

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 29, 2025

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: 903174293 / name: 位面之子 (af40d68)

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 903174293
Once this PR has been reviewed and has the lgtm label, please assign varshaprasad96 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link
Contributor

Welcome @903174293!

It looks like this is your first PR to kubernetes-sigs/kubebuilder 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kubebuilder has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 29, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @903174293. Thanks for your PR.

I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Nov 29, 2025
@903174293
Copy link
Author

在windows os上执行创建文件件,进入到文件夹下,执行如下命令即可验证:
git init
go mod init hihonor.com/kubebuilder/app
kubebuilder init --domain hihonor.com
kubebuilder create api --group kubebuilder --version v1 --kind App

@vitorfloriano
Copy link
Contributor

Hi @903174293 thanks for opening the PR. I'm afraid native Windows support is not currently on the roadmap for Kubebuilder. The motivation behind not pursuing Windows support can be read in here, here and here

Nonetheless, if you still think native support is better than the WSL2 + Docker combo we recommend, or if there are any limitations/shortcomings to that, please let us know and we can further discuss this patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants