p11-glue / p11-kit

Provides a way to load and enumerate PKCS#11 modules.
https://p11-glue.github.io/p11-glue/p11-kit.html
Other
149 stars 91 forks source link

Meson build failure in macOS Catalina (appleframeworks not found, tried framework) in p11-kit 0.25.1+ #598

Closed aminehaddad closed 9 months ago

aminehaddad commented 9 months ago

I've been having compilation failures since p11-kit 0.25.1/0.25.2 in macOS Catalina (with xcode-select installed). It was working fine with 0.25.0. Should this be reported in Meson or perhaps I am missing something on my end?

==> meson setup build -Dsystem_config=/usr/local/etc -Dmodule_config=/usr/local/etc/pkcs11/modules -Dtrust_paths=/usr/local/etc/ca-certificates/cert.pem" -Dsystemd=disabled
Last 15 lines from /Users/username/Library/Logs/Homebrew/p11-kit/01.meson:
Build type: native build
Project name: p11-kit
Project version: 0.25.2
C compiler for the host machine: clang (clang 12.0.0 "Apple clang version 12.0.0 (clang-1200.0.32.29)")
C linker for the host machine: clang ld64 609.8
Host machine cpu family: x86_64
Host machine cpu: x86_64
Has header "libintl.h" : YES 
Library intl found: YES
Checking for function "dgettext" with dependency -lintl: YES 
Run-time dependency appleframeworks found: NO (tried framework)

meson.build:70:26: ERROR: Dependency "appleframeworks" not found, tried framework

Side note: it is used for dependencies in QEMU -> gnutls -> p11-kit. Thanks!

ueno commented 9 months ago

Given the CI passes on macOS 12 with "Run-time dependency appleframeworks found: YES (foundation)", I suspect there might be something missing on your build setup, though I can't point what's exactly causing this. @neverpanic do you have any thought?

aminehaddad commented 9 months ago

Quick test with check_appleframeworks.c and meson.build:

#include <stdio.h>

int main() {
    printf("Apple Frameworks Test\n");
    return 0;
}
project('check_appleframeworks', 'c')
src = 'check_appleframeworks.c'
appleframeworks = dependency('appleframeworks', modules: 'foundation')

if appleframeworks.found()
  message('appleframeworks with "foundation" module found')
else
  message('appleframeworks with "foundation" module not found')
endif

executable('check_appleframeworks', src, dependencies: appleframeworks)

Output:

username appleframeworks_test % meson build
The Meson build system
Version: 1.2.3
Source dir: /Users/username/Development/appleframeworks_test
Build dir: /Users/username/Development/appleframeworks_test/build
Build type: native build
Project name: check_appleframeworks
Project version: undefined
C compiler for the host machine: cc (clang 12.0.0 "Apple clang version 12.0.0 (clang-1200.0.32.29)")
C linker for the host machine: cc ld64 609.8
Host machine cpu family: x86_64
Host machine cpu: x86_64
Run-time dependency appleframeworks found: NO (tried framework)

meson.build:7:18: ERROR: Dependency "appleframeworks" not found, tried framework

A full log can be found at /Users/username/Development/appleframeworks_test/build/meson-logs/meson-log.txt
WARNING: Running the setup command as `meson [options]` instead of `meson setup [options]` is ambiguous and deprecated.

Error logs (meson-log.txt):

