Skip to content

Remove .exe suffix when cross-compiling on Windows #27448

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

Merged
merged 5 commits into from
Oct 6, 2023
Merged

Remove .exe suffix when cross-compiling on Windows #27448

merged 5 commits into from
Oct 6, 2023

Conversation

sryze
Copy link
Contributor

@sryze sryze commented Oct 4, 2023

When compiling GItea for Linux on Windows, you get a gitea.exe file as output, but because it's a Linux executable, the .exe extension is unnecessary.

This PR adds a check for GOOS environment variable in addition to OS.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 4, 2023
@github-actions github-actions bot added the topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile label Oct 4, 2023
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Oct 4, 2023
@lng2020
Copy link
Member

lng2020 commented Oct 5, 2023

That's not right. What if I want to compile for Windows on Linux? Maybe we should check GOOS and GOARCH first. If they are not set, then we check the makefile OS env.

@sryze
Copy link
Contributor Author

sryze commented Oct 5, 2023

@lng2020 Thanks, I haven't thought of the reverse situation for some reason. Updated.

Copy link
Member

@lng2020 lng2020 left a comment

Choose a reason for hiding this comment

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

BTW, Is there a certain reason to replace findstring Windows with Windows_NT? I did the search and those two ways seem the same.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Oct 6, 2023
@silverwind
Copy link
Member

BTW, Is there a certain reason to replace findstring Windows with Windows_NT? I did the search and those two ways seem the same.

I guess the previous exact match is still better, even if the name is not accurate. I was unable to find any docs on this OS variable anywhere, I assume it is provided by Make itself?

@sryze
Copy link
Contributor Author

sryze commented Oct 6, 2023

It is defined by default on Windows by the system. I couldn't find any docs for this on MSDN, but it's mentioned in a Wikipedia article here

%OS%
The %OS% variable contains a symbolic name of the operating system family to distinguish between differing feature sets in batchjobs. It resembles an identically named environment variable %OS% found in all DOS-related operating systems of Digital Research-origin like Concurrent DOS, Multiuser DOS, REAL/32, DOS Plus, DR DOS, Novell DOS and OpenDOS. %OS% always holds the string "Windows_NT" on the Windows NT family.[26]

It seems that it should be safe to just check for equality with Windows_NT, I'm not sure why the Makefile had an additional Windows case. Do you think it should be a ifeq $(OS),Windows_NT only?

Update:

Checked it on Cygwin/MSYS - same value there.

@sryze
Copy link
Contributor Author

sryze commented Oct 6, 2023

Looks like it returns Windows on some machines, accoding to this issue: #16007

@silverwind
Copy link
Member

silverwind commented Oct 6, 2023

Looks like it returns Windows on some machines, accoding to this issue: #16007

In this case the findstr is good. Ideally it would check whether string starts with Windows.

Makefile Outdated
else ifeq ($(OS), Windows)
ifeq ($(GOOS),windows)
IS_WINDOWS := yes
else ifeq ($(findstring Windows,$(OS)),Windows)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
else ifeq ($(findstring Windows,$(OS)),Windows)
else ifeq ($(patsubst Windows%,,$(OS)),)

Test with this:

OS := Windows_NT

all:
ifeq ($(patsubst Windows%,,$(OS)),)
	@echo "$(OS) starts with Windows"
else
	@echo "$(OS) doesn't start with Windows"
endif

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, this is better. Updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually this doesn't work when OS is empty

Copy link
Member

@silverwind silverwind Oct 6, 2023

Choose a reason for hiding this comment

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

A bit of a hack but this works with empty as well:

ifeq ($(patsubst Windows%,x,$(OS)),x)

Copy link
Member

Choose a reason for hiding this comment

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

This is clearer:

ifeq ($(patsubst Windows%,Windows,$(OS)),Windows)

Copy link
Member

Choose a reason for hiding this comment

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

On the other hand it fails with spaces OS = Windows NT. Let's keep the current version.

@silverwind silverwind self-requested a review October 6, 2023 16:10
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. labels Oct 6, 2023
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Oct 6, 2023
@pull-request-size pull-request-size bot added size/XS and removed size/S labels Oct 6, 2023
@silverwind silverwind added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Oct 6, 2023
@silverwind silverwind enabled auto-merge (squash) October 6, 2023 18:05
auto-merge was automatically disabled October 6, 2023 18:06

Head branch was pushed to by a user without write access

@techknowlogick techknowlogick merged commit 6acce16 into go-gitea:main Oct 6, 2023
@GiteaBot GiteaBot added this to the 1.22.0 milestone Oct 6, 2023
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Oct 6, 2023
zjjhot added a commit to zjjhot/gitea that referenced this pull request Oct 8, 2023
* giteaoffical/main: (79 commits)
  Pre-register OAuth application for tea (go-gitea#27509)
  Fix mermaid flowchart margin issue (go-gitea#27503)
  add a shortcut to user's profile page to admin user details (go-gitea#27299)
  Fix actionlint (go-gitea#27513)
  [skip ci] Updated translations via Crowdin
  Update JS and PY dependencies (go-gitea#27501)
  Improve feed icons and feed merge text color (go-gitea#27498)
  Downgrade `go-co-op/gocron` to v1.31.1 (go-gitea#27511)
  Enable markdownlint `no-duplicate-header` (go-gitea#27500)
  bump go-deps (go-gitea#27489)
  Apply to became a maintainer (go-gitea#27491)
  change runner for binary
  [skip ci] Updated translations via Crowdin
  Remove .exe suffix when cross-compiling on Windows (go-gitea#27448)
  move re-useable workflow
  add checkout to disk-clean
  use hosted runners for nightly actions (go-gitea#27485)
  Avoid run change title process when the title is same (go-gitea#27467)
  Fix panic in storageHandler (go-gitea#27446)
  Rename the default themes to gitea-light, gitea-dark, gitea-auto (go-gitea#27419)
  ...
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Jan 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants