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

OpenSSL: improve MinGW support on Windows #6079

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from
Open

Conversation

Doekin
Copy link
Contributor

@Doekin Doekin commented Dec 27, 2024

OpenSSL targeting MinGW can be built on Linux or MSYS2, but not directly on Windows. This PR introduces a workaround to enable building on Windows using Git Bash.

@Doekin Doekin marked this pull request as draft December 27, 2024 23:50
@Doekin

This comment was marked as outdated.

@Doekin Doekin marked this pull request as ready for review December 28, 2024 03:17
if jom then
package:add("deps", "jom", {private = true})
elseif is_subhost("windows") then
package:add("deps", "strawberry-perl", { private = true })
Copy link
Member

Choose a reason for hiding this comment

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

why remove {system = false}, it will break some things. it will use incorrect perl in some systems and ci envs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you please share more details about the scenarios where the system Perl might fail? There might be a workaround we can implement to address this issue. Using the system Perl helps save disk space.

For your reference, I tested with Perl installed via scoop, and it seemed to work as expected.

Copy link
Member

Choose a reason for hiding this comment

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

I can't reproduce it because I don't remember what happened before. But since there is a clear comment to fix this problem by passing system = false, we shouldn't just remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment indicated that Perl bundled with GitForWindows fails to build OpenSSL. I encountered this issue too at the beginning. The error message is as follows:

Can't locate Pod/Usage.pm in @INC (you may need to install the Pod::Usage module) (@INC entries checked: . /usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl) at configdata.pm line 11398.
BEGIN failed--compilation aborted at configdata.pm line 11398.
Compilation failed in require.
BEGIN failed--compilation aborted.

I looked into the config script and found that Pod::Usage is only used to generate help messages, which are shown with the ./Configure help command. I guess that the help message is not needed when installing the package. So, I removed the use of the Pod::Usage module, and it builds successfully using Perl from GitForWindows.

@@ -32,15 +32,18 @@ package("openssl")
if package:is_plat("android") and is_subhost("windows") and os.arch() == "x64" then
-- when building for android on windows, use msys2 perl instead of strawberry-perl to avoid configure issue
package:add("deps", "msys2", {configs = {msystem = "MINGW64", base_devel = true}, private = true})
elseif is_subhost("windows") and not package:is_precompiled() then
Copy link
Member

Choose a reason for hiding this comment

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

and why not remove not package:is_precompiled()?
If you are using the build-artifacts binary, you do not need to compile openssl and install its build dependencies.

Copy link
Member

Choose a reason for hiding this comment

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

and here

Copy link
Contributor Author

@Doekin Doekin Dec 29, 2024

Choose a reason for hiding this comment

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

OK, there is no is_precompiled now

Copy link
Member

Choose a reason for hiding this comment

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

OK, there is no is_precompiled now

but we need is_precompiled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I misunderstood.

Copy link
Member

Choose a reason for hiding this comment

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

If you are downloading a precompiled binary, then all build dependencies do not need to be installed.

https://github.com/xmake-mirror/build-artifacts/releases?q=openssl&expanded=true

Copy link
Contributor Author

@Doekin Doekin Dec 30, 2024

Choose a reason for hiding this comment

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

I guess the outer if not package:is_precompiled() then might work .

on_load(function (package)
if not package:is_precompiled() then

@Doekin
Copy link
Contributor Author

Doekin commented Dec 29, 2024

Supported Combinations of Targets and Windows Environments

  • Build for Windows in PowerShell with Strawberry Perl
  • Build for MinGW in Git Bash with bundled Perl

Unsupported Combinations of Targets and Environments

  • Build for MinGW in PowerShell
    • This is expected due to the reliance on many Unix-like shell commands in the makefile.

package:add("deps", "msys2", {configs = {msystem = "MINGW64", base_devel = true}, private = true})
elseif is_subhost("windows") then
import("lib.detect.find_tool")
local perl = find_tool("perl", {paths={"$(env PERL)"}})
Copy link
Member

Choose a reason for hiding this comment

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

we should not call find_tool in on_load

if on_check then
on_check(function (package)
import("lib.detect.find_tool")
local perl = assert(find_tool("perl", {paths={"$(env PERL)"}}), "package(openssl): perl not found!")
Copy link
Member

Choose a reason for hiding this comment

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

use package:find_tool and add spaces =

@@ -83,7 +102,13 @@ package("openssl")
table.insert(configs, "no-makedepend")
table.insert(configs, "/FS")
end
os.vrunv("perl", configs)
import("lib.detect.find_tool")
local perl = assert(find_tool("perl", {paths={"$(env PERL)"}}), "package(openssl): perl not found!")
Copy link
Member

Choose a reason for hiding this comment

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

we should not call find_tool, we should use add_deps to bind perl path end and run perl

@Doekin Doekin marked this pull request as draft December 29, 2024 07:11
@Doekin Doekin marked this pull request as ready for review December 29, 2024 09:21
@SirLynix
Copy link
Member

I'm sorry but I don't understand what benefit this PR does, it seems complicated to just use the system perl instead of installing strawberry perl or am I missing something?

@Doekin
Copy link
Contributor Author

Doekin commented Dec 29, 2024

Thank you for your feedback. Let me clarify the reasoning behind this PR:

  1. When building OpenSSL for Windows, we can make use of a previously installed Strawberry Perl, as OpenSSL‘s configure script won't find the Perl bundled with Git Bash if we are in PowerShell or Command Prompt.
  2. For building OpenSSL for MinGW, Strawberry Perl cannot generate the Unix-style paths that OpenSSL requires, which leads to build failures. I added prompts to guide users to build in the appropriate environment. Suitable environments include Git Bash and MSYS2 shell.

Additionally, when building OpenSSL in Git Bash, we may encounter errors due to the missing POD::Usage Perl module, which is not included in the Perl bundled with Git Bash. However, this module is not essential for configuring OpenSSL's build; it is used to generate help information in the configure script. We can remove the use of POD::Usage to continue building.

I hope this clarifies the purpose of the changes.

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

Successfully merging this pull request may close these issues.

3 participants