AparokshaUI / adwaita-swift

A framework for creating user interfaces for GNOME with an API similar to SwiftUI
https://aparokshaui.github.io/adwaita-swift/
MIT License
749 stars 16 forks source link

Redefinition of module 'FFI' #11

Closed litewrap closed 3 months ago

litewrap commented 3 months ago

Describe the bug

macOS 13.6.6 Xcode 15.2

Building Adwaita Swift Pkg give the following error:

Redefinition of module 'FFI' /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/ffi/module.modulemap:1:8 Redefinition of module 'FFI'

Homebrew and libffi on my M1 mac:

admin@mbam1 ~ % which pkg-config
/opt/homebrew/bin/pkg-config

admin@mbam1 ~ % pkg-config --cflags libffi -I/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include/ffi

I found this same issue previously reported in Homebrew and SwiftPM sites by user having same clash problem when they try building swift-systemlib-demo.

Related links: Strange clash between Xcode and command-line tools when building Swift system library package #4025 https://github.com/orgs/Homebrew/discussions/4025

Patch *.sdk paths from pkgConfig files to the current SDK #6772 https://github.com/apple/swift-package-manager/pull/6772

See details here: https://github.com/apple/swift-package-manager/issues/6439

I give a try to compile the Swift package swift-systemlib-demo and its fine without error. As explained in This package that was used by the SwiftPM team to reproduce the error and test their fix.

It just strange the error re-appear when building Adwaita for Swift.

Any idea ?

To Reproduce

Download the Swift package and swift build

Expected behavior

Build success

Additional context

Building for debugging... /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/ffi/module.modulemap:1:8: error: redefinition of module 'FFI' module FFI [system] { ^ /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include/ffi/module.modulemap:1:8: note: previously defined here module FFI [system] [extern_c] { ^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/ffi/module.modulemap:1:8: error: redefinition of module 'FFI' module FFI [system] { ^ /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include/ffi/module.modulemap:1:8: note: previously defined here module FFI [system] [extern_c] {

david-swift commented 3 months ago

Thanks for opening the issue, @litewrap! I experienced this as well when testing on macOS. Here is what works for me:

  1. Clean the build folder (Xcode: Product > Clean Build Folder...).
  2. Reset package caches (Xcode: File > Packages > Reset Package Caches)
  3. Delete the DerivedData folder (~/Library/Developer/Xcode/DerivedData)
  4. Run the following command in a terminal:
    sed -i '' 's/-I..includedir.//g' $(brew --prefix)/Library/Homebrew/os/mac/pkgconfig/*/libffi.pc
  5. Resolve package versions (Xcode: File > Packages > Resolve Package Versions)
  6. Run the app. Now, it succeeds.

I'm not sure whether every step is strictly necessary. Does that help in your case?

I first experienced this problem here: https://github.com/stackotter/swift-cross-ui/issues/47

litewrap commented 3 months ago

Does that help in your case?

Yes package build success !

Thanks David and bravo for this great package !!

david-swift commented 3 months ago

Nice! While libadwaita works on macOS, I recommend using Linux for the best experience. I recommend trying Asahi Linux. Thanks for opening the issue!

david-swift commented 3 months ago

Thank you!