rb_sys 0.1.3 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7755763e3f051172f51006a6687ebf6903b7398279616a870ef767fd40e1bb2a
4
- data.tar.gz: 738c78050d540fbcdba4f3574ce768ed0cb3a6edc19f1a1864808c3326f829af
3
+ metadata.gz: 27affe876fb5901792fe8af81776d7b6b6094b7b97849c1a8894296c6d119f77
4
+ data.tar.gz: a1e59e9580925d7d0a470ec33c72f4fe296148efacb546901d40b4fb99c543bf
5
5
  SHA512:
6
- metadata.gz: a2cbd1b6111a37dca8391436b38163c563c0e35f38c0a73f28314f0eb4fd5eabda17ce392b71c20e8e7bb1fc5619fcb8d6dd95443acb35a86ea2830869e90aa7
7
- data.tar.gz: d494ee43053464007c2ecbe7dffdf0acd0b908a8e4d3b5f4b607371472dd70e07c328fd56d692911446030b8e4c8e6fc8d7fd5ce891bb867afc582b969f89ae1
6
+ metadata.gz: acfa547f5b88a8274c384a6d72953b22eaf5c8b551092caac377a533d80160a1f9fb76dbdf09668957dbe016ed78b6c1e5bfd57bb0ccfaf1cbab85b675353046
7
+ data.tar.gz: c56ed902664615dd777a9611fcbe3b7ae2229a8832690c47b568340df9746278939fd82d3b05dea1c7b258116ce2deb59a1c30ac954b648ddb552b922e70eef8
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/rb_sys/mkmf.rb CHANGED
@@ -6,9 +6,29 @@ require_relative "./../../vendor/rubygems/ext/cargo_builder"
6
6
 
7
7
  # Root module
8
8
  module RbSys
9
- # Helpers for creating a Ruby compatible makefile for Rust
9
+ # Helper class for creating Rust Makefiles
10
10
  module Mkmf
11
- def create_rust_makefile(target, srcprefix = nil)
11
+ # Helper for building Rust extensions by creating a Ruby compatible makefile
12
+ # for Rust. By using this class, your rust extension will be 100% compatible
13
+ # with the rake-compiler gem, which allows for easy cross compilation.
14
+ #
15
+ # @example Basic
16
+ # require 'mkmf'
17
+ # . require 'rb_sys/mkmf'
18
+ #
19
+ # . create_rust_makefile("my_extension") #=> Generate a Makefile in the current directory
20
+ #
21
+ # @example Configure a custom build profile
22
+ # require 'mkmf'
23
+ # . require 'rb_sys/mkmf'
24
+ #
25
+ # . create_rust_makefile("my_extension") do |r|
26
+ # . # All of these are optional
27
+ # . r.env = { 'FOO' => 'bar' }
28
+ # . r.profile = ENV.fetch('CARGO_BUILD_PROFILE', :dev).to_sym
29
+ # . r.features = %w[some_cargo_feature]
30
+ # . end
31
+ def create_rust_makefile(target, srcprefix = nil, &blk)
12
32
  if target.include?("/")
13
33
  target_prefix, target = File.split(target)
14
34
  target_prefix[0, 0] = "/"
@@ -18,6 +38,9 @@ module RbSys
18
38
 
19
39
  spec = Struct.new(:name, :metadata).new(target, {})
20
40
  builder = Gem::Ext::CargoBuilder.new(spec)
41
+
42
+ yield builder if blk
43
+
21
44
  srcprefix ||= "$(srcdir)/#{srcprefix}".chomp("/")
22
45
  RbConfig.expand(srcdir = srcprefix.dup)
23
46
 
@@ -70,7 +93,19 @@ module RbSys
70
93
  end
71
94
 
72
95
  def env_vars(builder)
