Top Level Namespace
Defined Under Namespace
Modules: Aws
Constant Summary collapse
- OS_BINARIES =
Maps OS name to crt binary name.
{ 'darwin' => 'libaws-crt-ffi.dylib', 'linux' => 'libaws-crt-ffi.so', 'mingw32' => 'aws-crt-ffi.dll' }.freeze
- DEFAULT_BINARY =
'libaws-crt-ffi.so'
- CMAKE_PATH =
find_executable('cmake3') || find_executable('cmake')
- CMAKE =
File.basename(CMAKE_PATH)
- CMAKE_VERSION =
cmake_version
Instance Method Summary collapse
-
#cmake_has_parallel_flag? ⇒ Boolean
whether installed cmake supports –parallel build flag.
- #cmake_version ⇒ Object
-
#compile_bin ⇒ Object
Compile bin to expected location.
-
#crt_bin_dir(platform) ⇒ String
Return the directory of the CRT library for the platform.
-
#crt_bin_name(platform) ⇒ String
Return the file name for the CRT library for the platform.
-
#crt_bin_path(platform) ⇒ String
Return the path to the CRT library for the platform.
- #find_file(name, search_dirs, base_dir) ⇒ Object
-
#host_cpu ⇒ String
Host cpu, even on jruby.
-
#host_os ⇒ String
Host os, even on jruby.
-
#host_string ⇒ String
Generate a string that be used with Gem::Platform.
-
#local_platform ⇒ String
similar to Gem::Platform.local but will return systems host os/cpu for Jruby.
- #run_cmd(args) ⇒ Object
Instance Method Details
#cmake_has_parallel_flag? ⇒ Boolean
whether installed cmake supports –parallel build flag
22 23 24 |
# File 'ext/compile.rb', line 22 def cmake_has_parallel_flag? (CMAKE_VERSION <=> [3, 12]) >= 0 end |
#cmake_version ⇒ Object
13 14 15 16 17 |
# File 'ext/compile.rb', line 13 def cmake_version version_str = `#{CMAKE} --version` match = /(\d+)\.(\d+)\.(\d+)/.match(version_str) [match[1].to_i, match[2].to_i, match[3].to_i] end |
#compile_bin ⇒ Object
Compile bin to expected location
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'ext/compile.rb', line 44 def compile_bin platform = local_platform native_dir = File.('../aws-crt-ffi', File.dirname(__FILE__)) tmp_build_dir = File.('../tmp/build', File.dirname(__FILE__)) # We need cmake to "install" aws-crt-ffi so that the binaries end up in a # predictable location. But cmake still adds subdirectories we don't want, # so we'll "install" under tmp, and manually copy to bin/ after that. tmp_install_dir = File.('../tmp/install', File.dirname(__FILE__)) build_type = 'RelWithDebInfo' config_cmd = [ CMAKE, "-H#{native_dir}", "-B#{tmp_build_dir}", "-DCMAKE_INSTALL_PREFIX=#{tmp_install_dir}", "-DCMAKE_BUILD_TYPE=#{build_type}", ] build_cmd = [ CMAKE, '--build', tmp_build_dir, '--target', 'install', '--config', build_type, ] # Build using all processors if cmake_has_parallel_flag? build_cmd.append('--parallel') build_cmd.append(Etc.nprocessors.to_s) end run_cmd(config_cmd) run_cmd(build_cmd) # Move file to bin/, instead of where cmake installed it under tmp/ bin_dir = crt_bin_dir(platform) FileUtils.mkdir_p(bin_dir) bin_name = crt_bin_name(platform) search_dirs = [ 'bin', # windows 'lib64', # some 64bit unix variants 'lib', # some unix variants ] tmp_path = find_file(bin_name, search_dirs, tmp_install_dir) FileUtils.cp(tmp_path, bin_dir) end |
#crt_bin_dir(platform) ⇒ String
Return the directory of the CRT library for the platform
25 26 27 |
# File 'lib/aws-crt/platforms.rb', line 25 def crt_bin_dir(platform) File.("../../bin/#{platform.cpu}", File.dirname(__FILE__)) end |
#crt_bin_name(platform) ⇒ String
Return the file name for the CRT library for the platform
20 21 22 |
# File 'lib/aws-crt/platforms.rb', line 20 def crt_bin_name(platform) OS_BINARIES[platform.os] || DEFAULT_BINARY end |
#crt_bin_path(platform) ⇒ String
Return the path to the CRT library for the platform
30 31 32 |
# File 'lib/aws-crt/platforms.rb', line 30 def crt_bin_path(platform) File.(crt_bin_name(platform), crt_bin_dir(platform)) end |
#find_file(name, search_dirs, base_dir) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'ext/compile.rb', line 34 def find_file(name, search_dirs, base_dir) search_dirs.each do |search_dir| dir = File.(search_dir, base_dir) file_path = File.(name, dir) return file_path if File.exist?(file_path) end raise "Cannot find #{name}" end |
#host_cpu ⇒ String
Returns host cpu, even on jruby.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/aws-crt/platforms.rb', line 40 def host_cpu case RbConfig::CONFIG['host_cpu'] when /86_64/ 'x86_64' when /86/ 'x86' else RbConfig::CONFIG['host_cpu'] end end |
#host_os ⇒ String
Returns host os, even on jruby.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/aws-crt/platforms.rb', line 52 def host_os case RbConfig::CONFIG['host_os'] when /darwin/ 'darwin' when /linux/ 'linux' when /mingw|mswin/ 'mingw32' else RbConfig::CONFIG['host_os'] end end |
#host_string ⇒ String
Returns generate a string that be used with Gem::Platform.
35 36 37 |
# File 'lib/aws-crt/platforms.rb', line 35 def host_string "#{host_cpu}-#{host_os}" end |
#local_platform ⇒ String
similar to Gem::Platform.local but will return systems host os/cpu for Jruby
15 16 17 |
# File 'lib/aws-crt/platforms.rb', line 15 def local_platform Gem::Platform.new(host_string) end |
#run_cmd(args) ⇒ Object
26 27 28 29 30 31 32 |
# File 'ext/compile.rb', line 26 def run_cmd(args) # use shellwords.join() for printing, don't pass that string to system(). # system() does better cross-platform when the args array is passed in. cmd_str = Shellwords.join(args) puts cmd_str system(*args) || raise("Error running: #{cmd_str}") end |