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

NordicDFU dynamic linking? #501

Open
mateusforgi opened this issue Feb 8, 2023 · 9 comments
Open

NordicDFU dynamic linking? #501

mateusforgi opened this issue Feb 8, 2023 · 9 comments
Labels

Comments

@mateusforgi
Copy link
Contributor

mateusforgi commented Feb 8, 2023

Can we change the linking type to .dynamic?
.library(name: "NordicDFU", type: .dynamic, targets: ["NordicDFU"])

I have a XCFramework, that depends on NordicDFU but it cannot link to NordicDFU at runtime because NordicDFU is not linked with dynamic type.

On apple documentation it says this:
Leave this parameter so Swift Package Manager can choose between static or dynamic linking (recommended).

But on the other part it says this:
A library’s product can be either statically or dynamically linked. It’s recommended that you don’t explicity declare the type of library, so Swift Package Manager can choose between static or dynamic linking based on the preference of the package’s consumer.

It is kind of confusing as it recommends the dynamic linking but It also says to let the type as nil.
https://developer.apple.com/documentation/packagedescription/product/library(name:type:targets:)

Note: ZIPFoundation would need to have dynamic linking too.

@mateusforgi
Copy link
Contributor Author

@philips77 can you take a look on that?

@dinesharjani
Copy link
Contributor

So, if you change the library to .dynamic, does this work for you? It fixes the issue?

@philips77
Copy link
Member

Are you referring to this line:

.library(name: "NordicDFU", targets: ["NordicDFU"])

But we don't specify that parameter, so SPM should be able to link it any way you want, right?

@mateusforgi
Copy link
Contributor Author

mateusforgi commented Feb 23, 2023

So, if you change the library to .dynamic, does this work for you? It fixes the issue?

Correct, but we also need to make ZIPFoundation dynamic. I already opened a issue there.

Are you referring to this line:

.library(name: "NordicDFU", targets: ["NordicDFU"])

But we don't specify that parameter, so SPM should be able to link it any way you want, right?

Yes, it is this line. We need to change to.

.library(name: "NordicDFU", type: .dynamic, targets: ["NordicDFU"]),

But it will not work unless ZIPFoundation is also dynamic.

Regarding SPM should be able to link it anyway. This is the real issue. It looks like it does not. According to this comment on swift forum there is no way of influence that beyond package manifest.

See also this comment about possible solutions. For me the only think that worked was making dynamic IOS-DFU-Library and ZIPFoundation.

@dinesharjani
Copy link
Contributor

@mateusforgi as soon as ZIPFoundation makes their change, either make a PR here or let us know and we'll change it as well.

@mateusforgi
Copy link
Contributor Author

@dinesharjani thanks, I will open a pr as soon as they make their change.

@philips77
Copy link
Member

No, no.. that change on our side would force the lib to be dynamically linked. Now it can be linked dynamically or staticly, depending on settings in your project's SPM config.
We would only change if our lib had to be dynamically linked, but I guess that's not the case

@philips77
Copy link
Member

I guess you're referring to https://stackoverflow.com/a/70812112 which says that xcode always prefers static linking, right? Unless we specify otherwise.

@mateusforgi
Copy link
Contributor Author

mateusforgi commented Feb 24, 2023

@philips77 correct. But as NordicDFU is a dependency from my SDK, this answer from stack overflow does not solve the issue because it assumes I am adding a package to an App. The final user would not add my SDK to their app, NordicDFU would be downloaded by swift package because it is a dependency from my SDK. So the solution of adding to "Frameworks, Libraries, and Embedded Content" does not work.

The real issue is that swift package manager does not allow to import a dependency and say how it will be linked, the only way to do that is by saying it on the package manifest.

Things that I did and worked.

  1. Forked dependencies and changed NordicDFU and ZIPFoundation to .dynamic.
    Or
  2. Made NordicDFU and ZIPFoundation a XCFramework too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants