Skip to content

Commit 686de87

Browse files
committed
wip - can we build against the amalgamation
across all our platforms
1 parent 3d93011 commit 686de87

File tree

8 files changed

+311433
-89
lines changed

8 files changed

+311433
-89
lines changed

dependencies.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

ext/sqlite3/extconf.rb

Lines changed: 54 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require "mkmf"
22
require "yaml"
33

4+
# rubocop:disable Style/GlobalVars
45
module Sqlite3
56
module ExtConf
67
ENV_ALLOWLIST = ["CC", "CFLAGS", "LDFLAGS", "LIBS", "CPPFLAGS", "LT_SYS_LIBRARY_PATH", "CPP"]
@@ -48,58 +49,59 @@ def configure_system_libraries
4849
end
4950

5051
def configure_packaged_libraries
51-
minimal_recipe.tap do |recipe|
52-
recipe.configure_options += [
53-
"--disable-shared",
54-
"--enable-static",
55-
"--enable-fts5"
56-
]
57-
ENV.to_h.tap do |env|
58-
user_cflags = with_config("sqlite-cflags")
59-
more_cflags = [
60-
"-fPIC", # needed for linking the static library into a shared library
61-
"-O2", # see https://github.com/sparklemotion/sqlite3-ruby/issues/335 for some benchmarks
62-
"-fvisibility=hidden", # see https://github.com/rake-compiler/rake-compiler-dock/issues/87
63-
"-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1",
64-
"-DSQLITE_USE_URI=1",
65-
"-DSQLITE_ENABLE_DBPAGE_VTAB=1",
66-
"-DSQLITE_ENABLE_DBSTAT_VTAB=1"
67-
]
68-
env["CFLAGS"] = [user_cflags, env["CFLAGS"], more_cflags].flatten.join(" ")
69-
recipe.configure_options += env.select { |k, v| ENV_ALLOWLIST.include?(k) }
70-
.map { |key, value| "#{key}=#{value.strip}" }
71-
end
72-
73-
unless File.exist?(File.join(recipe.target, recipe.host, recipe.name, recipe.version))
74-
recipe.cook
75-
end
76-
recipe.activate
77-
78-
# on macos, pkg-config will not return --cflags without this
79-
ENV["PKG_CONFIG_ALLOW_SYSTEM_CFLAGS"] = "t"
80-
81-
# only needed for Ruby 3.1.3, see https://bugs.ruby-lang.org/issues/19233
82-
RbConfig::CONFIG["PKG_CONFIG"] = config_string("PKG_CONFIG") || "pkg-config"
83-
84-
lib_path = File.join(recipe.path, "lib")
85-
pcfile = File.join(lib_path, "pkgconfig", "sqlite3.pc")
86-
abort_pkg_config("pkg_config") unless pkg_config(pcfile)
87-
88-
# see https://bugs.ruby-lang.org/issues/18490
89-
ldflags = xpopen(["pkg-config", "--libs", "--static", pcfile], err: [:child, :out], &:read)
90-
abort_pkg_config("xpopen") unless $?.success?
91-
ldflags = ldflags.split
92-
93-
# see https://github.com/flavorjones/mini_portile/issues/118
94-
"-L#{lib_path}".tap do |lib_path_flag|
95-
ldflags.prepend(lib_path_flag) unless ldflags.include?(lib_path_flag)
96-
end
97-
98-
ldflags.each { |ldflag| append_ldflags(ldflag) }
99-
100-
append_cppflags("-DUSING_PACKAGED_LIBRARIES")
101-
append_cppflags("-DUSING_PRECOMPILED_LIBRARIES") if cross_build?
52+
ext_dir = File.dirname(__FILE__)
53+
Dir.chdir(ext_dir) do
54+
$srcs = Dir["*.c", "sqlite-amalgamation-3500200/sqlite3.c"]
55+
$hdrs = Dir["*.h", "sqlite-amalgamation-3500200/sqlite3.h"]
10256
end
57+
$INCFLAGS << " -I$(srcdir)/sqlite-amalgamation-3500200"
58+
$VPATH << "$(srcdir)/sqlite-amalgamation-3500200"
59+
60+
sqlite_cppflags = [
61+
# things set by upstream debian, just as a baseline. taken from
62+
# https://deb.debian.org/debian/pool/main/s/sqlite3/sqlite3_3.46.1-1.debian.tar.xz
63+
"-DSQLITE_SECURE_DELETE",
64+
"-DSQLITE_ENABLE_COLUMN_METADATA",
65+
"-DSQLITE_ENABLE_FTS3",
66+
"-DSQLITE_ENABLE_FTS3_PARENTHESIS",
67+
"-DSQLITE_ENABLE_RTREE=1",
68+
"-DSQLITE_SOUNDEX=1",
69+
"-DSQLITE_ENABLE_UNLOCK_NOTIFY",
70+
"-DSQLITE_ENABLE_DBSTAT_VTAB",
71+
"-DSQLITE_ALLOW_ROWID_IN_VIEW",
72+
"-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1",
73+
"-DSQLITE_ENABLE_LOAD_EXTENSION",
74+
"-DSQLITE_ENABLE_JSON1",
75+
"-DSQLITE_LIKE_DOESNT_MATCH_BLOBS",
76+
"-DSQLITE_THREADSAFE=1",
77+
"-DSQLITE_ENABLE_FTS3_TOKENIZER=1",
78+
"-DSQLITE_USE_URI=1",
79+
"-DSQLITE_MAX_SCHEMA_RETRY=25",
80+
"-DSQLITE_ENABLE_PREUPDATE_HOOK",
81+
"-DSQLITE_ENABLE_SESSION",
82+
"-DSQLITE_ENABLE_STMTVTAB",
83+
"-DSQLITE_STRICT_SUBTYPE=1",
84+
"-DSQLITE_MAX_VARIABLE_NUMBER=250000",
85+
86+
# were previously being added by the autoconf amalgamation's configure script
87+
"-D_REENTRANT=1",
88+
"-DSQLITE_THREADSAFE=1",
89+
"-DSQLITE_ENABLE_MATH_FUNCTIONS",
90+
"-DSQLITE_ENABLE_FTS4",
91+
"-DSQLITE_ENABLE_FTS5",
92+
"-DSQLITE_ENABLE_RTREE",
93+
"-DSQLITE_ENABLE_GEOPOLY",
94+
"-DSQLITE_HAVE_ZLIB",
95+
96+
# things we set in this gem in addition to the above
97+
"-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1",
98+
"-DSQLITE_ENABLE_DBPAGE_VTAB=1",
99+
"-DSQLITE_ENABLE_DBSTAT_VTAB=1"
100+
].join(" ")
101+
102+
append_cppflags(sqlite_cppflags)
103+
append_cppflags("-DUSING_PACKAGED_LIBRARIES")
104+
append_cppflags("-DUSING_PRECOMPILED_LIBRARIES") if cross_build?
103105
end
104106

