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

[tre, libmagic] Windows + mingw support #17769

Merged
merged 10 commits into from
May 28, 2021

Conversation

longnguyen2004
Copy link
Contributor

After a year...

Describe the pull request

  • What does your PR fix?

    Fixes [libmagic] Clean build failure on Windows #11832
    Also fixes a small bug in vcpkg_configure_make where uuid isn't removed on mingw triplets.

  • Which triplets are supported/not supported? Have you updated the CI baseline?

    Windows + mingw triplets, Yes

  • Does your PR follow the maintainer guide?

    Yes

  • If you have added/updated a port: Have you run ./vcpkg x-add-version --all and committed the result?

    Yes

if(VCPKG_TARGET_IS_WINDOWS)
list(REMOVE_ITEM ALL_LIBS_LIST "uuid")
endif()
list(TRANSFORM ALL_LIBS_LIST REPLACE "^(${_lprefix})" "")
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC this is what I initially proposed in #17137, but it didn't seem to find acceptance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So now we have 2 different approaches to the same problem, let's see which one gets accepted first.
Since on MSVC triplets, uuid.lib gets stripped entirely, I'm doing the same with mingw.

@longnguyen2004
Copy link
Contributor Author

Also, now that we have host dependencies, theoretically libmagic can be cross compiled as well, but that's for another day.

#include <errno.h>
#include <fcntl.h> /* For open and flags */
-#include <regex.h>
+#include <tre/regex.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

pass -I"<vcpkginclude>/tre" instead of patching

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you help me with passing it to MSVC? No matter what I do, it doesn't seem to get through.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that I think about it, MXE users will have a problem with this, since VCPKG_C_FLAGS are not passed through.

dnl Checks for libraries
if test "$enable_zlib" != "no"; then
- AC_CHECK_LIB(z, gzopen)
+ AC_CHECK_LIB(zlib, gzopen)
Copy link
Contributor

Choose a reason for hiding this comment

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

AC_SEARCH_LIBS ! due to debug suffix on windows. Search for z zlib zlibd

Copy link
Contributor

Choose a reason for hiding this comment

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

Search for z zlib zlibd

Is this the right order for finding zlibd before zlib in debug builds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't have to worry about which one gets found first, since only one will be available in each build.

Copy link
Contributor

Choose a reason for hiding this comment

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

as longnguyen2004 said. This is not cmake where we have to deal with both prefixes/libdirs being visible.

Copy link
Contributor

Choose a reason for hiding this comment

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

For z, fair enough. But not in general. This is part of the "gdal completely broken on Linux" story. On Linux, there is always a system path, in addition to the debug path. And generally there is no control about the user environment (manifest mode, registries, overlay ports).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dg0yt We can probably uses -nostdinc/-nostdlib and manually add back in the necessary include and library paths, but that gets tedious fast.

@JackBoosY
Copy link
Contributor

What you made contains the same changes as #17137.

@longnguyen2004
Copy link
Contributor Author

@JackBoosY I'll keep my change here for the sake of CI, when one of them is merged I'll remove it.

@dg0yt
Copy link
Contributor

dg0yt commented May 11, 2021

file requires a native file of the same version to compile the magic file, so we have to add file itself as a host dependency (is it possible?)

Maybe a host dependency of a non-core default feature on a non-default feature?

No way to pass the tool path explicitly instead of modifying PATH?

@longnguyen2004
Copy link
Contributor Author

It's possible for a port to depend on itself (I just figured it out after reading the docs...)

No way to pass the tool path explicitly instead of modifying PATH?

Yeah, but that's not a problem since it's pretty straightforward, also it's the build system that needs it, not vcpkg.

@JackBoosY JackBoosY self-assigned this May 12, 2021
@JackBoosY JackBoosY added the category:community-triplet A PR or issue related to community triplets not officially validated by the vcpkg team. label May 12, 2021
ports/libmagic/portfile.cmake Outdated Show resolved Hide resolved
@longnguyen2004
Copy link
Contributor Author

longnguyen2004 commented May 13, 2021

@Neumann-A Can you check x86-windows and see if there's a workaround?
The build system detects the correct file, but file --version returns D:\installed\x64-windows\tools\libmagic\bin\file.exe-5.40 for some reason, while the build expect file-x.xx, thus it fails to detect the version.
Removing the whole check might be good, since we're going to build file natively after all, but that sounds sketchy to me.

EDIT: https://github.com/file/file/blob/03b6dcb4a24455207ef4094560c334fbc38875bd/src/file.c#L204
This line only checks for '/' in argv[0], which is not the case on Windows (?)

@Neumann-A
Copy link
Contributor

This line only checks for '/' in argv[0], which is not the case on Windows (?)

Yeah probably need to fix that + adding ${EXEEXT} in the Makefile doing the check.
Also install the magic.mgc file into tools/libmagic/share/misc so that the tool automatically picks it up

@longnguyen2004
Copy link
Contributor Author

Eh...git rebase -i messes everything up :)

@longnguyen2004 longnguyen2004 force-pushed the libmagic-windows branch 3 times, most recently from f899987 to 4db21fb Compare May 14, 2021 13:17
Copy link
Contributor

@strega-nil-ms strega-nil-ms left a comment

Choose a reason for hiding this comment

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

This looks good to me, just needs a minor change

ports/libmagic/portfile.cmake Outdated Show resolved Hide resolved
@dg0yt
Copy link
Contributor

dg0yt commented May 16, 2021

On mingw, the build failed:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./.libs/libmagic.a(compress.o):compress.c:(.text+0xae): undefined reference to `ioctl'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./.libs/libmagic.a(compress.o):compress.c:(.text+0x108): undefined reference to `__imp_select'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./.libs/libmagic.a(compress.o):compress.c:(.text+0x12e): undefined reference to `ioctl'
collect2.exe: error: ld returned 1 exit status

@longnguyen2004
Copy link
Contributor Author

@longnguyen2004
Copy link
Contributor Author

@dg0yt Is the problem solved?

@dg0yt
Copy link
Contributor

dg0yt commented May 18, 2021

@dg0yt Is the problem solved?

Yes, mingw build succeeds now. 👍

@JackBoosY JackBoosY added info:reviewed Pull Request changes follow basic guidelines requires:discussion labels May 19, 2021
@longnguyen2004
Copy link
Contributor Author

Now that #17137 is merged, I'll take that fix off of my PR.

@JackBoosY JackBoosY added info:reviewed Pull Request changes follow basic guidelines and removed info:reviewed Pull Request changes follow basic guidelines requires:discussion labels May 27, 2021
@strega-nil-ms
Copy link
Contributor

Alright, great, thanks for the awesome work @longnguyen2004 :)

@strega-nil-ms strega-nil-ms merged commit a29126f into microsoft:master May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:community-triplet A PR or issue related to community triplets not officially validated by the vcpkg team. info:reviewed Pull Request changes follow basic guidelines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[libmagic] Clean build failure on Windows
5 participants