summaryrefslogtreecommitdiff
path: root/lib/bundler/templates
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2023-03-24 14:30:19 +0100
committergit <svn-admin@ruby-lang.org>2023-03-25 00:31:46 +0000
commit276f4be96df08becfc59ef253025c2e5f19718fa (patch)
tree7d9046ad92eaa79549ea877ddacfebc0794f8bb2 /lib/bundler/templates
parentc08fe408722d28daebaa62f0b820147b0d66986f (diff)
[rubygems/rubygems] Generate native gems with `-fvisibility=hidden`
I recently ran into very nasty issues with dynamic symbols clashing between two native gems. I believe the overwhelming majority of native gems don't want to export their symbols, so hidding them by default would make sense to me. https://github.com/rubygems/rubygems/commit/449624aa54
Diffstat (limited to 'lib/bundler/templates')
-rw-r--r--lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt5
-rw-r--r--lib/bundler/templates/newgem/ext/newgem/newgem.c.tt2
-rw-r--r--lib/bundler/templates/newgem/rubocop.yml.tt4
3 files changed, 10 insertions, 1 deletions
diff --git a/lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt b/lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt
index e918063ddf..49764e9931 100644
--- a/lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt
+++ b/lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt
@@ -2,4 +2,9 @@
require "mkmf"
+# Makes all symbols private by default to avoid unintended conflict
+# with other gems. To explicitly export symbols you can use RUBY_FUNC_EXPORTED
+# selectively, or entirely remove this flag.
+$CFLAGS << " -fvisibility=hidden "
+
create_makefile(<%= config[:makefile_path].inspect %>)
diff --git a/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt b/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt
index 8177c4d202..bcd5148569 100644
--- a/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt
+++ b/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt
@@ -2,7 +2,7 @@
VALUE rb_m<%= config[:constant_array].join %>;
-void
+RUBY_FUNC_EXPORTED void
Init_<%= config[:underscored_name] %>(void)
{
rb_m<%= config[:constant_array].join %> = rb_define_module(<%= config[:constant_name].inspect %>);
diff --git a/lib/bundler/templates/newgem/rubocop.yml.tt b/lib/bundler/templates/newgem/rubocop.yml.tt
index 9ecec78807..4845a67bd5 100644
--- a/lib/bundler/templates/newgem/rubocop.yml.tt
+++ b/lib/bundler/templates/newgem/rubocop.yml.tt
@@ -9,5 +9,9 @@ Style/StringLiteralsInInterpolation:
Enabled: true
EnforcedStyle: double_quotes
+Style/GlobalVars:
+ Exclude:
+ - ext/**/extconf.rb
+
Layout/LineLength:
Max: 120