Skip to content

Commit df38424

Browse files
authored
fix(common): db_common windows sqlite3 collision (#5481)
1 parent 0fa2282 commit df38424

File tree

4 files changed

+66
-50
lines changed

4 files changed

+66
-50
lines changed

packages/common/amplify_db_common/example/pubspec.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ dependencies:
1111
drift: ">=2.18.0 <2.19.0"
1212
flutter:
1313
sdk: flutter
14+
# Unused in example app, rather included to validate
15+
# windows app will build when there is a downstream dependency on sqlite3
16+
# https://github.com/aws-amplify/amplify-flutter/issues/5477
17+
sqlite3: ">=2.0.0 <2.4.7"
1418

1519
dev_dependencies:
1620
amplify_lints: ^2.0.0

packages/common/amplify_db_common/windows/CMakeLists.txt

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ add_library(${PLUGIN_NAME} SHARED
1616
"amplify_db_common_plugin.cpp"
1717
)
1818

19-
###
19+
# ##
2020
# Below here, keep in sync with: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_flutter_libs/windows/CMakeLists.txt
21-
###
21+
# ##
2222

2323
# Essentially, the idea of this build script is to compile a sqlite3.dll
2424
# and make Fluter bundle that with the final app.
2525
# It looks like we can't avoid building a sqlite3_flutter_libs.dll too,
2626
# but that's not on me.
27-
2827
apply_standard_settings(${PLUGIN_NAME})
2928
set_target_properties(${PLUGIN_NAME} PROPERTIES
3029
CXX_VISIBILITY_PRESET hidden)
@@ -34,57 +33,70 @@ target_include_directories(${PLUGIN_NAME} INTERFACE
3433
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
3534

3635
include(FetchContent)
37-
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
38-
# cmake 3.24.0 added the `DOWNLOAD_EXTRACT_TIMESTAMP` and prints an ugly warning when
39-
# the default is used, so override it to the recommended behavior.
40-
# We can't really ask users to use a cmake that recent, so there's this if here.
41-
FetchContent_Declare(
42-
sqlite3
43-
URL https://sqlite.org/2023/sqlite-autoconf-3430000.tar.gz
44-
DOWNLOAD_EXTRACT_TIMESTAMP NEW
36+
37+
# Only add the sqlite3 library if it hasn't been defined already.
38+
if(NOT TARGET sqlite3)
39+
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
40+
# cmake 3.24.0 added the `DOWNLOAD_EXTRACT_TIMESTAMP` and prints an ugly warning when
41+
# the default is used, so override it to the recommended behavior.
42+
# We can't really ask users to use a cmake that recent, so there's this if here.
43+
FetchContent_Declare(
44+
sqlite3
45+
URL https://sqlite.org/2023/sqlite-autoconf-3430000.tar.gz
46+
DOWNLOAD_EXTRACT_TIMESTAMP NEW
47+
)
48+
else()
49+
FetchContent_Declare(
50+
sqlite3
51+
URL https://sqlite.org/2023/sqlite-autoconf-3430000.tar.gz
52+
)
53+
endif()
54+
55+
FetchContent_MakeAvailable(sqlite3)
56+
57+
# Define the sqlite3 library only if it wasn't already defined.
58+
add_library(sqlite3 SHARED "sqlite3_flutter.c")
59+
60+
target_include_directories(sqlite3 PRIVATE "${sqlite3_SOURCE_DIR}")
61+
target_compile_options(sqlite3 PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O2>" "/w")
62+
63+
# Note: Keep in sync with https://github.com/simolus3/sqlite-native-libraries/blob/master/sqlite3-native-library/cpp/CMakeLists.txt
64+
target_compile_definitions(sqlite3 PRIVATE
65+
SQLITE_ENABLE_FTS5
66+
SQLITE_ENABLE_RTREE
67+
SQLITE_DQS=0
68+
SQLITE_DEFAULT_MEMSTATUS=0
69+
SQLITE_TEMP_STORE=2
70+
SQLITE_MAX_EXPR_DEPTH=0
71+
SQLITE_OMIT_AUTHORIZATION
72+
SQLITE_OMIT_DECLTYPE
73+
SQLITE_OMIT_DEPRECATED
74+
SQLITE_OMIT_GET_TABLE
75+
SQLITE_OMIT_LOAD_EXTENSION
76+
SQLITE_OMIT_PROGRESS_CALLBACK
77+
SQLITE_OMIT_SHARED_CACHE
78+
SQLITE_OMIT_TCL_VARIABLE
79+
SQLITE_OMIT_TRACE
80+
SQLITE_USE_ALLOCA
81+
SQLITE_UNTESTABLE
82+
SQLITE_HAVE_ISNAN
83+
SQLITE_HAVE_LOCALTIME_R
84+
SQLITE_HAVE_LOCALTIME_S
4585
)
86+
87+
# Create an alias for this version of sqlite3.
88+
add_library(sqlite3_amplify_db_common ALIAS sqlite3)
4689
else()
47-
FetchContent_Declare(
48-
sqlite3
49-
URL https://sqlite.org/2023/sqlite-autoconf-3430000.tar.gz
50-
)
90+
# If sqlite3 already exists, create an alias for amplify plugin to avoid duplication.
91+
add_library(sqlite3_amplify_db_common ALIAS sqlite3)
5192
endif()
52-
FetchContent_MakeAvailable(sqlite3)
53-
54-
add_library(sqlite3 SHARED "sqlite3_flutter.c")
5593

56-
target_include_directories(sqlite3 PRIVATE "${sqlite3_SOURCE_DIR}")
57-
target_compile_options(sqlite3 PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O2>" "/w")
58-
59-
# Note: Keep in sync with https://github.com/simolus3/sqlite-native-libraries/blob/master/sqlite3-native-library/cpp/CMakeLists.txt
60-
target_compile_definitions(sqlite3 PRIVATE
61-
SQLITE_ENABLE_FTS5
62-
SQLITE_ENABLE_RTREE
63-
SQLITE_DQS=0
64-
SQLITE_DEFAULT_MEMSTATUS=0
65-
SQLITE_TEMP_STORE=2
66-
SQLITE_MAX_EXPR_DEPTH=0
67-
SQLITE_OMIT_AUTHORIZATION
68-
SQLITE_OMIT_DECLTYPE
69-
SQLITE_OMIT_DEPRECATED
70-
SQLITE_OMIT_GET_TABLE
71-
SQLITE_OMIT_LOAD_EXTENSION
72-
SQLITE_OMIT_PROGRESS_CALLBACK
73-
SQLITE_OMIT_SHARED_CACHE
74-
SQLITE_OMIT_TCL_VARIABLE
75-
SQLITE_OMIT_TRACE
76-
SQLITE_USE_ALLOCA
77-
SQLITE_UNTESTABLE
78-
SQLITE_HAVE_ISNAN
79-
SQLITE_HAVE_LOCALTIME_R
80-
SQLITE_HAVE_LOCALTIME_S
81-
)
94+
target_link_libraries(${PLUGIN_NAME} PRIVATE sqlite3_amplify_db_common)
8295

83-
# Ensure sqlite3 actually gets build
84-
add_dependencies(${PLUGIN_NAME} sqlite3)
96+
add_dependencies(${PLUGIN_NAME} sqlite3_amplify_db_common)
8597

86-
# List of absolute paths to libraries that should be bundled with the plugin
98+
# List of absolute paths to libraries that should be bundled with the plugin.
8799
set(amplify_db_common_bundled_libraries
88-
"$<TARGET_FILE:sqlite3>"
100+
"$<TARGET_FILE:sqlite3_amplify_db_common>"
89101
PARENT_SCOPE
90102
)

packages/common/amplify_db_common_dart/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies:
1515
drift: ">=2.18.0 <2.19.0"
1616
meta: ^1.7.0
1717
path: ">=1.8.0 <2.0.0"
18-
sqlite3: ">=2.0.0 <2.4.3"
18+
sqlite3: ">=2.0.0 <2.4.7"
1919

2020
dev_dependencies:
2121
amplify_lints: ">=3.1.0 <3.2.0"

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dependencies:
3939
oauth2: ^2.0.2
4040
package_info_plus: ^8.0.0
4141
pigeon: ^11.0.0
42-
sqlite3: ">=2.0.0 <2.4.3"
42+
sqlite3: ">=2.0.0 <2.4.7"
4343
source_gen: ^1.3.2
4444
stack_trace: ^1.10.0
4545
uuid: ">=3.0.6 <5.0.0"

0 commit comments

Comments
 (0)