105107
def configure_extension
@@ -144,32 +146,10 @@ def configure_extension
144146
have_type("sqlite3_uint64", "sqlite3.h")
145147
end
146148

147-
def minimal_recipe
148-
require "mini_portile2"
149-
150-
MiniPortile.new(libname, sqlite3_config[:version]).tap do |recipe|
151-
if sqlite_source_dir
152-
recipe.source_directory = sqlite_source_dir
153-
else
154-
recipe.files = sqlite3_config[:files]
155-
recipe.target = File.join(package_root_dir, "ports")
156-
recipe.patch_files = Dir[File.join(package_root_dir, "patches", "*.patch")].sort
157-
end
158-
end
159-
end
160-
161149
def package_root_dir
162150
File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
163151
end
164152

165-
def sqlite3_config
166-
mini_portile_config[:sqlite3]
167-
end
168-
169-
def mini_portile_config
170-
YAML.load_file(File.join(package_root_dir, "dependencies.yml"), symbolize_names: true)
171-
end
172-
173153
def abort_could_not_find(missing)
174154
abort("\nCould not find #{missing}.\nPlease visit https://github.com/sparklemotion/sqlite3-ruby for installation instructions.\n\n")
175155
end
@@ -279,6 +259,7 @@ def print_help
279259
end
280260
end
281261
end
262+
# rubocop:enable Style/GlobalVars
282263

283264
if arg_config("--help")
284265
Sqlite3::ExtConf.print_help

0 commit comments

Comments
 (0)