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

fix(common): db_common windows sqlite3 collision #5481

Merged
merged 9 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 59 additions & 45 deletions packages/common/amplify_db_common/windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,58 +33,72 @@ target_include_directories(${PLUGIN_NAME} INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)

# Include FetchContent for sqlite3 if not already available.
include(FetchContent)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
# cmake 3.24.0 added the `DOWNLOAD_EXTRACT_TIMESTAMP` and prints an ugly warning when
# the default is used, so override it to the recommended behavior.
# We can't really ask users to use a cmake that recent, so there's this if here.
FetchContent_Declare(
sqlite3
URL https://sqlite.org/2023/sqlite-autoconf-3430000.tar.gz
DOWNLOAD_EXTRACT_TIMESTAMP NEW

# Only add the sqlite3 library if it hasn't been defined already.
if (NOT TARGET sqlite3)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
FetchContent_Declare(
sqlite3
URL https://sqlite.org/2023/sqlite-autoconf-3430000.tar.gz
DOWNLOAD_EXTRACT_TIMESTAMP NEW
)
else()
FetchContent_Declare(
sqlite3
URL https://sqlite.org/2023/sqlite-autoconf-3430000.tar.gz
)
endif()

FetchContent_MakeAvailable(sqlite3)

# Define the sqlite3 library only if it wasn't already defined.
add_library(sqlite3 SHARED "sqlite3_flutter.c")

# Configure sqlite3 compilation options.
target_include_directories(sqlite3 PRIVATE "${sqlite3_SOURCE_DIR}")
target_compile_options(sqlite3 PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O2>" "/w")

# Note: Keep in sync with https://github.com/simolus3/sqlite-native-libraries/blob/master/sqlite3-native-library/cpp/CMakeLists.txt
target_compile_definitions(sqlite3 PRIVATE
SQLITE_ENABLE_FTS5
SQLITE_ENABLE_RTREE
SQLITE_DQS=0
SQLITE_DEFAULT_MEMSTATUS=0
SQLITE_TEMP_STORE=2
SQLITE_MAX_EXPR_DEPTH=0
SQLITE_OMIT_AUTHORIZATION
SQLITE_OMIT_DECLTYPE
SQLITE_OMIT_DEPRECATED
SQLITE_OMIT_GET_TABLE
SQLITE_OMIT_LOAD_EXTENSION
SQLITE_OMIT_PROGRESS_CALLBACK
SQLITE_OMIT_SHARED_CACHE
SQLITE_OMIT_TCL_VARIABLE
SQLITE_OMIT_TRACE
SQLITE_USE_ALLOCA
SQLITE_UNTESTABLE
SQLITE_HAVE_ISNAN
SQLITE_HAVE_LOCALTIME_R
SQLITE_HAVE_LOCALTIME_S
)

# Create an alias for this version of sqlite3 for your plugin's use.
add_library(sqlite3_amplify_db_common ALIAS sqlite3)
else()
FetchContent_Declare(
sqlite3
URL https://sqlite.org/2023/sqlite-autoconf-3430000.tar.gz
)
# If sqlite3 already exists, create an alias for your plugin to avoid duplication.
add_library(sqlite3_amplify_db_common ALIAS sqlite3)
endif()
FetchContent_MakeAvailable(sqlite3)

add_library(sqlite3 SHARED "sqlite3_flutter.c")

target_include_directories(sqlite3 PRIVATE "${sqlite3_SOURCE_DIR}")
target_compile_options(sqlite3 PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O2>" "/w")

# Note: Keep in sync with https://github.com/simolus3/sqlite-native-libraries/blob/master/sqlite3-native-library/cpp/CMakeLists.txt
target_compile_definitions(sqlite3 PRIVATE
SQLITE_ENABLE_FTS5
SQLITE_ENABLE_RTREE
SQLITE_DQS=0
SQLITE_DEFAULT_MEMSTATUS=0
SQLITE_TEMP_STORE=2
SQLITE_MAX_EXPR_DEPTH=0
SQLITE_OMIT_AUTHORIZATION
SQLITE_OMIT_DECLTYPE
SQLITE_OMIT_DEPRECATED
SQLITE_OMIT_GET_TABLE
SQLITE_OMIT_LOAD_EXTENSION
SQLITE_OMIT_PROGRESS_CALLBACK
SQLITE_OMIT_SHARED_CACHE
SQLITE_OMIT_TCL_VARIABLE
SQLITE_OMIT_TRACE
SQLITE_USE_ALLOCA
SQLITE_UNTESTABLE
SQLITE_HAVE_ISNAN
SQLITE_HAVE_LOCALTIME_R
SQLITE_HAVE_LOCALTIME_S
)
# Link your plugin to the sqlite3 alias.
target_link_libraries(${PLUGIN_NAME} PRIVATE sqlite3_amplify_db_common)

# Ensure sqlite3 actually gets build
add_dependencies(${PLUGIN_NAME} sqlite3)
# Ensure sqlite3 actually gets built.
add_dependencies(${PLUGIN_NAME} sqlite3_amplify_db_common)

# List of absolute paths to libraries that should be bundled with the plugin
# List of absolute paths to libraries that should be bundled with the plugin.
set(amplify_db_common_bundled_libraries
"$<TARGET_FILE:sqlite3>"
"$<TARGET_FILE:sqlite3_amplify_db_common>"
PARENT_SCOPE
)
2 changes: 1 addition & 1 deletion packages/common/amplify_db_common_dart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
drift: ">=2.18.0 <2.19.0"
meta: ^1.7.0
path: ">=1.8.0 <2.0.0"
sqlite3: ">=2.0.0 <2.4.3"
sqlite3: ">=2.0.0 <2.4.7"

dev_dependencies:
amplify_lints: ">=3.1.0 <3.2.0"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies:
oauth2: ^2.0.2
package_info_plus: ^8.0.0
pigeon: ^11.0.0
sqlite3: ">=2.0.0 <2.4.3"
sqlite3: ">=2.0.0 <2.4.7"
source_gen: ^1.3.2
stack_trace: ^1.10.0
uuid: ">=3.0.6 <5.0.0"
Expand Down
Loading