73
- builder.build_env.map { |k, v| %($(DLLIB): export #{k} = #{v.gsub("\n", '\n')}) }.join("\n")
96
+ lines = builder.build_env.map { |k, v| env_line(k, v) }
97
+ lines << env_line("CC", env_or_makefile_config("CC"))
98
+ lines << env_line("AR", env_or_makefile_config("AR")) unless env_or_makefile_config("AR") == "libtool -static"
99
+ lines.compact.join("\n")
100
+ end
101
+
102
+ def env_line(k, v)
103
+ return unless v
104
+ %($(DLLIB): export #{k} = #{v.gsub("\n", '\n')})
105
+ end
106
+
107
+ def env_or_makefile_config(key)
108
+ ENV[key] || RbConfig::MAKEFILE_CONFIG[key]
74
109
  end
75
110
 
76
111
  def dllib_path(builder)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RbSys
4
- VERSION = "0.1.3"
4
+ VERSION = "0.9.0"
5
5
  end
@@ -4,7 +4,7 @@
4
4
  # over the `cargo rustc` command which takes care of building Rust code in a way
5
5
  # that Ruby can use.
6
6
  class Gem::Ext::CargoBuilder < Gem::Ext::Builder
7
- attr_accessor :spec, :runner, :profile
7
+ attr_accessor :spec, :runner, :profile, :env, :features, :target, :extra_rustc_args
8
8
 
9
9
  def initialize(spec)
10
10
  require "rubygems/command"
@@ -12,7 +12,11 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder
12
12
 
13
13
  @spec = spec
14
14
  @runner = self.class.method(:run)
15
- @profile = :release
15
+ @profile = ENV.fetch("CARGO_BUILD_PROFILE", :release).to_sym
16
+ @env = {}
17
+ @features = []
18
+ @target = ENV['CARGO_BUILD_TARGET']
19
+ @extra_rustc_args = []
16
20
  end
17
21
 
18
22
  def build(_extension, dest_path, results, args = [], lib_dir = nil, cargo_dir = Dir.pwd)
@@ -37,7 +41,7 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder
37
41
  def build_env
38
42
  build_env = rb_config_env
39
43
  build_env["RUBY_STATIC"] = "true" if ruby_static? && ENV.key?("RUBY_STATIC")
40
- build_env
44
+ build_env.merge(env)
41
45
  end
42
46
 
43
47
  def cargo_command(cargo_dir, dest_path, args = [])
@@ -46,23 +50,25 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder
46
50
 
47
51
  cmd = []
48
52
  cmd += [cargo, "rustc"]
49
- cmd += ["--target", ENV["CARGO_BUILD_TARGET"]] if ENV["CARGO_BUILD_TARGET"]
53
+ cmd += ["--target", target] if target
50
54
  cmd += ["--target-dir", dest_path]
55
+ cmd += ["--features", features.join(",")] unless features.empty?
51
56
  cmd += ["--manifest-path", manifest]
52
57
  cmd += ["--lib"]
53
58
  cmd += ["--profile", profile.to_s]
54
- cmd += ["--locked"] if profile == :release
59
+ cmd += ["--locked"] if profile.to_s == 'release'
55
60
  cmd += Gem::Command.build_args
56
61
  cmd += args
57
62
  cmd += ["--"]
58
63
  cmd += [*cargo_rustc_args(dest_path)]
64
+ cmd += extra_rustc_args
59
65
  cmd
60
66
  end
61
67
 
62
68
  def cargo_dylib_path(dest_path)
63
69
  prefix = so_ext == "dll" ? "" : "lib"
64
70
  path_parts = [dest_path]
65
- path_parts << ENV["CARGO_BUILD_TARGET"] if ENV["CARGO_BUILD_TARGET"]
71
+ path_parts << target if target
66
72
  path_parts += [profile_target_directory, "#{prefix}#{cargo_crate_name}.#{so_ext}"]
67
73
  File.join(*path_parts)
68
74
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb_sys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Ker-Seymer
@@ -30,7 +30,7 @@ cert_chain:
30
30
  Rl+ASkq2/1i07TkBpCf+2hq66+h/hx+/Y/KrUzXfe0jtvil0WESkJT2kqRqHWNhD
31
31
  9GKBxaQlXokNDtWCm1/gl6cD8WRZ0N5S4ZGJT1FLLsA=
32
32
  -----END CERTIFICATE-----
33
- date: 2022-04-27 00:00:00.000000000 Z
33
+ date: 2022-05-25 00:00:00.000000000 Z
34
34
  dependencies: []
35
35
  description:
36
36
  email:
metadata.gz.sig CHANGED
Binary file