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

dotnet6.0-maccatalyst: Linking fails on native reference dylib #2

Closed
angelru opened this issue Aug 31, 2022 · 21 comments
Closed

dotnet6.0-maccatalyst: Linking fails on native reference dylib #2

angelru opened this issue Aug 31, 2022 · 21 comments

Comments

@angelru
Copy link

angelru commented Aug 31, 2022

Hello,

I can't get your library to work for MacCatalyst

More info:
dotnet/maui#9808
xamarin/xamarin-macios#15044

@mmoraga
Copy link

mmoraga commented Aug 31, 2022

just edit the macOS Makefile to include the necessary flags for catalyst and you'll get a fat binary to use for the catalyst platform.

https://github.com/Pkcs11Interop/empty-pkcs11/blob/2d4de20cbbb14ac251fc5e43f1f12728b5d377ba/build/osx/Makefile

@angelru
Copy link
Author

angelru commented Aug 31, 2022

just edit the macOS Makefile to include the necessary flags for catalyst and you'll get a fat binary to use for the catalyst platform.

https://github.com/Pkcs11Interop/empty-pkcs11/blob/2d4de20cbbb14ac251fc5e43f1f12728b5d377ba/build/osx/Makefile

but in which line do I add this?

clang -target x86_64-apple-ios-macabi \
-arch arm64 -arch x86_64 \
-isysroot `xcrun --sdk macosx --show-sdk-path` \
-miphoneos-version-min=13.0 \
-fembed-bitcode \
main.c

@mmoraga
Copy link

mmoraga commented Sep 1, 2022

try changing

CC= gcc
ARCH_FLAGS= -m32

to

CC= clang
ARCH_FLAGS= -target x86_64-apple-ios-macabi -arch arm64 -arch x86_64 -isysroot `xcrun --sdk macosx --show-sdk-path` -miphoneos-version-min=13.0 -fembed-bitcode

but you'll have to play around with it yourself a bit

@jariq
Copy link
Member

jariq commented Sep 1, 2022

@angelru could you please help me to understand the root cause of this issue by providing more high-level description of your problem? By high-level I mean:

  • Why are you using/targeting MacCatalyst?
  • What are you trying to achieve by using Pkcs11Interop projects with MacCatalyst?
  • On what platforms do you expect your application to run?
  • Does your cryptographic device vendor provide PKCS#11 libraries for all those platforms?
  • etc..

@angelru
Copy link
Author

angelru commented Sep 1, 2022

@jariq
Hello, the application compiles and works with Xamarin.macOS but when creating it with .NET MAUI I get this error:

  ld: building for Mac Catalyst, but linking in dylib built for macOS, file 'obj/Debug/net6.0-maccatalyst/maccatalyst-x64/nativelibraries/libempty-pkcs11-x64.dylib' for architecture x86_64
         clang: error: linker command failed with exit code 1 (use -v to see invocation)

The app runs on windows desktop and mac.

@angelru
Copy link
Author

angelru commented Sep 1, 2022

try changing

CC= gcc
ARCH_FLAGS= -m32

to

CC= clang
ARCH_FLAGS= -target x86_64-apple-ios-macabi -arch arm64 -arch x86_64 -isysroot `xcrun --sdk macosx --show-sdk-path` -miphoneos-version-min=13.0 -fembed-bitcode

but you'll have to play around with it yourself a bit

Thanks, but this keeps generating the same file for me.

@angelru
Copy link
Author

angelru commented Sep 5, 2022

@mmoraga @jariq
I can't get it to compile a .NET MAUI application, can you help me?

@jariq
Copy link
Member

jariq commented Sep 6, 2022

@angelru I was trying to replicate your issue in my environment over the weekend and ended up with MAUI app working on Windows and not building on macOS. Up until now I didn't have enough time to analyze why it's not building. I don't when I'll be able to continue.

@angelru
Copy link
Author

angelru commented Sep 6, 2022

@jariq
Indeed, on windows it works fine, but on macOS this warning appears:

  ld: building for Mac Catalyst, but linking in dylib built for macOS, file 'obj/Debug/net6.0-maccatalyst/maccatalyst-x64/nativelibraries/libempty-pkcs11-x64.dylib' for architecture x86_64
         clang: error: linker command failed with exit code 1 (use -v to see invocation)

It seems that libempty-pkcs11-x64.dylib needs to be generated for Mac Catalyst, but I haven't been able to.

