Module: RbSys::Mkmf
- Defined in:
- lib/rb_sys/mkmf.rb
Overview
Helpers for creating a Ruby compatible makefile for Rust
Instance Method Summary collapse
Instance Method Details
#create_rust_makefile(target, srcprefix = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rb_sys/mkmf.rb', line 11 def create_rust_makefile(target, srcprefix = nil) if target.include?("/") target_prefix, target = File.split(target) target_prefix[0, 0] = "/" else target_prefix = "" end spec = Struct.new(:name, :metadata).new(target, {}) builder = Gem::Ext::CargoBuilder.new(spec) srcprefix ||= "$(srcdir)/#{srcprefix}".chomp("/") RbConfig.(srcdir = srcprefix.dup) # rubocop:disable Style/GlobalVars make_install = <<~MAKE target_prefix = #{target_prefix} CARGO_PROFILE = release CLEANLIBS = target/ $(RUSTLIB) $(DLLIB) RUBYARCHDIR = $(sitearchdir)$(target_prefix) RUSTLIB = #{dllib_path(builder)} TARGET = #{target} DLLIB = $(TARGET).#{RbConfig::CONFIG["DLEXT"]} #{base_makefile(srcdir)} #{env_vars(builder)} FORCE: ; $(DLLIB): FORCE \t#{cargo_command(srcdir, builder)} \t$(COPY) "$(RUSTLIB)" $@ install: $(DLLIB) \t$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR) all: #{$extout ? "install" : "$(DLLIB)"} MAKE File.write("Makefile", make_install) end |