[ruby-core:81458] [Ruby trunk Feature#13570] Using mkmf for ruby/spec C API specs

From: Greg.mpls@...
Date: 2017-05-29 16:39:03 UTC
List: ruby-core #81458
Issue #13570 has been updated by MSP-Greg (Greg L).


Benoit,

Sorry, never set this to 'watch'.  I'll try a build with MinGW.

FWIW, I just got one of the spec c files to compile with only the following --

```ruby
require 'mkmf'
Dir.chdir('src/build-x86_64/spec/rubyspec/optional/capi/temp') { |d|
  append_ldflags('-L /e/GitHub/ruby-loco/src/build-x86_64')
  create_makefile("bignum_spec")
  puts `make`
  require_relative 'src/build-x86_64/spec/rubyspec/optional/capi/temp/bignum_spec.so'
  puts CApiBignumSpecs.instance_methods(false)
}
```

Output:

```
E:\GitHub\ruby-loco>ruby make_test.rb
checking for whether -L /e/GitHub/ruby-loco/src/build-x86_64 is accepted as LDFLAGS... yes
creating Makefile
generating bignum_spec-x64-mingw32.def
compiling bignum_spec.c
linking shared-object bignum_spec.so

rb_big_pack_array
rb_big_pack_length
rb_big2dbl
rb_dbl2big
rb_big2ll
rb_big2long
rb_big2str
rb_big2ulong
rb_big_cmp
rb_big_pack
```

For the test, I only copied `bignum_spec.c` to the temp folder, along with `rubyspec.h`.  I'm sure there's a setting to pick that up in `mkmf.rb`, along with several more that I'm probably missing.  Again, I'm not a c type...

----------------------------------------
Feature #13570: Using mkmf for ruby/spec C API specs
https://bugs.ruby-lang.org/issues/13570#change-65161

* Author: Eregon (Benoit Daloze)
* Status: Assigned
* Priority: Normal
* Assignee: cruby-windows
* Target version: 
----------------------------------------
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:

~~~ ruby
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)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next