mrousavy / nitro

🔥 Insanely fast native C++, Swift or Kotlin modules with a statically compiled binding layer to JSI
https://nitro.margelo.com
MIT License
650 stars 22 forks source link

support USE_FRAMEWORKS=static #333

Open baveku opened 1 week ago

baveku commented 1 week ago

Fix issue: #219 #218

vercel[bot] commented 1 week ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **nitro-docs** | ⬜️ Skipped ([Inspect](https://vercel.com/margelo/nitro-docs/3fFtqTcXTkxMxQKYF6Btdudv4ws1)) | | | Nov 21, 2024 0:53am |
mrousavy commented 1 week ago

In my opinion, this shouldn't go in the +autolinking.rb file.

This should go into NitroModules.podspec and the template's .podspec, but not in the autogenerated part. It's something that might change over time, and it's also an external factor (folly) - not really my fault that this breaks. I don't think going out of my way to fix a bug in another library is the right idea.

baveku commented 1 week ago

In my opinion, this shouldn't go in the +autolinking.rb file.

This should go into NitroModules.podspec and the template's .podspec, but not in the autogenerated part. It's something that might change over time, and it's also an external factor (folly) - not really my fault that this breaks. I don't think going out of my way to fix a bug in another library is the right idea.

That's right, I'll reference other libraries instead of editing autolink.

folly_config = get_folly_config()
folly_compiler_flags = folly_config[:compiler_flags]
folly_version = folly_config[:version]
boost_compiler_flags = '-Wno-documentation'
baveku commented 1 week ago

Hey @mrousavy, First, I update umbera to support static, we don't need use HEADER_SEARCH_PATHS

// Include Swift defined types
#if __has_include("NitroImage-Swift.h")
// This header is generated by Xcode/Swift on every app build.
// If it cannot be found, make sure the Swift module's name (= podspec name) is actually "NitroImage".
#include "NitroImage-Swift.h"
#elif __has_include(<NitroImage/NitroImage-Swift.h>)
#include <NitroImage/NitroImage-Swift.h>
#else
#error NitroImage's autogenerated Swift header cannot be found! Make sure the Swift module's name (= podspec name) is actually "NitroImage", and try building the app first.
#endif

Second, I don't find any ways to support build static so I will edit podspec to support GCC_PREPROCESSOR_DEFINITIONS

$gcc_shared_flags = "$(inherited) FOLLY_NO_CONFIG FOLLY_CFG_NO_COROUTINES"
gcc_flags = ''
$use_frameworks = ENV['USE_FRAMEWORKS']
if $use_frameworks
    gcc_flags = $gcc_shared_flags
end
...

s.pod_target_xcconfig = {
        "GCC_PREPROCESSOR_DEFINITIONS" => gcc_flags}
}

Hope we can use this solution for USE_FRAMEWORKS=static