Skip to content

Commit

Permalink
Merge pull request #371 from sparklemotion/flavorjones-use-visibility…
Browse files Browse the repository at this point in the history
…-hidden-by-default

ext: export only Init_sqlite3_native
  • Loading branch information
flavorjones committed Jan 4, 2023
2 parents 1815290 + c8c1eb3 commit 52b3cf3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
21 changes: 6 additions & 15 deletions ext/sqlite3/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def configure_packaged_libraries
additional_cflags = [
"-fPIC", # needed for linking the static library into a shared library
"-O2", # see https://github.com/sparklemotion/sqlite3-ruby/issues/335 for some benchmarks
"-fvisibility=hidden", # see https://github.com/rake-compiler/rake-compiler-dock/issues/87
]
env["CFLAGS"] = [env["CFLAGS"], additional_cflags].flatten.join(" ")
recipe.configure_options += env.select { |k,v| ENV_ALLOWLIST.include?(k) }
Expand All @@ -81,14 +82,9 @@ def configure_packaged_libraries
abort_pkg_config("xpopen") unless $?.success?
ldflags = ldflags.split

if needs_darwin_linker_hack
ldflags.delete("-lsqlite3")
ldflags.prepend("-Wl,-flat_namespace", "-Wl,-hidden-lsqlite3")
else
# see https://github.com/flavorjones/mini_portile/issues/118
"-L#{lib_path}".tap do |lib_path_flag|
ldflags.prepend(lib_path_flag) unless ldflags.include?(lib_path_flag)
end
# see https://github.com/flavorjones/mini_portile/issues/118
"-L#{lib_path}".tap do |lib_path_flag|
ldflags.prepend(lib_path_flag) unless ldflags.include?(lib_path_flag)
end

ldflags.each { |ldflag| append_ldflags(ldflag) }
Expand All @@ -100,6 +96,8 @@ def configure_extension
append_cppflags("-DTAINTING_SUPPORT")
end

append_cflags("-fvisibility=hidden") # see https://github.com/rake-compiler/rake-compiler-dock/issues/87

if find_header("sqlite3.h")
# noop
elsif sqlcipher? && find_header("sqlcipher/sqlite3.h")
Expand Down Expand Up @@ -177,13 +175,6 @@ def download
minimal_recipe.download
end

def needs_darwin_linker_hack
# See https://github.com/rake-compiler/rake-compiler-dock/issues/87 for more info.
cross_build? &&
darwin? &&
RbConfig::CONFIG["ruby_version"] >= "3.2"
end

def darwin?
RbConfig::CONFIG["target_os"].include?("darwin")
end
Expand Down
1 change: 1 addition & 0 deletions ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void init_sqlite3_constants()
#endif
}

RUBY_FUNC_EXPORTED
void Init_sqlite3_native()
{
/*
Expand Down

0 comments on commit 52b3cf3

Please sign in to comment.