swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.73k stars 1.34k forks source link

Module bundle not found when using dynamic library #6048

Open erudel opened 1 year ago

erudel commented 1 year ago

Description

The generated resource bundle accessor Bundle.module crashes in a test target because it cannot find the bundle of a dynamically linked library.

The setup is the following:

The sample code can be found here: https://github.com/erudel/spm-dynamic-bundles/

I've searched for similar issues and found this post and other similar reports, however these all seem to be using static libraries. I tried switching BaseLibrary to be a static library and everything works as expected, so it seems the issue only arises when using a dynamic library.

Expected behavior

The test target ClientLibraryTests passes

Actual behavior

ClientLibraryTests crashes with the following error:

BaseLibrary/resource_bundle_accessor.swift:40: Fatal error: unable to find bundle named BaseLibrary_ BaseLibrary

Steps to reproduce

  1. Clone project https://github.com/erudel/spm-dynamic-bundles/
  2. Double click on ClientLibrary/Package.swift to open the project with Xcode
  3. Select Product > Test (cmd-U)

Swift Package Manager version/commit hash

5.7

Swift & OS version (output of swift --version && uname -a)

swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
Target: arm64-apple-macosx12.0
Darwin M9XDHW1R40 21.6.0 Darwin Kernel Version 21.6.0: Thu Sep 29 20:13:56 PDT 2022; root:xnu-8020.240.7~1/RELEASE_ARM64_T6000 arm64

EDIT: after finding https://github.com/apple/swift-package-manager/pull/3824 it seems that, if this is indeed a bug, the problem lies in the accessor generated by Xcode and not by SPM. Is anyone able to confirm this?

shahzadmajeed commented 1 year ago

I'm seeing a similar error in generated resource_bundle_accessor.swift file which throws following error. My swift package builds fine on Xcode 13 but fails on Xcode 14.x (both 14.1 & 14.2)

Screen Shot 2023-02-06 at 5 18 48 PM