aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.33k stars 247 forks source link

CMake Error at flutter/ephemeral/.plugin_symlinks/amplify_db_common/windows/CMakeLists.txt:54 (add_library): add_library cannot create target "sqlite3" because an imported target with the same name already exists. #5477

Open richard457 opened 2 months ago

richard457 commented 2 months ago

Description

CMake Error at flutter/ephemeral/.plugin_symlinks/amplify_db_common/windows/CMakeLists.txt:54 (add_library): add_library cannot create target "sqlite3" because an imported target with the same name already exists.

Categories

Steps to Reproduce

CMake Error at flutter/ephemeral/.plugin_symlinks/amplify_db_common/windows/CMakeLists.txt:54 (add_library): add_library cannot create target "sqlite3" because an imported target with the same name already exists.

Screenshots

No response

Platforms

Flutter Version

3.24

Amplify Flutter Version

2.0

Deployment Method

Amplify Gen 2

Schema

No response

Equartey commented 2 months ago

Hi @richard457, can you give specific reproduction steps? What are you doing to produce this error?

richard457 commented 2 months ago

Create a simple flutter project, add amplify_storage_s3: ^2.4.1 and powersync: ^1.8.2 or any other plugin that uses sqlite3 the compile the app for windows, I think I checking in amplify_db_common and realized that we are using sqlite3 as name which will conflict with other sqlite3 packages out there

# The Flutter tooling requires that developers have a version of Visual Studio
# installed that includes CMake 3.14 or later. You should not increase this
# version, as doing so will cause the plugin to fail to compile for some
# customers of the plugin.
cmake_minimum_required(VERSION 3.14)

# Project-level configuration.
set(PROJECT_NAME "amplify_db_common")
project(${PROJECT_NAME} LANGUAGES C CXX)

# This value is used when generating builds using this plugin, so it must
# not be changed
set(PLUGIN_NAME "amplify_db_common_plugin")

add_library(${PLUGIN_NAME} SHARED
  "amplify_db_common_plugin.cpp"
)

###
# Below here, keep in sync with: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_flutter_libs/windows/CMakeLists.txt
###

# Essentially, the idea of this build script is to compile a sqlite3.dll
# and make Fluter bundle that with the final app.
# It looks like we can't avoid building a sqlite3_flutter_libs.dll too,
# but that's not on me.

apply_standard_settings(${PLUGIN_NAME})
set_target_properties(${PLUGIN_NAME} PROPERTIES
  CXX_VISIBILITY_PRESET hidden)
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
target_include_directories(${PLUGIN_NAME} INTERFACE
  "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)

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
  )
else()
  FetchContent_Declare(
    sqlite3
    URL https://sqlite.org/2023/sqlite-autoconf-3430000.tar.gz
  )
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
)

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

# List of absolute paths to libraries that should be bundled with the plugin
set(amplify_db_common_bundled_libraries
  "$<TARGET_FILE:sqlite3>"
  PARENT_SCOPE
)

@Equartey

Equartey commented 2 months ago

@richard457 Thanks for sharing. We'll investigate and let you know what we find.

richard457 commented 2 months ago

@Equartey any update?

Equartey commented 1 month ago

@richard457 I've been able to reproduce the error. Currently investigating a solution. I'll you know when more progress has been made.

richard457 commented 1 month ago

Thank you for update @Equartey We really appreciate your support, we are patiently waiting.

Equartey commented 3 weeks ago

Hi @richard457, apologies for the delay. A fix for this has been merged. We will notify you when it has been released!

richard457 commented 3 weeks ago

I installed the update but the error still persists

.plugin_symlinks/amplify_db_common/windows".
  See documentation for policy CMP0002 for more details.
Unable to generate build files

https://github.com/yegobox/flipper/actions/runs/11630194715/job/32388623308 cc @Equartey

ekjotmultani commented 3 weeks ago

Hi @richard457, our sincere apologies that you are still facing this issue. For clarification, you upgraded to the latest version 2.5.0 of amplify-flutter, yet nothing changed?.

veganguy commented 3 weeks ago

For clarification, you upgraded to the latest version 2.5.0 of amplify-flutter, yet nothing changed?.

That's correct - I have upgraded to amplify-flutter 2.5.0 and still get the same compile error on Windows, too. πŸ₯ΊπŸ˜’

ekjotmultani commented 3 weeks ago

Thank you @veganguy for the update. We will investigate further into this issue and the fix.

veganguy commented 3 weeks ago

Thank you, @ekjotmultani - we sincerely appreciate your assistance with this. πŸ™πŸ½

richard457 commented 2 weeks ago

Yes I upgraded to 2.5.0 and it is still the same.

Equartey commented 4 days ago

Hi @richard457, sorry for the delay. I was reviewing the build log you provided and noticed you have had subsequent clean builds. Can you confirm if you are still facing this issue or resolved it another way?

richard457 commented 3 days ago

The issue continues to be a problem that needs urgent attention.

Equartey commented 3 days ago

@richard457, I have a potential fix. Can you verify it works before we release it?

You can do this by adding a pubspec_overrides.yaml file with the following content:

dependency_overrides:
  amplify_db_common:
    git:
      url: https://github.com/aws-amplify/amplify-flutter.git
      ref: fix/windows-cmake-namespace
      path: packages/common/amplify_db_common
      fetch: fix/windows-cmake-namespace
veganguy commented 3 days ago

@richard457, I have a potential fix. Can you verify it works before we release it?

Dreams really do come true! πŸ˜ƒ

I just tried your fix and I can confirm that YES I can finally compile one again for Windows. πŸ‘πŸ½

Thanks so very much resolving this, @Equartey @ekjotmultani ! Most sincerely appreciated. πŸ™πŸ½

Equartey commented 3 days ago

@veganguy awesome! I'm still working on fixing the failing tests. You're welcome to continue to use the override I supplied. Changes I make to fix tests might cause unexpected breakage. In such a case, consider changing the override ref to the original commit hash that produced a clean build for you. For example:

dependency_overrides:
  amplify_db_common:
    git:
      url: https://github.com/aws-amplify/amplify-flutter.git
      ref: 9010ff4e2470e086d469af1ad1ecb61f9054e6b7
      path: packages/common/amplify_db_common
      fetch: 9010ff4e2470e086d469af1ad1ecb61f9054e6b7

Thanks again for your patience. Once the fix gets released we will notify yall here.

veganguy commented 3 days ago

Thanks again for your patience. Once the fix gets released we will notify yall here.

Thanks for that! And thank you, @Equartey, once again for your most-appreciated assistance.