Project

General

Profile

Actions

Feature #13570

closed

Using mkmf for ruby/spec C API specs

Added by Eregon (Benoit Daloze) almost 7 years ago. Updated about 5 years ago.

Status:
Closed
Assignee:
Target version:
-
[ruby-core:81199]

Description

Hello all,

I am thinking to use mkmf to compile the C API specs.

https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/optional/capi/spec_helper.rb
is getting pretty complex and hard to maintain.

I have a few questions:

  • Does mkmf works well on Windows?
  • What is a good way to compile a single .c file with mkmf to a given library file in another directory?

I tried this but I am not sure it's correct:

def compile_extension(name)
  objdir = object_path
  ext = "#{name}_spec"
  lib = "#{objdir}/#{ext}.#{RbConfig::CONFIG['DLEXT']}"

  require 'mkmf' # TODO: probably best to use a subprocess to avoid polluting the namespace
  Dir.chdir(objdir) do
    $srcs = ["#{extension_path}/#{ext}.c"]
    $objs = ["#{extension_path}/#{ext}.o"] # should probably be in objdir but that does not seem to work
    create_makefile(ext)
    system "make"
  end

  lib
end

Alternatively, we can copy the needed files to a temporary directory, build there and copy the shared library back.
It's a bit more work but not a big deal either.


Files

spec_helper.rb (2.22 KB) spec_helper.rb Eregon (Benoit Daloze), 05/29/2017 03:28 PM
spec_helper.rb (2.24 KB) spec_helper.rb New spec_helper handling ruby 2.2 to trunk on Linux Eregon (Benoit Daloze), 06/02/2017 09:14 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #13611: MinGW spec/rubyspec/optional/capi compile/link issuesRejectedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0