@mmoraga
Copy link

mmoraga commented Sep 6, 2022

I managed to get it to build by editing the Makefile ARCH flags to:

ARCH_FLAGS= -target x86_64-apple-ios14.8-macabi -arch arm64 -arch x86_64 -isysroot `xcrun --sdk macosx --show-sdk-path` -miphoneos-version-min=14.8 -fembed-bitcode

then building a minimal maccatalyst project succeeded:

% dotnet build
MSBuild version 17.3.0+92e077650 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  Detected signing identity:

    Bundle Id: com.companyname.catalyst_pkcs
    App Id: com.companyname.catalyst_pkcs
  catalyst-pkcs -> /Users/manuel.moraga/Documents/catalyst-pkcs/bin/Debug/net6.0-maccatalyst/maccatalyst-x64/catalyst-pkcs.dll
  Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:03.94

PR is here: #3

@angelru
Copy link
Author

angelru commented Sep 8, 2022

I managed to get it to build by editing the Makefile ARCH flags to:

ARCH_FLAGS= -target x86_64-apple-ios14.8-macabi -arch arm64 -arch x86_64 -isysroot `xcrun --sdk macosx --show-sdk-path` -miphoneos-version-min=14.8 -fembed-bitcode

then building a minimal maccatalyst project succeeded:

% dotnet build
MSBuild version 17.3.0+92e077650 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  Detected signing identity:

    Bundle Id: com.companyname.catalyst_pkcs
    App Id: com.companyname.catalyst_pkcs
  catalyst-pkcs -> /Users/manuel.moraga/Documents/catalyst-pkcs/bin/Debug/net6.0-maccatalyst/maccatalyst-x64/catalyst-pkcs.dll
  Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:03.94

PR is here: #3

Can you show the csproj file?

@mmoraga
Copy link

mmoraga commented Sep 8, 2022

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0-maccatalyst</TargetFramework>
    <RuntimeIdentifier>maccatalyst-x64</RuntimeIdentifier>
    <RootNamespace>catalyst_pkcs</RootNamespace>
    <OutputType>Exe</OutputType>
    <Nullable>enable</Nullable>
    <ImplicitUsings>true</ImplicitUsings>
    <SupportedOSPlatformVersion>14.2</SupportedOSPlatformVersion>
  </PropertyGroup>
  <ItemGroup>
  <NativeReference Include="libempty-pkcs11-catalyst.dylib">
      <Kind>Dynamic</Kind>
      <IsCxx>False</IsCxx>
  </NativeReference>
  </ItemGroup>
</Project>

@angelru
Copy link
Author

angelru commented Sep 8, 2022

It works very well!

@angelru
Copy link
Author

angelru commented Nov 17, 2022

@mmoraga @jariq Pkcs11Interop/Pkcs11Interop#215

It seems that with the new versions of .NET it does not connect with the token, did you get an error?

@angelru
Copy link
Author

angelru commented Nov 24, 2022

@mmoraga Compile compiles and before it worked but now it doesn't, does it work for you?

@mmoraga
Copy link

mmoraga commented Nov 24, 2022

I don't actually use maccatalyst so I don't really know.

@angelru
Copy link
Author

angelru commented Nov 24, 2022

@mmoraga Would you mind trying? see if you see anything?

here I put the error:

Pkcs11Interop/Pkcs11Interop#215

@angelru
Copy link
Author

angelru commented Feb 2, 2023

@mmoraga @jariq I understand that there is no solution for now right?

@angelru
Copy link
Author

angelru commented Mar 23, 2024

is there news?

@jariq
Copy link
Member

jariq commented Mar 23, 2024

Nope. I am not currently working on anything MAUI or maccatalyst related.

@jariq
Copy link
Member

jariq commented May 25, 2024

Since 11586be the macOS version of empty-pkcs11 library is built for both x86_64-apple-macos10.12 and arm64-apple-macos11 targets and then merged into a single Mach-O universal binary (empty-pkcs11.dylib) usable on both Apple silicon and Intel-based Mac computers. This version is also working in a Catalyst app on macOS so I am closing this issue now.

Unresolved Pkcs11Interop related problems with Catalyst apps will be further discussed in Pkcs11Interop/Pkcs11Interop#215

@jariq jariq closed this as completed May 25, 2024
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

No branches or pull requests

3 participants