Creating default metal library from ios framework

I am creating a framework which includes several metal files, while creating default library using device?.makeDefaultLibrary() (when this framework is embedded in a project), application is crashing. It turns out that without specifying Bundle() to makeDefaultLibrary() it only searches for library in main bundle, but as per requirement compiler should search for library in embedded framework's bundle (a .metallib file is being generated while creating Framework). I have tried specifying bundle as below:

A.

let frameworkBundle = Bundle(for: type(of: self))
let bundleLib = try device?.makeDefaultLibrary(bundle: frameworkBundle)

B.

let frameworkBundle = Bundle(identifier: "com.myframework")
let bundleLib = try device?.makeDefaultLibrary(bundle: frameworkBundle)

Still the application is crashing, I have also noticed that in both the above methods frameworkBundle is returned as nil.

  • For (B):

    Would it be possible for you to provide a small sample project that shows this problem so that someone can take a look to see what's going wrong?

  • Though I haven't figured out problem yet, but when I converted the framework to Dynamic library then it works fine!

Add a Comment

Replies

The fact that frameworkBundle is returned as nil is the main problem here.

For (A):

The documentation for Bundle has:

// Get the bundle containing the specified private class.
let myBundle = Bundle(for: NSClassFromString("MyPrivateClass")!)

so could you please try:

let frameworkBundle = Bundle(for: self.Type)
  • I have tried this but gets the same problem with static library, though with dynamic library I am not facing any issue even if I use code snippet A or B or the one suggested by you

Add a Comment