From a9c2d98c2dda6b6215e0512d64a68432cbd2d260 Mon Sep 17 00:00:00 2001 From: Barry Allard Date: Thu, 12 Jan 2023 01:38:16 -0600 Subject: [PATCH] Fix use of require_relative -> relative And, the `spec.extensions` setting from rb-sys Also, add a trivial C code example --- .../bundler/templates/newgem/ext/newgem/newgem.c.tt | 12 ++++++++++++ .../lib/bundler/templates/newgem/lib/newgem.rb.tt | 2 +- .../lib/bundler/templates/newgem/newgem.gemspec.tt | 5 +---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bundler/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt b/bundler/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt index 8177c4d20214..deb8dff153bf 100644 --- a/bundler/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +++ b/bundler/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt @@ -2,8 +2,20 @@ VALUE rb_m<%= config[:constant_array].join %>; +VALUE rb_<%= config[:constant_array].join %>_hello(VALUE self, VALUE str); + void Init_<%= config[:underscored_name] %>(void) { rb_m<%= config[:constant_array].join %> = rb_define_module(<%= config[:constant_name].inspect %>); + rb_define_singleton_method(rb_m<%= config[:constant_array].join %>, "hello", rb_<%= config[:constant_array].join %>_hello, 1); +} + +VALUE +rb_<%= config[:constant_array].join %>_hello(VALUE self, VALUE str) +{ + if (RB_TYPE_P(str, T_STRING) == 1) { + return rb_sprintf("Hello from C, %s!", StringValueCStr(str)); + } + return Qnil; } diff --git a/bundler/lib/bundler/templates/newgem/lib/newgem.rb.tt b/bundler/lib/bundler/templates/newgem/lib/newgem.rb.tt index caf6e32f4abf..3aedee0d25e9 100644 --- a/bundler/lib/bundler/templates/newgem/lib/newgem.rb.tt +++ b/bundler/lib/bundler/templates/newgem/lib/newgem.rb.tt @@ -2,7 +2,7 @@ require_relative "<%= File.basename(config[:namespaced_path]) %>/version" <%- if config[:ext] -%> -require_relative "<%= File.basename(config[:namespaced_path]) %>/<%= config[:underscored_name] %>" +require "<%= File.basename(config[:namespaced_path]) %>/<%= config[:underscored_name] %>" <%- end -%> <%- config[:constant_array].each_with_index do |c, i| -%> diff --git a/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt b/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt index e35a1212452c..539af2e2b78f 100644 --- a/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt +++ b/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt @@ -35,12 +35,9 @@ Gem::Specification.new do |spec| spec.bindir = "exe" spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] -<%- if config[:ext] == 'c' -%> +<%- if %w[c rust].include? config[:ext] -%> spec.extensions = ["ext/<%= config[:underscored_name] %>/extconf.rb"] <%- end -%> -<%- if config[:ext] == 'rust' -%> - spec.extensions = ["ext/<%= config[:underscored_name] %>/Cargo.toml"] -<%- end -%> # Uncomment to register a new dependency of your gem # spec.add_dependency "example-gem", "~> 1.0"