Build started at 2023-11-05T06:35:55.255921
Main binary: /usr/local/opt/python@3.12/bin/python3.12
Build Options: 
Python system: Darwin
The Meson build system
Version: 1.2.3
Source dir: /Users/username/Development/appleframeworks_test
Build dir: /Users/username/Development/appleframeworks_test/build
Build type: native build
Project name: check_appleframeworks
Project version: undefined
-----------
Detecting compiler via: `cc --version` -> 0
stdout:
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
-----------
Running command: cc -E -dM -
-----
-----------
Detecting linker via: `cc -Wl,--version` -> 1
stderr:
ld: unknown option: --version
clang: error: linker command failed with exit code 1 (use -v to see invocation)
-----------
-----------
Detecting Apple linker via: `cc -Wl,-v` -> 1
stderr:
@(#)PROGRAM:ld  PROJECT:ld64-609.8
BUILD 15:07:46 Dec 18 2020
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
Library search paths:
    /usr/local/lib
    /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib
Framework search paths:
    /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
-----------
Sanity testing C compiler: cc
Is cross compiler: False.
Sanity check compiler command line: cc sanitycheckc.c -o sanitycheckc.exe
Sanity check compile stdout:

-----
Sanity check compile stderr:

-----
Running test binary command:  /Users/username/Development/appleframeworks_test/build/meson-private/sanitycheckc.exe
C compiler for the host machine: cc (clang 12.0.0 "Apple clang version 12.0.0 (clang-1200.0.32.29)")
C linker for the host machine: cc ld64 609.8
-----------
Detecting linker via: `ar --version` -> 1
stderr:
usage:  ar -d [-TLsv] archive file ...
    ar -m [-TLsv] archive file ...
    ar -m [-abiTLsv] position archive file ...
    ar -p [-TLsv] archive [file ...]
    ar -q [-cTLsv] archive file ...
    ar -r [-cuTLsv] archive file ...
    ar -r [-abciuTLsv] position archive file ...
    ar -t [-TLsv] archive [file ...]
    ar -x [-ouTLsv] archive [file ...]
-----------
-----------
Detecting compiler via: `cc --version` -> 0
stdout:
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
-----------
Running command: cc -E -dM -
-----
-----------
Detecting linker via: `cc -Wl,--version` -> 1
stderr:
ld: unknown option: --version
clang: error: linker command failed with exit code 1 (use -v to see invocation)
-----------
-----------
Detecting Apple linker via: `cc -Wl,-v` -> 1
stderr:
@(#)PROGRAM:ld  PROJECT:ld64-609.8
BUILD 15:07:46 Dec 18 2020
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
Library search paths:
    /usr/local/lib
    /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib
Framework search paths:
    /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
-----------
Sanity testing C compiler: cc
Is cross compiler: False.
Sanity check compiler command line: cc sanitycheckc.c -o sanitycheckc.exe
Sanity check compile stdout:

-----
Sanity check compile stderr:

-----
Running test binary command:  /Users/username/Development/appleframeworks_test/build/meson-private/sanitycheckc.exe
C compiler for the build machine: cc (clang 12.0.0 "Apple clang version 12.0.0 (clang-1200.0.32.29)")
C linker for the build machine: cc ld64 609.8
-----------
Detecting linker via: `ar --version` -> 1
stderr:
usage:  ar -d [-TLsv] archive file ...
    ar -m [-TLsv] archive file ...
    ar -m [-abiTLsv] position archive file ...
    ar -p [-TLsv] archive [file ...]
    ar -q [-cTLsv] archive file ...
    ar -r [-cuTLsv] archive file ...
    ar -r [-abciuTLsv] position archive file ...
    ar -t [-TLsv] archive [file ...]
    ar -x [-ouTLsv] archive [file ...]
-----------
Build machine cpu family: x86_64
Build machine cpu: x86_64
Host machine cpu family: x86_64
Host machine cpu: x86_64
Target machine cpu family: x86_64
Target machine cpu: x86_64
Running compile:
Working directory:  /Users/username/Development/appleframeworks_test/build/meson-private/tmpgxg7gflj
Code:
 int main(void) { return 0; }
-----------
Command line: `cc /Users/username/Development/appleframeworks_test/build/meson-private/tmpgxg7gflj/testfile.c -o /Users/username/Development/appleframeworks_test/build/meson-private/tmpgxg7gflj/output.exe -O0 -Werror=implicit-function-declaration -framework foundation` -> 1
stderr:
ld: framework not found foundation
clang: error: linker command failed with exit code 1 (use -v to see invocation)
-----------
Run-time dependency appleframeworks found: NO (tried framework)

meson.build:7:18: ERROR: Dependency "appleframeworks" not found, tried framework

More information (MacOS Catalina 10.15.7):

username % xcrun --show-sdk-path 
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk
username % xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

There are more issues but not sure if they are related: Support for appleframeworks with GCC and Intel Cross-compilation for iOS fails after upgrade to Big Sur (macOS 11)

Thanks :)

aminehaddad commented 9 months ago

Hi, this works with a capital F in Foundation. Path to it is /System/Library/Frameworks/Foundation.framework, and my filesystem is also case-sensitive.

project('check_appleframeworks', 'c')
src = 'check_appleframeworks.c'
appleframeworks = dependency('appleframeworks', modules: 'Foundation')

if appleframeworks.found()
  message('appleframeworks with "foundation" module found')
else
  message('appleframeworks with "foundation" module not found')
endif

executable('check_appleframeworks', src, dependencies: appleframeworks)
......
C compiler for the host machine: cc (clang 12.0.0 "Apple clang version 12.0.0 (clang-1200.0.32.29)")
C linker for the host machine: cc ld64 609.8
Host machine cpu family: x86_64
Host machine cpu: x86_64
Run-time dependency appleframeworks found: YES (Foundation)
Message: appleframeworks with "foundation" module found
Build targets in project: 1

Found ninja-1.11.1 at /usr/local/bin/ninja
WARNING: Running the setup command as `meson [options]` instead of `meson setup [options]` is ambiguous and deprecated.

If you set it to Foundation, it should work for both case-sensitive and case-insensitive disk format. Please let me know your opinion and if it passes the tests for your macOS versions.

Thanks again!

Note: if this turns out to be the fix, case-sensitivity should also be mentioned in Meson Dependencies for AppleFrameworks

ueno commented 9 months ago

@aminehaddad thank you tracking down the issue! Regarding the fix, I would like to hear any opinion from the Meson folks. Could you open an issue at https://github.com/mesonbuild/meson/issues ?

aminehaddad commented 9 months ago

@ueno Hi, I've reported it but I also tried their python code and they seem to be lowercasing (glob) the entry in *.framework.

I'm not sure why my python script works, and why my meson build works, but it is making an error installing p11-kit. I could use some help, please! Thank you!

aminehaddad commented 9 months ago

I tried building p11-kit from source, and it worked when changing it to 'Foundation':

With 'foundation':

username p11-kit-0.25.1 % meson setup --reconfigure _build -Dsystemd=disabled -Dbash_completion=disabled
The Meson build system
Version: 1.2.3
Source dir: /Users/username/Development/p11-kit-0.25.1
Build dir: /Users/username/Development/p11-kit-0.25.1/_build
Build type: native build
Project name: p11-kit
Project version: 0.25.1
C compiler for the host machine: cc (clang 12.0.0 "Apple clang version 12.0.0 (clang-1200.0.32.29)")
C linker for the host machine: cc ld64 609.8
Host machine cpu family: x86_64
Host machine cpu: x86_64
Has header "libintl.h" : YES
Library intl found: YES
Checking for function "dgettext" with dependency -lintl: YES
Run-time dependency appleframeworks found: NO (tried framework)

meson.build:70:26: ERROR: Dependency "appleframeworks" not found, tried framework

A full log can be found at /Users/username/Development/p11-kit-0.25.1/_build/meson-logs/meson-log.txt

Changed to 'Foundation':

username p11-kit-0.25.1 % meson setup --reconfigure _build -Dsystemd=disabled -Dbash_completion=disabled
The Meson build system
Version: 1.2.3
Source dir: /Users/username/Development/p11-kit-0.25.1
Build dir: /Users/username/Development/p11-kit-0.25.1/_build
Build type: native build
Project name: p11-kit
Project version: 0.25.1
C compiler for the host machine: cc (clang 12.0.0 "Apple clang version 12.0.0 (clang-1200.0.32.29)")
C linker for the host machine: cc ld64 609.8
Host machine cpu family: x86_64
Host machine cpu: x86_64
Has header "libintl.h" : YES
Library intl found: YES
Checking for function "dgettext" with dependency -lintl: YES
Run-time dependency appleframeworks found: YES (Foundation)
Checking for size of "unsigned long" : 8
Run-time dependency threads found: YES
Checking for function "pthread_create" with dependency threads: YES
Checking for function "nanosleep" : YES
Checking for function "dlopen" : YES
....
....
Program test-objects.sh found: YES (/Users/username/Development/p11-kit-0.25.1/p11-kit/test-objects.sh)
Program test-lists.sh found: YES (/Users/username/Development/p11-kit-0.25.1/p11-kit/test-lists.sh)
Program test-messages.sh found: YES (/Users/username/Development/p11-kit-0.25.1/p11-kit/test-messages.sh)
Program test-server.sh found: YES (/Users/username/Development/p11-kit-0.25.1/p11-kit/test-server.sh)
Program test-list-mechanisms.sh found: YES (/Users/username/Development/p11-kit-0.25.1/p11-kit/test-list-mechanisms.sh)
Program test-list-tokens.sh found: YES (/Users/username/Development/p11-kit-0.25.1/p11-kit/test-list-tokens.sh)
Program test-generate-keypair.sh found: YES (/Users/username/Development/p11-kit-0.25.1/p11-kit/test-generate-keypair.sh)
Program test-export-public.sh found: YES (/Users/username/Development/p11-kit-0.25.1/p11-kit/test-export-public.sh)
Program test-import-public.sh found: YES (/Users/username/Development/p11-kit-0.25.1/p11-kit/test-import-public.sh)
Program test-profiles.sh found: YES (/Users/username/Development/p11-kit-0.25.1/p11-kit/test-profiles.sh)
Configuring pkcs11.conf.example using configuration
Program msgfmt found: YES (/usr/local/bin/msgfmt)
Program msginit found: YES (/usr/local/bin/msginit)
Program msgmerge found: YES (/usr/local/bin/msgmerge)
Program xgettext found: YES (/usr/local/bin/xgettext)
Dependency bash-completion skipped: feature bash_completion disabled
bash-completion/meson.build:7: WARNING: Will not install bash completion due to missing dependencies!
Build targets in project: 194

p11-kit 0.25.1

  Subprojects
    pkcs11-json    : YES

  User defined options
    bash_completion: disabled
    systemd        : disabled

Found ninja-1.11.1 at /usr/local/bin/ninja

I also noticed that Catalina was removed from Homebrew.

neverpanic commented 9 months ago

Unfortunately it is common for such case issues to remain undetected on macOS because the default is a case-insensitive but case-preserving filesystem.

I'm not sure whether this should be fixed in meson or p11-kit, but it's definitely a bug.

aminehaddad commented 9 months ago

If it is a case-sensitive issue, then it should follow the rules that AppleFramework does. In iOS/etc development, they use case-sensitive. In most projects with meson.build, they use case-sensitive as well:

QEMU - I use this as well (it compiles fine with darwin and it uses case-sensitive letters) mpv-player GNOME/glib gstreamer macports-wine

Can a fix be added on p11-kit as well, please? Thanks!

claviola commented 9 months ago

Thanks a lot, @aminehaddad, this allowed me upgrade locally!

For other Homebrew users going through this issue, for the time being, what allowed me to upgrade p11-kit was to do the following:

Run brew upgrade --debug p11-kit, wait for the build to fail, choose option 5 (shell) and manually change ./meson.build as @aminehaddad suggested. Save and then re-run the failed command (meson setup build -Dsystem_config=...).

After it completes, exit the shell and choose option 2, "ignore" – the build should now succeed.

claviola commented 9 months ago

I've taken the liberty to open #600 myself, feel free to close if an alternative fix is found.