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

Add post build check to verify that the libs on macOS have the right architecture #163

Merged
merged 11 commits into from
Mar 7, 2022

Conversation

autoantwort
Copy link
Contributor

@autoantwort autoantwort commented Aug 18, 2021

@Neumann-A
Copy link
Contributor

hmm can this be generalized to include apple and normal linux with objdump instead?

neumann@heineken:~$ objdump -f /usr/lib/libvmtools.so.0

/usr/lib/libvmtools.so.0:     file format elf64-x86-64
architecture: i386:x86-64, flags 0x00000150:
HAS_SYMS, DYNAMIC, D_PAGED
start address 0x000000000001f9e0

@autoantwort
Copy link
Contributor Author

I don't know objdump very good, but it seems that it does not support universal binaries:

➜  vcpkg git:(update-fontconfig) objdump -f /Applications/Firefox.app/Contents/MacOS/libosclientcerts.dylib
➜  vcpkg git:(update-fontconfig) lipo -archs /Applications/Firefox.app/Contents/MacOS/libosclientcerts.dylib
x86_64 arm64

it also returns sometimes errors where lipo just works:

➜  vcpkg git:(update-fontconfig) objdump -f  /Users/leanderSchulten/git_projekte/Lichtsteuerung/vcpkg/packages/gettext_x64-osx/debug/lib/libintl.a 

/Users/leanderSchulten/git_projekte/Lichtsteuerung/vcpkg/packages/gettext_x64-osx/debug/lib/libintl.a(bindtextdom.o):   file format mach-o arm64

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/objdump: error: 'bindtextdom.o': Invalid/Unsupported object file format
➜  vcpkg git:(update-fontconfig) echo $?                                                                                                          
1

@autoantwort
Copy link
Contributor Author

Here an example that shows that it works:

Log
$ vcpkg install --triplet=x64-osx --host-triplet=x64-osx --binarysource=clear
... 
Starting package 2/3: gettext:x64-osx
Building package gettext[core,tools]:x64-osx...
-- Downloading https://ftp.gnu.org/pub/gnu/gettext/gettext-0.21.tar.gz;https://www.mirrorservice.org/sites/ftp.gnu.org/gnu/gettext/gettext-0.21.tar.gz -> gettext-0.21.tar.gz...
-- Cleaning sources at /Users/leanderSchulten/git_projekte/Lichtsteuerung/vcpkg/buildtrees/gettext/src/0.21-d3cbdc875d.clean. Use --editable to skip cleaning for the packages you specify.
-- Extracting source /Users/leanderSchulten/git_projekte/Lichtsteuerung/vcpkg/downloads/gettext-0.21.tar.gz
-- Applying patch 0002-Fix-uwp-build.patch
-- Applying patch 0003-Fix-win-unicode-paths.patch
-- Applying patch rel_path.patch
-- Applying patch android.patch
-- Using source at /Users/leanderSchulten/git_projekte/Lichtsteuerung/vcpkg/buildtrees/gettext/src/0.21-d3cbdc875d.clean
-- Getting CMake variables for x64-osx-rel
-- Configuring x64-osx-rel
-- Building x64-osx-rel
-- Installing x64-osx-rel
-- Configuring x64-osx-dbg
-- Building x64-osx-dbg
-- Installing x64-osx-dbg
-- Performing post-build validation
The following files were built for an incorrect architecture:

    /Users/leanderSchulten/git_projekte/Lichtsteuerung/vcpkg/packages/gettext_x64-osx/debug/lib/libintl.a
Expected x64, but was: arm64


Found 1 error(s). Please correct the portfile:
    /Users/leanderSchulten/git_projekte/Lichtsteuerung/vcpkg/ports/gettext/portfile.cmake
-- Performing post-build validation done
Error: Building package gettext:x64-osx failed with: POST_BUILD_CHECKS_FAILED
Please ensure you're using the latest portfiles with `./vcpkg update`, then
submit an issue at https://github.com/Microsoft/vcpkg/issues including:
  Package: gettext:x64-osx
  Vcpkg version: 2021-08-12-unknownhash-debug

Additionally, attach any relevant sections from the log files above.

@autoantwort autoantwort force-pushed the do-macOS-arch-check branch 2 times, most recently from de502ef to 8377d64 Compare August 18, 2021 22:11
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 really good; we should also set up testing for arm64-osx I think.

src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
return LintStatus::ERROR_DETECTED;
}
#elif defined(__APPLE__)
std::vector<FileAndArch> binaries_with_invalid_architecture;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be better implemented as a separate function unless it can actually share some of the implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah the function name was very matching and it is doing the, but now for mac. If you want I can change it, but I would prefer the current solution.

src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
@autoantwort autoantwort force-pushed the do-macOS-arch-check branch 5 times, most recently from 842bd26 to d28f208 Compare August 24, 2021 00:53
@autoantwort
Copy link
Contributor Author

What is the state of this PR?

@autoantwort autoantwort force-pushed the do-macOS-arch-check branch 4 times, most recently from c074b8e to 7c2a157 Compare October 6, 2021 11:18
@strega-nil-ms
Copy link
Contributor

It looks like this has an infinite loop; can you take a look?

@autoantwort
Copy link
Contributor Author

Ready now.

include/vcpkg/base/util.h Outdated Show resolved Hide resolved
include/vcpkg/base/util.h Outdated Show resolved Hide resolved
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
@autoantwort
Copy link
Contributor Author

Any news?

@strega-nil-ms
Copy link
Contributor

I do want @ras0219-msft's review on this.

@autoantwort
Copy link
Contributor Author

Ping @ras0219-msft for review :)

Copy link
Contributor

@ras0219-msft ras0219-msft left a comment

Choose a reason for hiding this comment

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

Approved after my comments are addressed. Thanks for the PR and happy holidays!

src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
autoantwort and others added 3 commits January 16, 2022 23:11
Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
@BillyONeal
Copy link
Member

Nicole poked Robert in person about taking another look at this one today.

Copy link
Contributor

@ras0219-msft ras0219-msft left a comment

Choose a reason for hiding this comment

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

I think there are still a few deficiencies, but I don't think this makes our current situation worse except perhaps cross-compiling from MacOS to Windows with MinGW, which according to my reading will now crash when lipo fails to understand the PE binaries.

I would like to see the hard crashes downgraded to warnings, but it's only a suggestion and I see no blocking issues for this PR.

src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
src/vcpkg/postbuildlint.cpp Outdated Show resolved Hide resolved
@strega-nil-ms strega-nil-ms merged commit cb47927 into microsoft:main Mar 7, 2022
@dg0yt
Copy link
Contributor

dg0yt commented Mar 9, 2022

except perhaps cross-compiling from MacOS to Windows with MinGW

... or mingw in general? #23450

@autoantwort autoantwort deleted the do-macOS-arch-check branch August 9, 2022 15:28
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.

binary cache on macOS is not deterministic
8 participants