Skip to content

Instantly share code, notes, and snippets.

@gam0022
Last active December 26, 2015 07:09
Show Gist options
  • Save gam0022/7112650 to your computer and use it in GitHub Desktop.
Save gam0022/7112650 to your computer and use it in GitHub Desktop.
BundlerでC拡張を含んだgemを公開する ref: http://qiita.com/gam0022/items/2ee82e84e5c9f608eb85
require "mkmf"
create_makefile("immutable_list/immutable_list")
$ bundle gem immutable_list
create immutable_list/Gemfile
create immutable_list/Rakefile
create immutable_list/LICENSE.txt
create immutable_list/README.md
create immutable_list/.gitignore
create immutable_list/immutable_list.gemspec
create immutable_list/lib/immutable_list.rb
create immutable_list/lib/immutable_list/version.rb
Initializating git repo in /Users/gam0022/git/gem/t/immutable_list
ext
└── immutable_list
├── extconf.rb
└── immutable_list.c
lib
├── immutable_list
│   └── version.rb
└── immutable_list.rb
source 'https://rubygems.org'
# Specify your gem's dependencies in immutable_list.gemspec
gemspec
+gem "rake-compiler"
#include <stdio.h>
#include <ruby.h>
#define true 1
#define false 0
VALUE cImmutableList;
struct immutable_list {
VALUE value;
VALUE next;
};
static void
immutable_list_mark(struct immutable_list *ptr)
{
rb_gc_mark(ptr->value);
rb_gc_mark(ptr->next);
}
// 長すぎるので以下略。気になる人は以下を参照
// https://github.com/gam0022/immutable_list/blob/master/ext/immutable_list/immutable_list.c
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'immutable_list/version'
Gem::Specification.new do |spec|
spec.name = "immutable_list"
spec.version = ImmutableList::VERSION
spec.authors = ["gam0022"]
spec.email = ["[email protected]"]
- spec.description = %q{TODO: Write a gem description}
- spec.summary = %q{TODO: Write a gem summary}
+ spec.description = %q{Immutable Linked List implemented in C-Extensions}
+ spec.summary = %q{Immutable Linked List implemented in C-Extensions}
spec.homepage = ""
spec.license = "MIT"
+ spec.extensions = %w[ext/immutable_list/extconf.rb]
spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
end
require "immutable_list/version"
+require "immutable_list/immutable_list"
-module ImmutableList
+class ImmutableList
# Your code goes here...
end
require "bundler/gem_tasks"
+require "rake/extensiontask"
+
+Rake::ExtensionTask.new "immutable_list" do |ext|
+ ext.lib_dir = "lib/immutable_list"
+end
-module ImmutableList
+class ImmutableList
VERSION = "0.0.1"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment