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

build(client/electron): build Windows with MinGW #1952

Merged
merged 4 commits into from
Apr 5, 2024
Merged

Conversation

fortuna
Copy link
Collaborator

@fortuna fortuna commented Apr 4, 2024

This works on both Linux and Windows.

I was even able to run tun2socks with Wine!

/cc @amircybersec

@fortuna fortuna requested a review from a team as a code owner April 4, 2024 22:31
Copy link
Contributor

@jyyi1 jyyi1 left a comment

Choose a reason for hiding this comment

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

We need to update the CI script as well. The build jobs are failing.

Also suggest to update the PR title to build(client/electron): ..., here is a list of all conventional commit types, we can either to build or ci.

@fortuna fortuna changed the title chore(client/electron): build Windows with MinGW build(client/electron): build Windows with MinGW Apr 4, 2024
@fortuna fortuna requested a review from jyyi1 April 4, 2024 23:38
Copy link
Collaborator Author

@fortuna fortuna left a comment

Choose a reason for hiding this comment

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

Comments addressed

Copy link
Contributor

@jyyi1 jyyi1 left a comment

Choose a reason for hiding this comment

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

This is exiciting! We can now finally cross-compile Windows binaries natively! Before merging the code, we need to consider some behavior changes carefully (for example, changing from 32-bit to 64-bit).


android: $(BUILDDIR)/android/tun2socks.aar

$(BUILDDIR)/android/tun2socks.aar: $(GOMOBILE)
mkdir -p "$(BUILDDIR)/android"
$(ANDROID_BUILD_CMD) -o "$@" $(IMPORT_PATH)/$(ROOT_PKG)/outline/tun2socks $(IMPORT_PATH)/$(ROOT_PKG)/outline/shadowsocks
# Don't strip Android debug symbols so we can upload them to crash reporting tools.
Copy link
Contributor

@jyyi1 jyyi1 Apr 4, 2024

Choose a reason for hiding this comment

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

I think we are still stripping the debug symbols (-w)? Should this be a TODO?

Also we need to consider whether we should include debug symbols, that increase the binary size in a significant amount.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

-s is what disables the symbol table.
-w is disable DWARF generation

Ideally we would output tun2socks with debug info, and the client build would remove them. Is that possible?

But that's out of scope for this PR


$(WINDOWS_BUILDDIR)/tun2socks.exe:
mkdir -p "$(@D)"
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC="x86_64-w64-mingw32-gcc" go build --ldflags=--extldflags=$(XGO_LDFLAGS) -o "$@" $(ELECTRON_PKG)
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this is updating from a 32-bit (386) binary to 64-bit (amd64), which might break some old OS users (like 32-bit Windows 7 / 8 / 10).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As discussed, let's move forward with 64-bit


$(WINDOWS_BUILDDIR)/tun2socks.exe:
mkdir -p "$(@D)"
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC="x86_64-w64-mingw32-gcc" go build --ldflags=--extldflags=$(XGO_LDFLAGS) -o "$@" $(ELECTRON_PKG)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe not in this PR: our CI is not checking the build file (it is building directly from native Windows), we may need to add some x-compile CI jobs in the future.

@@ -30,6 +29,26 @@ npm run action electron/start [windows|linux]

### Windows

To build for Windows on a macOS, you need to install minGW v11.0.1.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
To build for Windows on a macOS, you need to install minGW v11.0.1.
To build for Windows on a macOS, you need to install [MinGW-w64](https://www.mingw-w64.org/) v11.0.1.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@@ -30,6 +29,26 @@ npm run action electron/start [windows|linux]

### Windows

To build for Windows on a macOS, you need to install minGW v11.0.1.

With Homebrew (how to ensure consistent version?):
Copy link
Contributor

Choose a reason for hiding this comment

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

Will MacPorts allow you downloading an old version? Actually homebrew is not the official release channel, MacPorts is: https://www.mingw-w64.org/downloads/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, updated.

Copy link
Collaborator Author

@fortuna fortuna left a comment

Choose a reason for hiding this comment

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

Another look?


android: $(BUILDDIR)/android/tun2socks.aar

$(BUILDDIR)/android/tun2socks.aar: $(GOMOBILE)
mkdir -p "$(BUILDDIR)/android"
$(ANDROID_BUILD_CMD) -o "$@" $(IMPORT_PATH)/$(ROOT_PKG)/outline/tun2socks $(IMPORT_PATH)/$(ROOT_PKG)/outline/shadowsocks
# Don't strip Android debug symbols so we can upload them to crash reporting tools.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

-s is what disables the symbol table.
-w is disable DWARF generation

Ideally we would output tun2socks with debug info, and the client build would remove them. Is that possible?

But that's out of scope for this PR


$(WINDOWS_BUILDDIR)/tun2socks.exe:
mkdir -p "$(@D)"
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC="x86_64-w64-mingw32-gcc" go build --ldflags=--extldflags=$(XGO_LDFLAGS) -o "$@" $(ELECTRON_PKG)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As discussed, let's move forward with 64-bit

@@ -30,6 +29,26 @@ npm run action electron/start [windows|linux]

### Windows

To build for Windows on a macOS, you need to install minGW v11.0.1.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@@ -30,6 +29,26 @@ npm run action electron/start [windows|linux]

### Windows

To build for Windows on a macOS, you need to install minGW v11.0.1.

With Homebrew (how to ensure consistent version?):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, updated.

@fortuna fortuna requested a review from jyyi1 April 5, 2024 16:40
Copy link
Contributor

@jyyi1 jyyi1 left a comment

Choose a reason for hiding this comment

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

LGTM now, thanks!

@fortuna fortuna merged commit 29d2f2b into master Apr 5, 2024
19 checks passed
@fortuna fortuna deleted the fortuna-win branch April 5, 2024 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants