@@ -105,31 +105,52 @@ def asplode(lib)
105
105
'-Wno-missing-field-initializers' , # gperf generates bad code
106
106
'-Wno-missing-variable-declarations' , # missing symbols due to ruby native ext initialization
107
107
'-Wno-padded' , # mysql :(
108
+ '-Wno-reserved-id-macro' , # rubby :(
108
109
'-Wno-sign-conversion' , # gperf generates bad code
109
110
'-Wno-static-in-inline' , # gperf generates bad code
110
111
'-Wno-switch-enum' , # result.c -- enum_field_types (when not fully covered, e.g. mysql 5.6+)
111
112
'-Wno-undef' , # rubinius :(
113
+ '-Wno-unreachable-code' , # rubby :(
112
114
'-Wno-used-but-marked-unused' , # rubby :(
113
115
]
114
116
115
- if ENV [ 'CI' ]
116
- wishlist += [
117
- '-Werror' ,
118
- '-fsanitize=address' ,
119
- '-fsanitize=cfi' ,
120
- '-fsanitize=integer' ,
121
- '-fsanitize=memory' ,
122
- '-fsanitize=thread' ,
123
- '-fsanitize=undefined' ,
124
- ]
125
- end
126
-
127
117
usable_flags = wishlist . select do |flag |
128
- try_link ( 'int main() {return 0;}' , flag )
118
+ try_link ( 'int main() {return 0;}' , "-Werror -Wunknown-warning-option #{ flag } " )
129
119
end
130
120
131
121
$CFLAGS << ' ' << usable_flags . join ( ' ' )
132
122
123
+ enabled_sanitizers = disabled_sanitizers = [ ]
124
+ # Specify a commna-separated list of sanitizers, or try them all by default
125
+ sanitizers = with_config ( 'sanitize' )
126
+ case sanitizers
127
+ when true
128
+ # Try them all, turn on whatever we can
129
+ enabled_sanitizers = %w( address cfi integer memory thread undefined ) . select do |s |
130
+ try_link ( 'int main() {return 0;}' , "-Werror -Wunknown-warning-option -fsanitize=#{ s } " )
131
+ end
132
+ when String
133
+ # Figure out which sanitizers are supported
134
+ enabled_sanitizers , disabled_sanitizers = sanitizers . split ( ',' ) . partition do |s |
135
+ try_link ( 'int main() {return 0;}' , "-Werror -Wunknown-warning-option -fsanitize=#{ s } " )
136
+ end
137
+ end
138
+
139
+ unless disabled_sanitizers . empty?
140
+ abort "-----\n Could not enable requested sanitizers: #{ disabled_sanitizers . join ( ',' ) } \n -----"
141
+ end
142
+
143
+ unless enabled_sanitizers . empty?
144
+ warn "-----\n Enabling sanitizers: #{ enabled_sanitizers . join ( ',' ) } \n -----"
145
+ enabled_sanitizers . each do |s |
146
+ # address sanitizer requires runtime support
147
+ if s == 'address' # rubocop:disable Style/IfUnlessModifier
148
+ have_library ( 'asan' ) || $LDFLAGS << ' -fsanitize=address'
149
+ end
150
+ $CFLAGS << " -fsanitize=#{ s } "
151
+ end
152
+ end
153
+
133
154
if RUBY_PLATFORM =~ /mswin|mingw/
134
155
# Build libmysql.a interface link library
135
156
require 'rake'
@@ -155,8 +176,8 @@ def asplode(lib)
155
176
156
177
# Make sure the generated interface library works (if cross-compiling, trust without verifying)
157
178
unless RbConfig ::CONFIG [ 'host_os' ] =~ /mswin|mingw/
158
- abort "-----\n Cannot find libmysql.a\n ----" unless have_library ( 'libmysql' )
159
- abort "-----\n Cannot link to libmysql.a (my_init)\n ----" unless have_func ( 'my_init' )
179
+ abort "-----\n Cannot find libmysql.a\n ----- " unless have_library ( 'libmysql' )
180
+ abort "-----\n Cannot link to libmysql.a (my_init)\n ----- " unless have_func ( 'my_init' )
160
181
end
161
182
162
183
# Vendor libmysql.dll
0 commit comments