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

Support for SQLite Compile-Time Options? #37

Closed
HaydenPWoods opened this issue Apr 8, 2022 · 16 comments · Fixed by #86
Closed

Support for SQLite Compile-Time Options? #37

HaydenPWoods opened this issue Apr 8, 2022 · 16 comments · Fixed by #86

Comments

@HaydenPWoods
Copy link

Looking at this library as a replacement for react-native-sqlite-storage in a project I'm working on and first impressions are great.

I've got requirements for enabling FTS5 and Geopoly extensions. This seems possible with this library as opposed to RNSS since the SQLite source is compiled from /cpp for both iOS and Android, instead of using the phone's SQLite. Is there any method of setting compile-time options for enabling specific extensions (e.g. SQLITE_ENABLE_GEOPOLY) ?

The closest I have reached is presuming that you can set options somewhere in 'CMakeLists.txt' for Android and the podspec for iOS, but I've not been having any luck.

Thanks.

@ospfranco
Copy link
Owner

That's an interesting use case, but no, I have never tried modifying the compilation behavior of the embedded SQLite source.

Indeed you can try setting flags on the CMakeLists and for iOS I would assume you need to set them somewhere on the XCode build settings.

@ospfranco
Copy link
Owner

Arent those flags global though? You can try first setting them globally in your environment to see if that works. Then try to figure out how to enable them in a specific project only.

@HaydenPWoods
Copy link
Author

Thanks for the quick reply, and happy to hear that you think it's a possibility at least. I didn't know that these flags could be set globally, so I'll give that a shot to see if I can add any extensions at all. Global flags might be good enough for me for now, but I'll leave a comment here if I can get the flags working for the build scripts.

@ospfranco
Copy link
Owner

Ah, no they are not global variables.

https://www.sqlite.org/geopoly.html

In any case, no idea tbh. You will have to play around and see what works, try it on the CMakeLists cxx flags, maybe that will work.

@HaydenPWoods
Copy link
Author

That's a shame (it would almost be too convenient..!). No worries, and thanks for the guidance - I'll close this issue for now whilst I look into it further, and I'll note it here if I have any success.

@ospfranco
Copy link
Owner

At least on iOS/macOS here is where I set additional compilation flags. In this case for Swift compilation. But you should be able to add further flags for CLang compilation.

Screenshot 000176

Best of luck trying to make it work.

@savv
Copy link

savv commented Jun 21, 2022

Enabling the various sqlite extensions seems like a common enough feature and part of what makes sqlite great to use.

Would it be worth reopening this and figuring out how to make it easy?

@ospfranco
Copy link
Owner

Have you tried changing the xcode settings I posted?

@savv
Copy link

savv commented Jun 22, 2022

Thanks, I am planning to try it in the next few days. What about Android?

For me, "making it easy" means that this is documented somewhere, which then also implies long term support.

@ospfranco
Copy link
Owner

ospfranco commented Jun 22, 2022

As the author of the issue posted, cmakelists is the place where you pass c++ compilation flags. I think doesn't get any easier than that, C++ compilation is somewhat of a de-attached process from the build systems (gradle/xcode). If it works for you feel free to submit a PR documenting it in the README. I created and maintain this library in my free time, there are no long-term guarantees unless you are willing to pay for me to dedicate further time to it.

@savv
Copy link

savv commented Jun 22, 2022

Hi Oscar, understood, I didn't mean to suggest that you need to work on it with any urgency (nor that it has to be you) - I was merely stating that we should keep this issue open because it's a useful one, as well as what I meant.

Regarding cmakelists, it's not obvious to me how to inject options there without forking the library and setting them inside of the forked version.

@ospfranco
Copy link
Owner

@craftzdog
Copy link
Contributor

craftzdog commented Sep 28, 2022

Setting a flag in the Pod project works:

CleanShot 2022-09-28 at 16 01 42@2x

But I don't know how to set it via Podfile in my project atm 🤔


ah, so I need to use patch-package to specify the flag.

@ospfranco
Copy link
Owner

I'm open to ideas on how to pass these flags without patch package to CMakeLists and Xcode. I didn't figure out a nice way to do it so far.

@craftzdog
Copy link
Contributor

managed to change the build config via Podfile of the RN project by using a post_install hook!

  post_install do |installer|
    react_native_post_install(installer)

    installer.pods_project.targets.each do |target|
      if target.name == "react-native-quick-sqlite" then
        target.build_configurations.each do |config|
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'SQLITE_ENABLE_FTS5=1']
        end
      end
    end
  end

Next up is CMakeLists

@craftzdog
Copy link
Contributor

craftzdog commented Sep 29, 2022

ok, adding the following lines to the CMakeLists.txt works!

add_definitions(
  -DSQLITE_ENABLE_FTS5
)

well, how can this be specified from the parent project🤔
Something like rootProject.ext.get('quickSqliteBuildFlags') in build.gradle?


Yes, looks like it works:

In build.gradle:

android {  
  defaultConfig {
    externalNativeBuild {
        cmake {
            arguments '-DANDROID_STL=c++_shared',
              "-DREACT_NATIVE_VERSION=${REACT_NATIVE_VERSION}",
              "-DNODE_MODULES_DIR=${nodeModules}",
              "-DSQLITE_FLAGS='-DSQLITE_ENABLE_FTS5'"
        }
    }
  }

In CMakeLists.txt:

add_definitions(
  ${SQLITE_FLAGS}
)

craftzdog added a commit to craftzdog/react-native-quick-sqlite_old that referenced this issue Sep 29, 2022
It lets you enable compile-time options like FTS5

fix ospfranco#37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants