From b40f120f908f5774473554522660cea329013f3b Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Fri, 24 Mar 2023 14:30:19 +0100 Subject: [PATCH] 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. --- .../lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt | 2 ++ bundler/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt | 2 +- bundler/lib/bundler/templates/newgem/rubocop.yml.tt | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bundler/lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt b/bundler/lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt index e918063ddf68..1399b1ae719d 100644 --- a/bundler/lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt +++ b/bundler/lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt @@ -2,4 +2,6 @@ require "mkmf" +$CFLAGS << " -fvisibility=hidden " + create_makefile(<%= config[:makefile_path].inspect %>) diff --git a/bundler/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt b/bundler/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt index 8177c4d20214..bcd5148569ea 100644 --- a/bundler/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +++ b/bundler/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/bundler/lib/bundler/templates/newgem/rubocop.yml.tt b/bundler/lib/bundler/templates/newgem/rubocop.yml.tt index 9ecec788075a..4845a67bd569 100644 --- a/bundler/lib/bundler/templates/newgem/rubocop.yml.tt +++ b/bundler/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