1
0
Fork 0
mirror of https://github.com/rubyjs/mini_racer synced 2023-03-27 23:21:28 -04:00
mini_racer/ext/mini_racer_extension/extconf.rb
Sam Saffron e9b2adae10
extconf: add-fms-extensions for clang
The ruby/internal/attr/noreturn.h header of Ruby 3.0+ favors
using __has_declspec_attribute and __declspec(noreturn) over
other options (e.g. __attribute__((__noreturn__)) for gcc) i
available.

gcc (9.3.0) does not currently implement
__has_declspec_attribute and Ruby headers will use the
gcc-specific __attribute__((__noreturn__)).

clang (10.0.0) implements __has_declspec_attribute and Ruby
headers will favor use of __declspec, however __declspec itself
is only available via -fms-extensions or -fdeclspec in clang.

The -fms-extensions flag was chosen over -fdeclspec for
compatibility with gcc, as gcc only implements the former.
2021-12-03 15:53:30 +11:00

74 lines
2.1 KiB
Ruby

require 'mkmf'
require_relative '../../lib/mini_racer/version'
gem 'libv8-node', MiniRacer::LIBV8_NODE_VERSION
require 'libv8-node'
IS_DARWIN = RUBY_PLATFORM =~ /darwin/
have_library('pthread')
have_library('objc') if IS_DARWIN
$CPPFLAGS += " -Wall" unless $CPPFLAGS.split.include? "-Wall"
$CPPFLAGS += " -g" unless $CPPFLAGS.split.include? "-g"
$CPPFLAGS += " -rdynamic" unless $CPPFLAGS.split.include? "-rdynamic"
$CPPFLAGS += " -fPIC" unless $CPPFLAGS.split.include? "-rdynamic" or IS_DARWIN
$CPPFLAGS += " -std=c++14"
$CPPFLAGS += " -fpermissive"
#$CPPFLAGS += " -DV8_COMPRESS_POINTERS"
$CPPFLAGS += " -fvisibility=hidden "
# __declspec gets used by clang via ruby 3.x headers...
$CPPFLAGS += " -fms-extensions"
$CPPFLAGS += " -Wno-reserved-user-defined-literal" if IS_DARWIN
$LDFLAGS.insert(0, " -stdlib=libc++ ") if IS_DARWIN
# check for missing symbols at link time
# $LDFLAGS += " -Wl,--no-undefined " unless IS_DARWIN
# $LDFLAGS += " -Wl,-undefined,error " if IS_DARWIN
if ENV['CXX']
puts "SETTING CXX"
CONFIG['CXX'] = ENV['CXX']
end
CXX11_TEST = <<EOS
#if __cplusplus <= 199711L
# error A compiler that supports at least C++11 is required in order to compile this project.
#endif
EOS
`echo "#{CXX11_TEST}" | #{CONFIG['CXX']} -std=c++0x -x c++ -E -`
unless $?.success?
warn <<EOS
WARNING: C++11 support is required for compiling mini_racer. Please make sure
you are using a compiler that supports at least C++11. Examples of such
compilers are GCC 4.7+ and Clang 3.2+.
If you are using Travis, consider either migrating your build to Ubuntu Trusty or
installing GCC 4.8. See mini_racer's README.md for more information.
EOS
end
CONFIG['LDSHARED'] = '$(CXX) -shared' unless IS_DARWIN
if CONFIG['warnflags']
CONFIG['warnflags'].gsub!('-Wdeclaration-after-statement', '')
CONFIG['warnflags'].gsub!('-Wimplicit-function-declaration', '')
end
if enable_config('debug') || enable_config('asan')
CONFIG['debugflags'] << ' -ggdb3 -O0'
end
Libv8::Node.configure_makefile
if enable_config('asan')
$CPPFLAGS.insert(0, " -fsanitize=address ")
$LDFLAGS.insert(0, " -fsanitize=address ")
end
create_makefile 'mini_racer_extension'