rcee_precompiled 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b7b8a4b4b98b4d15ef9531671f6ad780fdac15003bef73acfcfd1a1a5487e388
4
+ data.tar.gz: 9fd162c2895075677fffb3ef8a3954906fa7162aee495679de6c5fd9e3d30b41
5
+ SHA512:
6
+ metadata.gz: d444b7e3384c0c1bce477582c3b7db9a038afb1b4b8af2d853129907f578fb3bec98e20b47205a5573dfd87c1f9a9abdf18907ab90c4db5adc6b441d4343a5be
7
+ data.tar.gz: 0c9616d7cd6208edbff6d833ded4f45fcfde378303fc01aa61f2617b01aa864c11bab63678740fbe97830b4da069ff1ae004359ff93a76dc3231d53e1aee9ebf
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.bundle
10
+ *.so
11
+ *.o
12
+ *.a
13
+ mkmf.log
14
+ ports
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in precompiled.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rake-compiler"
11
+ gem "rake-compiler-dock"
12
+
13
+ gem "minitest", "~> 5.0"
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+
2
+ This gem is part of the Ruby C Extensions Explained project at https://github.com/flavorjones/ruby-c-extensions-explained
data/Rakefile ADDED
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ rcee_precompiled_spec = Bundler.load_gemspec("rcee_precompiled.gemspec")
7
+
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << "test"
10
+ t.libs << "lib"
11
+ t.test_files = FileList["test/**/*_test.rb"]
12
+ end
13
+
14
+ # "gem" task for vanilla packaged (tarball)
15
+ require "rubygems/package_task"
16
+ Gem::PackageTask.new(rcee_precompiled_spec).define
17
+
18
+ require "rake/extensiontask"
19
+ require "rake_compiler_dock"
20
+
21
+ cross_rubies = ["3.0.0", "2.7.0", "2.6.0", "2.5.0"]
22
+ cross_platforms = ["x64-mingw32", "x86_64-linux", "x86_64-darwin", "arm64-darwin"]
23
+
24
+ ENV["RUBY_CC_VERSION"] = cross_rubies.join(":")
25
+
26
+
27
+ Rake::ExtensionTask.new("precompiled", rcee_precompiled_spec) do |ext|
28
+ ext.lib_dir = "lib/rcee/precompiled"
29
+ ext.cross_compile = true
30
+ ext.cross_platform = cross_platforms
31
+ ext.cross_config_options << "--enable-cross-build" # so extconf.rb knows we're cross-compiling
32
+ ext.cross_compiling do |spec|
33
+ # remove things not needed for precompiled gems
34
+ spec.dependencies.reject! { |dep| dep.name == 'mini_portile2' }
35
+ spec.files.reject! { |file| File.fnmatch?("*.tar.gz", file) }
36
+ end
37
+ end
38
+
39
+ namespace "gem" do
40
+ cross_platforms.each do |platform|
41
+ desc "build native gem for #{platform}"
42
+ task platform do
43
+ RakeCompilerDock.sh(<<~EOF, platform: platform)
44
+ gem install bundler --no-document &&
45
+ bundle &&
46
+ bundle exec rake gem:#{platform}:buildit
47
+ EOF
48
+ end
49
+
50
+ namespace platform do
51
+ # this runs in the rake-compiler-dock docker container
52
+ task "buildit" do
53
+ # use Task#invoke because the pkg/*gem task is defined at runtime
54
+ Rake::Task["native:#{platform}"].invoke
55
+ Rake::Task["pkg/#{rcee_precompiled_spec.full_name}-#{Gem::Platform.new(platform).to_s}.gem"].invoke
56
+ end
57
+ end
58
+ end
59
+
60
+ desc "build native gem for all platforms"
61
+ multitask "all" => [cross_platforms, "gem"].flatten
62
+ end
63
+
64
+
65
+ CLOBBER.add("ports")
66
+ CLEAN.add("{ext,lib}/**/*.{o,so}")
67
+
68
+ task build: :compile
69
+ task default: %i[clobber compile test]
@@ -0,0 +1,40 @@
1
+ require "mkmf"
2
+ require "mini_portile2"
3
+
4
+ package_root_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
5
+
6
+ RbConfig::CONFIG["CC"] = RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"]
7
+ ENV["CC"] = RbConfig::CONFIG["CC"]
8
+
9
+ # not needed for libyaml, but generally useful to know whether we're cross-compiling
10
+ cross_build_p = enable_config("cross-build")
11
+
12
+ MiniPortile.new("yaml", "0.2.5").tap do |recipe|
13
+ recipe.files = [{
14
+ url: "https://github.com/yaml/libyaml/releases/download/0.2.5/yaml-0.2.5.tar.gz",
15
+ sha256: "c642ae9b75fee120b2d96c712538bd2cf283228d2337df2cf2988e3c02678ef4",
16
+ }]
17
+ recipe.target = File.join(package_root_dir, "ports")
18
+
19
+ # configure the environment that MiniPortile will use for subshells
20
+ ENV.to_h.dup.tap do |env|
21
+ # -fPIC is necessary for linking into a shared library
22
+ env["CFLAGS"] = [env["CFLAGS"], "-fPIC"].join(" ")
23
+ env["SUBDIRS"] = "include src" # libyaml: skip tests
24
+
25
+ recipe.configure_options += env.map { |key, value| "#{key}=#{value.strip}" }
26
+ end
27
+
28
+ unless File.exist?(File.join(recipe.target, recipe.host, recipe.name, recipe.version))
29
+ recipe.cook
30
+ end
31
+
32
+ recipe.activate
33
+ pkg_config(File.join(recipe.path, "lib", "pkgconfig", "yaml-0.1.pc"))
34
+ end
35
+
36
+ unless have_library("yaml", "yaml_get_version", "yaml.h")
37
+ abort("\nERROR: *** could not find libyaml development environment ***\n\n")
38
+ end
39
+
40
+ create_makefile("rcee/precompiled/precompiled")
@@ -0,0 +1,25 @@
1
+ #include "precompiled.h"
2
+
3
+ VALUE rb_mRCEE;
4
+ VALUE rb_mPrecompiled;
5
+ VALUE rb_cPrecompiledExtension;
6
+
7
+ static VALUE
8
+ rb_precompiled_extension_class_do_something(VALUE self)
9
+ {
10
+ int major, minor, patch;
11
+
12
+ yaml_get_version(&major, &minor, &patch);
13
+
14
+ return rb_sprintf("libyaml version %d.%d.%d", major, minor, patch);
15
+ }
16
+
17
+ void
18
+ Init_precompiled(void)
19
+ {
20
+ rb_mRCEE = rb_define_module("RCEE");
21
+ rb_mPrecompiled = rb_define_module_under(rb_mRCEE, "Precompiled");
22
+ rb_cPrecompiledExtension = rb_define_class_under(rb_mPrecompiled, "Extension", rb_cObject);
23
+ rb_define_singleton_method(rb_cPrecompiledExtension, "do_something",
24
+ rb_precompiled_extension_class_do_something, 0);
25
+ }
@@ -0,0 +1,7 @@
1
+ #ifndef PRECOMPILED_H
2
+ #define PRECOMPILED_H 1
3
+
4
+ #include "ruby.h"
5
+ #include "yaml.h"
6
+
7
+ #endif /* PRECOMPILED_H */
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RCEE
4
+ module Precompiled
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "precompiled/version"
4
+
5
+ begin
6
+ # load the precompiled extension file
7
+ ruby_version = /(\d+\.\d+)/.match(::RUBY_VERSION)
8
+ require_relative "precompiled/#{ruby_version}/precompiled"
9
+ rescue LoadError
10
+ # fall back to the extension compiled upon installation.
11
+ # use "require" instead of "require_relative" because non-native gems will place C extension files
12
+ # in Gem::BasicSpecification#extension_dir after compilation (during normal installation), which
13
+ # is in $LOAD_PATH but not necessarily relative to this file
14
+ # (see https://github.com/sparklemotion/nokogiri/issues/2300 for more)
15
+ require "rcee/precompiled/precompiled"
16
+ end
17
+
18
+ module RCEE
19
+ module Precompiled
20
+ class Error < StandardError; end
21
+ # Your code goes here...
22
+ end
23
+ end
Binary file
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/rcee/precompiled/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rcee_precompiled"
7
+ spec.version = RCEE::Precompiled::VERSION
8
+ spec.authors = ["Mike Dalessio"]
9
+ spec.email = ["mike.dalessio@gmail.com"]
10
+
11
+ spec.summary = "Example gem demonstrating a basic C extension."
12
+ spec.description = "Part of a project to explain how Ruby C extensions work."
13
+ spec.homepage = "https://github.com/flavorjones/ruby-c-extensions-explained"
14
+ spec.required_ruby_version = ">= 2.5.0"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = [
20
+ ".gitignore",
21
+ "Gemfile",
22
+ "README.md",
23
+ "Rakefile",
24
+ "ext/precompiled/extconf.rb",
25
+ "ext/precompiled/precompiled.c",
26
+ "ext/precompiled/precompiled.h",
27
+ "lib/rcee/precompiled.rb",
28
+ "lib/rcee/precompiled/version.rb",
29
+ "ports/archives/yaml-0.2.5.tar.gz",
30
+ "rcee_precompiled.gemspec",
31
+ ]
32
+
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+ spec.extensions = ["ext/precompiled/extconf.rb"]
37
+
38
+ spec.add_dependency "mini_portile2"
39
+
40
+ # For more information and examples about making a new gem, checkout our
41
+ # guide at: https://bundler.io/guides/creating_gem.html
42
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rcee_precompiled
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Dalessio
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mini_portile2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Part of a project to explain how Ruby C extensions work.
28
+ email:
29
+ - mike.dalessio@gmail.com
30
+ executables: []
31
+ extensions:
32
+ - ext/precompiled/extconf.rb
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - README.md
38
+ - Rakefile
39
+ - ext/precompiled/extconf.rb
40
+ - ext/precompiled/precompiled.c
41
+ - ext/precompiled/precompiled.h
42
+ - lib/rcee/precompiled.rb
43
+ - lib/rcee/precompiled/version.rb
44
+ - ports/archives/yaml-0.2.5.tar.gz
45
+ - rcee_precompiled.gemspec
46
+ homepage: https://github.com/flavorjones/ruby-c-extensions-explained
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 2.5.0
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.2.15
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: Example gem demonstrating a basic C extension.
69
+ test_files: []