rcee_packaged_source 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +82 -0
- data/Rakefile +4 -7
- data/lib/rcee/packaged_source/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0df51eb6ab06d9d2ba927b2fdd31012f176f52eaa9564c2f4f5727726ad5d28
|
4
|
+
data.tar.gz: 93967b78bc17354ca1375fd0375c541aab6b1317f9b677ecee3cefc7ab4a6ebb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccccd66db676cfbab807fede1d48e1fcf13ea988af7aada56f68160590e05b34949fb5fb6dd260c5ea4897b89e664bb207e885d50379bd651dbc995caf74cb15
|
7
|
+
data.tar.gz: 6490bb71e469eef7be4c8418b52b82397d84fcc85a62ea3ae3dc6bb388c41ac47be3d788f7767df757f65250d81b5c15c6baafe41a7b3545f0243e23a5a4cbff
|
data/README.md
CHANGED
@@ -1,2 +1,84 @@
|
|
1
|
+
# RCEE::PackagedSource
|
1
2
|
|
2
3
|
This gem is part of the Ruby C Extensions Explained project at https://github.com/flavorjones/ruby-c-extensions-explained
|
4
|
+
|
5
|
+
## Summary
|
6
|
+
|
7
|
+
Some gems, like nokogumbo and psych, include the third-party library's C files.
|
8
|
+
|
9
|
+
This means the gem is *redistributing* the library -- so be careful with licensing implications if you do this. Packaging third-party libraries is a little more work for gem maintainers to set up, but may simplify your codebase and make installation more reliable.
|
10
|
+
|
11
|
+
|
12
|
+
## Details
|
13
|
+
|
14
|
+
This gem has simply copied the source files from `libyaml`, along with that library's LICENSE file, into the extensions directory:
|
15
|
+
|
16
|
+
``` text
|
17
|
+
ext/
|
18
|
+
└── packaged_source
|
19
|
+
├── extconf.rb
|
20
|
+
├── packaged_source.c
|
21
|
+
├── packaged_source.h
|
22
|
+
└── yaml
|
23
|
+
├── LICENSE
|
24
|
+
├── api.c
|
25
|
+
├── config.h
|
26
|
+
├── dumper.c
|
27
|
+
├── emitter.c
|
28
|
+
├── loader.c
|
29
|
+
├── parser.c
|
30
|
+
├── reader.c
|
31
|
+
├── scanner.c
|
32
|
+
├── writer.c
|
33
|
+
├── yaml.h
|
34
|
+
└── yaml_private.h
|
35
|
+
```
|
36
|
+
|
37
|
+
The `extconf.rb` contains some new code:
|
38
|
+
|
39
|
+
``` ruby
|
40
|
+
$VPATH << "$(srcdir)/yaml"
|
41
|
+
$srcs = Dir.glob("#{$srcdir}/{,yaml/}*.c").map { |n| File.basename(n) }.sort
|
42
|
+
append_cppflags("-I$(srcdir)/yaml")
|
43
|
+
|
44
|
+
find_header("yaml.h")
|
45
|
+
have_header("config.h")
|
46
|
+
```
|
47
|
+
|
48
|
+
It first configures `MakeMakefile` to pay attention to the `./yaml` directory as well as the C and header files. It then verifies that `yaml.h` can be found (we could skip this since we're packing it and setting the include path manually). Finally, a libyaml-specific action is taken which is to make sure `config.h` can be found and that the `HAVE_CONFIG_H` macro is set so that `yaml.h` is compiled properly.
|
49
|
+
|
50
|
+
The `Makefile` recipe looks something like:
|
51
|
+
|
52
|
+
``` sh
|
53
|
+
# `create_makefile` recipe is something like this
|
54
|
+
|
55
|
+
# compile phase:
|
56
|
+
gcc -c -I/path/to/ruby/include -I/path/to/libyaml/include packaged_source.c -o packaged_source.o
|
57
|
+
gcc -c -I/path/to/ruby/include -I/path/to/libyaml/include yaml/api.c -o api.o
|
58
|
+
gcc -c -I/path/to/ruby/include -I/path/to/libyaml/include yaml/dumper.c -o dumper.o
|
59
|
+
gcc -c -I/path/to/ruby/include -I/path/to/libyaml/include yaml/emitter.c -o emitter.o
|
60
|
+
gcc -c -I/path/to/ruby/include -I/path/to/libyaml/include yaml/loader.c -o loader.o
|
61
|
+
gcc -c -I/path/to/ruby/include -I/path/to/libyaml/include yaml/parser.c -o parser.o
|
62
|
+
gcc -c -I/path/to/ruby/include -I/path/to/libyaml/include yaml/reader.c -o reader.o
|
63
|
+
gcc -c -I/path/to/ruby/include -I/path/to/libyaml/include yaml/scanner.c -o scanner.o
|
64
|
+
gcc -c -I/path/to/ruby/include -I/path/to/libyaml/include yaml/writer.c -o writer.o
|
65
|
+
|
66
|
+
# link phase:
|
67
|
+
gcc -shared \
|
68
|
+
-L/path/to/ruby/lib -lruby \
|
69
|
+
-lyaml \
|
70
|
+
-lc -lm \
|
71
|
+
packaged_source.o api.o dumper.o emitter.o loader.o parser.o reader.o scanner.o writer.o \
|
72
|
+
-o packaged_source.so
|
73
|
+
```
|
74
|
+
|
75
|
+
Now we're able to rely on a specific version of the library existing with known configuration, allowing us to avoid much real-world complexity in our `extconf.rb`, and our code.
|
76
|
+
|
77
|
+
|
78
|
+
## What Can Go Wrong
|
79
|
+
|
80
|
+
In addition to what's enumerated in `isolated`'s README ...
|
81
|
+
|
82
|
+
This strategy works pretty well for simple cases, but looking at the recipe, we can see that the libyaml code is being treated as if it were part of the Ruby C extension that we wrote. That's limiting, because the same compilation step must be shared across the extension code and the third-party library, and we need to be careful about filename collisions between the two filesets.
|
83
|
+
|
84
|
+
Maintainers now have an additional responsibility to keep that library up-to-date and secure for your users.
|
data/Rakefile
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "bundler/gem_tasks"
|
4
|
-
require "rake/testtask"
|
5
4
|
require "rubygems/package_task"
|
5
|
+
require "rake/testtask"
|
6
|
+
require "rake/extensiontask"
|
6
7
|
|
7
8
|
rcee_packaged_source_spec = Bundler.load_gemspec("rcee_packaged_source.gemspec")
|
8
9
|
Gem::PackageTask.new(rcee_packaged_source_spec).define
|
@@ -13,14 +14,10 @@ Rake::TestTask.new(:test) do |t|
|
|
13
14
|
t.test_files = FileList["test/**/*_test.rb"]
|
14
15
|
end
|
15
16
|
|
16
|
-
require "rake/extensiontask"
|
17
|
-
|
18
|
-
task build: :compile
|
19
|
-
|
20
17
|
Rake::ExtensionTask.new("packaged_source") do |ext|
|
21
18
|
ext.lib_dir = "lib/rcee/packaged_source"
|
22
19
|
end
|
23
20
|
|
24
|
-
task default:
|
21
|
+
task default: [:clobber, :compile, :test]
|
25
22
|
|
26
|
-
CLEAN.add("{ext,lib}/**/*.{o,so}")
|
23
|
+
CLEAN.add("{ext,lib}/**/*.{o,so}", "pkg")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcee_packaged_source
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Dalessio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Part of a project to explain how Ruby C extensions work.
|
14
14
|
email:
|
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
61
|
requirements: []
|
62
|
-
rubygems_version: 3.2.
|
62
|
+
rubygems_version: 3.2.22
|
63
63
|
signing_key:
|
64
64
|
specification_version: 4
|
65
65
|
summary: Example gem demonstrating a basic C extension.
|