graaf 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +8 -0
- data/CHANGELOG.md +3 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Dockerfile +32 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +146 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +63 -0
- data/Steepfile +8 -0
- data/docker-compose.yml +8 -0
- data/exe/graaf +13 -0
- data/lib/graaf/builder.rb +56 -0
- data/lib/graaf/create_isolate_params.rb +8 -0
- data/lib/graaf/library.rb +86 -0
- data/lib/graaf/version.rb +6 -0
- data/lib/graaf.rb +17 -0
- data/rbs_collection.lock.yaml +14 -0
- data/rbs_collection.yaml +21 -0
- data/sig/graaf.rbs +57 -0
- data/sig_private/ffi.rbs +30 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4a093897a513f24deb680564244b440ad3d910c28c2e8a3d492944b1cda7060f
|
4
|
+
data.tar.gz: 68c805a6696b2724244234ba9b7fabf2a896d385efe9a6a3781460b0abaabf20
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bbf42c7da24d537ccb5ec61d410d0dfc8c91e0e2fcef77506a04668bac6e164ced8cde1ced34e23cc861df927b83116460b1f01e5a547b7a6ad572473cb5045f
|
7
|
+
data.tar.gz: 4c1ab045f54c6f93de84bc469695e09c6eb6b7e67633436cfe7f1b1236dda4c5f1ffe6757e5c28ff1926c34f7eff4fc44017d4cbb8ac3f357e8b349138cfb795
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at 23730734+shoma07@users.noreply.github.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Dockerfile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
FROM ruby:3.2.2
|
2
|
+
|
3
|
+
ARG GRAALVM_PATH=/opt/graalvm-jdk
|
4
|
+
ARG JAVA_VERSION=21
|
5
|
+
|
6
|
+
RUN set -eu && \
|
7
|
+
apt-get update -y && \
|
8
|
+
apt-get install -y --no-install-recommends \
|
9
|
+
build-essential \
|
10
|
+
git \
|
11
|
+
curl \
|
12
|
+
&& \
|
13
|
+
apt-get clean && \
|
14
|
+
rm -rf /var/lib/apt/lists/* && \
|
15
|
+
mkdir -p ${GRAALVM_PATH} && \
|
16
|
+
curl -L https://download.oracle.com/graalvm/${JAVA_VERSION}/latest/graalvm-jdk-${JAVA_VERSION}_linux-$(arch)_bin.tar.gz | \
|
17
|
+
tar zx -C ${GRAALVM_PATH} --strip-components 1
|
18
|
+
|
19
|
+
ENV JAVA_HOME=$GRAALVM_PATH \
|
20
|
+
PATH=$GRAALVM_PATH/bin:$PATH
|
21
|
+
|
22
|
+
WORKDIR /usr/src/gem
|
23
|
+
|
24
|
+
RUN set -eu \
|
25
|
+
&& mkdir -p lib/graaf \
|
26
|
+
&& echo "module Graaf\n VERSION = \"0.1.0\"\nend\n" > lib/graaf/version.rb
|
27
|
+
|
28
|
+
COPY bin/setup ./bin/
|
29
|
+
COPY Gemfile Gemfile.lock graaf.gemspec ./
|
30
|
+
|
31
|
+
RUN set -eu \
|
32
|
+
&& bin/setup
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in graaf.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'ffi'
|
9
|
+
gem 'rake'
|
10
|
+
gem 'rspec', require: false
|
11
|
+
gem 'rubocop', require: false
|
12
|
+
gem 'rubocop-performance', require: false
|
13
|
+
gem 'rubocop-rake', require: false
|
14
|
+
gem 'rubocop-rspec', require: false
|
15
|
+
gem 'rubocop-thread_safety', require: false
|
16
|
+
gem 'simplecov', require: false
|
17
|
+
gem 'steep', require: false
|
18
|
+
gem 'yard', require: false
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
graaf (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (7.1.0)
|
10
|
+
base64
|
11
|
+
bigdecimal
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
connection_pool (>= 2.2.5)
|
14
|
+
drb
|
15
|
+
i18n (>= 1.6, < 2)
|
16
|
+
minitest (>= 5.1)
|
17
|
+
mutex_m
|
18
|
+
tzinfo (~> 2.0)
|
19
|
+
ast (2.4.2)
|
20
|
+
base64 (0.1.1)
|
21
|
+
bigdecimal (3.1.4)
|
22
|
+
concurrent-ruby (1.2.2)
|
23
|
+
connection_pool (2.4.1)
|
24
|
+
csv (3.2.7)
|
25
|
+
diff-lcs (1.5.0)
|
26
|
+
docile (1.4.0)
|
27
|
+
drb (2.1.1)
|
28
|
+
ruby2_keywords
|
29
|
+
ffi (1.16.3)
|
30
|
+
fileutils (1.7.1)
|
31
|
+
i18n (1.14.1)
|
32
|
+
concurrent-ruby (~> 1.0)
|
33
|
+
json (2.6.3)
|
34
|
+
language_server-protocol (3.17.0.3)
|
35
|
+
listen (3.8.0)
|
36
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
37
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
38
|
+
logger (1.5.3)
|
39
|
+
minitest (5.20.0)
|
40
|
+
mutex_m (0.1.2)
|
41
|
+
parallel (1.23.0)
|
42
|
+
parser (3.2.2.4)
|
43
|
+
ast (~> 2.4.1)
|
44
|
+
racc
|
45
|
+
racc (1.7.1)
|
46
|
+
rainbow (3.1.1)
|
47
|
+
rake (13.0.6)
|
48
|
+
rb-fsevent (0.11.2)
|
49
|
+
rb-inotify (0.10.1)
|
50
|
+
ffi (~> 1.0)
|
51
|
+
rbs (3.2.2)
|
52
|
+
regexp_parser (2.8.1)
|
53
|
+
rexml (3.2.6)
|
54
|
+
rspec (3.12.0)
|
55
|
+
rspec-core (~> 3.12.0)
|
56
|
+
rspec-expectations (~> 3.12.0)
|
57
|
+
rspec-mocks (~> 3.12.0)
|
58
|
+
rspec-core (3.12.2)
|
59
|
+
rspec-support (~> 3.12.0)
|
60
|
+
rspec-expectations (3.12.3)
|
61
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
+
rspec-support (~> 3.12.0)
|
63
|
+
rspec-mocks (3.12.6)
|
64
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
+
rspec-support (~> 3.12.0)
|
66
|
+
rspec-support (3.12.1)
|
67
|
+
rubocop (1.56.4)
|
68
|
+
base64 (~> 0.1.1)
|
69
|
+
json (~> 2.3)
|
70
|
+
language_server-protocol (>= 3.17.0)
|
71
|
+
parallel (~> 1.10)
|
72
|
+
parser (>= 3.2.2.3)
|
73
|
+
rainbow (>= 2.2.2, < 4.0)
|
74
|
+
regexp_parser (>= 1.8, < 3.0)
|
75
|
+
rexml (>= 3.2.5, < 4.0)
|
76
|
+
rubocop-ast (>= 1.28.1, < 2.0)
|
77
|
+
ruby-progressbar (~> 1.7)
|
78
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
79
|
+
rubocop-ast (1.29.0)
|
80
|
+
parser (>= 3.2.1.0)
|
81
|
+
rubocop-capybara (2.19.0)
|
82
|
+
rubocop (~> 1.41)
|
83
|
+
rubocop-factory_bot (2.24.0)
|
84
|
+
rubocop (~> 1.33)
|
85
|
+
rubocop-performance (1.19.1)
|
86
|
+
rubocop (>= 1.7.0, < 2.0)
|
87
|
+
rubocop-ast (>= 0.4.0)
|
88
|
+
rubocop-rake (0.6.0)
|
89
|
+
rubocop (~> 1.0)
|
90
|
+
rubocop-rspec (2.24.1)
|
91
|
+
rubocop (~> 1.33)
|
92
|
+
rubocop-capybara (~> 2.17)
|
93
|
+
rubocop-factory_bot (~> 2.22)
|
94
|
+
rubocop-thread_safety (0.5.1)
|
95
|
+
rubocop (>= 0.90.0)
|
96
|
+
ruby-progressbar (1.13.0)
|
97
|
+
ruby2_keywords (0.0.5)
|
98
|
+
securerandom (0.2.2)
|
99
|
+
simplecov (0.22.0)
|
100
|
+
docile (~> 1.1)
|
101
|
+
simplecov-html (~> 0.11)
|
102
|
+
simplecov_json_formatter (~> 0.1)
|
103
|
+
simplecov-html (0.12.3)
|
104
|
+
simplecov_json_formatter (0.1.4)
|
105
|
+
steep (1.5.3)
|
106
|
+
activesupport (>= 5.1)
|
107
|
+
concurrent-ruby (>= 1.1.10)
|
108
|
+
csv (>= 3.0.9)
|
109
|
+
fileutils (>= 1.1.0)
|
110
|
+
json (>= 2.1.0)
|
111
|
+
language_server-protocol (>= 3.15, < 4.0)
|
112
|
+
listen (~> 3.0)
|
113
|
+
logger (>= 1.3.0)
|
114
|
+
parser (>= 3.1)
|
115
|
+
rainbow (>= 2.2.2, < 4.0)
|
116
|
+
rbs (>= 3.1.0)
|
117
|
+
securerandom (>= 0.1)
|
118
|
+
strscan (>= 1.0.0)
|
119
|
+
terminal-table (>= 2, < 4)
|
120
|
+
strscan (3.0.6)
|
121
|
+
terminal-table (3.0.2)
|
122
|
+
unicode-display_width (>= 1.1.1, < 3)
|
123
|
+
tzinfo (2.0.6)
|
124
|
+
concurrent-ruby (~> 1.0)
|
125
|
+
unicode-display_width (2.5.0)
|
126
|
+
yard (0.9.34)
|
127
|
+
|
128
|
+
PLATFORMS
|
129
|
+
aarch64-linux
|
130
|
+
|
131
|
+
DEPENDENCIES
|
132
|
+
ffi
|
133
|
+
graaf!
|
134
|
+
rake
|
135
|
+
rspec
|
136
|
+
rubocop
|
137
|
+
rubocop-performance
|
138
|
+
rubocop-rake
|
139
|
+
rubocop-rspec
|
140
|
+
rubocop-thread_safety
|
141
|
+
simplecov
|
142
|
+
steep
|
143
|
+
yard
|
144
|
+
|
145
|
+
BUNDLED WITH
|
146
|
+
2.4.10
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 shoma07
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Graaf
|
2
|
+
|
3
|
+
Ruby FFI for Built a Shared Library by GraalVM Native Image
|
4
|
+
|
5
|
+
## Motivation
|
6
|
+
|
7
|
+
Using a Shared Library built with GraalVM Native Image requires built-in control over `IsolateThread`.
|
8
|
+
|
9
|
+
This gem manages the control of `IsolateThread`.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Install the gem and add to the application's Gemfile by executing:
|
14
|
+
|
15
|
+
$ bundle add graaf
|
16
|
+
|
17
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
18
|
+
|
19
|
+
$ gem install graaf
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
module Example
|
25
|
+
extend Graaf::Library
|
26
|
+
|
27
|
+
graaf_lib('libexample.so')
|
28
|
+
|
29
|
+
# @note
|
30
|
+
# The first argument `graal_isolatethread_t*` does not need to be specified.
|
31
|
+
graaf_attach_function :add, [:int, :int], :int
|
32
|
+
end
|
33
|
+
|
34
|
+
Example.add(1, 2)
|
35
|
+
# => 3
|
36
|
+
```
|
37
|
+
|
38
|
+
## Development
|
39
|
+
|
40
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
41
|
+
|
42
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/graaf_rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/graaf_rb/blob/main/CODE_OF_CONDUCT.md).
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
51
|
+
|
52
|
+
## Code of Conduct
|
53
|
+
|
54
|
+
Everyone interacting in the Graaf project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/graaf_rb/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
# rubocop
|
9
|
+
require 'rubocop/rake_task'
|
10
|
+
RuboCop::RakeTask.new(:lint) do |t|
|
11
|
+
t.options = %w[--parallel]
|
12
|
+
end
|
13
|
+
namespace :lint do
|
14
|
+
desc 'Lint fix (Rubocop)'
|
15
|
+
task fix: :autocorrect
|
16
|
+
|
17
|
+
namespace :fix do
|
18
|
+
desc 'Lint fix all (Rubocop)'
|
19
|
+
task all: :autocorrect_all
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# steep
|
24
|
+
# @see https://github.com/soutaro/steep/blob/master/exe/steep
|
25
|
+
require 'rbs'
|
26
|
+
require 'rbs/cli'
|
27
|
+
require 'steep'
|
28
|
+
require 'steep/cli'
|
29
|
+
desc 'Typecheck (Steep)'
|
30
|
+
task :typecheck do
|
31
|
+
Steep::CLI.new(
|
32
|
+
argv: %w[check -j4], stdout: $stdout, stderr: $stderr, stdin: $stdin
|
33
|
+
).run.zero? || exit(1)
|
34
|
+
end
|
35
|
+
|
36
|
+
namespace :typecheck do
|
37
|
+
desc 'Install RBS Collection'
|
38
|
+
task :install do
|
39
|
+
RBS::CLI.new(stdout: $stdout, stderr: $stderr).run('collection install --frozen'.split)
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'Update RBS Collection'
|
43
|
+
task :update do
|
44
|
+
RBS::CLI.new(stdout: $stdout, stderr: $stderr).run('collection update'.split)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# yard
|
49
|
+
require 'yard'
|
50
|
+
## custom rake task
|
51
|
+
desc 'Generate and Check code documents'
|
52
|
+
task :doc do
|
53
|
+
# @note hack yard logger
|
54
|
+
# @see https://github.com/lsegal/yard/blob/92b9b7c/lib/yard/logging.rb#L38-L40
|
55
|
+
io = StringIO.new
|
56
|
+
YARD::Logger.instance(io)
|
57
|
+
YARD::CLI::CommandParser.run(*%w[stats --list-undoc])
|
58
|
+
result = io.tap(&:rewind).read
|
59
|
+
$stdout.puts(result)
|
60
|
+
result.lines(chomp: true).last.strip == '100.00% documented' || exit(1)
|
61
|
+
end
|
62
|
+
|
63
|
+
task default: %i[lint typecheck doc spec]
|
data/Steepfile
ADDED
data/docker-compose.yml
ADDED
data/exe/graaf
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'graaf'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
options = { o: "#{Dir.pwd}/libgraaf" }
|
8
|
+
OptionParser
|
9
|
+
.new
|
10
|
+
.tap { |opt| opt.on('-o [VAL]', String) }
|
11
|
+
.parse!(ARGV, into: options)
|
12
|
+
|
13
|
+
Graaf::Builder.new(java_paths: ARGV, output_path: options[:o]).execute
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Graaf
|
4
|
+
# Graaf::Builder
|
5
|
+
class Builder
|
6
|
+
# @param java_paths [Array<String>]
|
7
|
+
# @param output_path [String]
|
8
|
+
# @return [void]
|
9
|
+
def initialize(java_paths:, output_path:)
|
10
|
+
@java_paths = java_paths
|
11
|
+
@output_path = output_path
|
12
|
+
@output_dir = File.dirname(@output_path)
|
13
|
+
@options = [
|
14
|
+
'-march=native',
|
15
|
+
'--enable-sbom',
|
16
|
+
'--strict-image-heap',
|
17
|
+
'-H:+UnlockExperimentalVMOptions'
|
18
|
+
].freeze
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [void]
|
22
|
+
def execute
|
23
|
+
class_path = random_class_path
|
24
|
+
system(<<~SYSTEM)
|
25
|
+
javac -d #{class_path} #{java_paths.join(' ')} && \
|
26
|
+
native-image -cp #{class_path} -o #{output_path} --shared #{options.join(' ')} && \
|
27
|
+
rm -r \
|
28
|
+
#{class_path} \
|
29
|
+
#{output_dir}/graal_isolate.h \
|
30
|
+
#{output_dir}/graal_isolate_dynamic.h \
|
31
|
+
#{output_path}.h \
|
32
|
+
#{output_path}_dynamic.h
|
33
|
+
SYSTEM
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# @return [String]
|
39
|
+
def random_class_path
|
40
|
+
File.expand_path("../../tmp/#{SecureRandom.hex(10)}", __dir__)
|
41
|
+
end
|
42
|
+
|
43
|
+
# @!attribute [r] java_paths
|
44
|
+
# @return [Array<String>]
|
45
|
+
attr_reader :java_paths
|
46
|
+
# @!attribute [r] output_path
|
47
|
+
# @return [String]
|
48
|
+
attr_reader :output_path
|
49
|
+
# @!attribute [r] output_dir
|
50
|
+
# @return [String]
|
51
|
+
attr_reader :output_dir
|
52
|
+
# @!attribute [r] options
|
53
|
+
# @return [Array<String>]
|
54
|
+
attr_reader :options
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Graaf
|
4
|
+
# Graaf::Library
|
5
|
+
module Library
|
6
|
+
include FFI::Library
|
7
|
+
|
8
|
+
# @return [String]
|
9
|
+
ALIAS_PREFIX = '__graaf_'
|
10
|
+
private_constant :ALIAS_PREFIX
|
11
|
+
|
12
|
+
# @!method graal_create_isolate
|
13
|
+
# @private
|
14
|
+
# @param params [Graaf::CreateIsolateParams]
|
15
|
+
# @param graal_isolate_t [FFI::MemoryPointer]
|
16
|
+
# @param graal_isolatethread_t [FFI::MemoryPointer]
|
17
|
+
# @return [Integer]
|
18
|
+
# @!method graal_attach_thread
|
19
|
+
# @private
|
20
|
+
# @param graal_isolate_t [FFI::Pointer]
|
21
|
+
# @param graal_isolatethread_t [FFI::MemoryPointer]
|
22
|
+
# @return [Integer]
|
23
|
+
# @!method graal_detach_thread
|
24
|
+
# @private
|
25
|
+
# @param graal_isolatethread_t [FFI::Pointer]
|
26
|
+
# @return [Integer]
|
27
|
+
# @!method graal_tear_down_isolate
|
28
|
+
# @private
|
29
|
+
# @param graal_isolatethread_t [FFI::Pointer]
|
30
|
+
# @return [Integer]
|
31
|
+
# @!method graal_detach_all_threads_and_tear_down_isolate
|
32
|
+
# @private
|
33
|
+
# @param graal_isolatethread_t [FFI::Pointer]
|
34
|
+
# @return [Integer]
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# @param args [Array]
|
39
|
+
# @return [void]
|
40
|
+
def private_attach_function(*args)
|
41
|
+
attach_function(*args)
|
42
|
+
private_class_method(args[0])
|
43
|
+
end
|
44
|
+
|
45
|
+
# @param names [Array<String>]
|
46
|
+
# @return [void]
|
47
|
+
def graaf_lib(*names)
|
48
|
+
ffi_lib(*names)
|
49
|
+
private_attach_function :graal_create_isolate, [CreateIsolateParams.by_ref, :pointer, :pointer], :int
|
50
|
+
private_attach_function :graal_attach_thread, %i[pointer pointer], :int
|
51
|
+
private_attach_function :graal_detach_thread, %i[pointer], :int
|
52
|
+
private_attach_function :graal_tear_down_isolate, %i[pointer], :int
|
53
|
+
private_attach_function :graal_detach_all_threads_and_tear_down_isolate, %i[pointer], :int
|
54
|
+
end
|
55
|
+
|
56
|
+
# @param func [#to_s]
|
57
|
+
# @param args [Array<Symbol>]
|
58
|
+
# @param returns [Symbol]
|
59
|
+
# @param options [Hash]
|
60
|
+
# @option options [Boolean] :blocking
|
61
|
+
# @option options [Symbol] :convention
|
62
|
+
# @option options [FFI::Enums] :enums
|
63
|
+
# @option options [Hash] :type_map
|
64
|
+
# @return [void]
|
65
|
+
# @raise [FFI::NotFoundError]
|
66
|
+
def graaf_attach_function(func, args, returns = nil, options = nil)
|
67
|
+
alias_method_name = "#{ALIAS_PREFIX}#{func}"
|
68
|
+
private_attach_function(alias_method_name, func, [:pointer] + args, returns, options)
|
69
|
+
define_singleton_method(func) do |*override_args|
|
70
|
+
with_isolate { |thread| __send__(alias_method_name, thread, *override_args) }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# @yieldparam thread [FFI::Pointer]
|
75
|
+
# @yieldreturn [Object]
|
76
|
+
# @return [Object]
|
77
|
+
def with_isolate
|
78
|
+
thread = FFI::MemoryPointer.new(:pointer)
|
79
|
+
isolate = FFI::MemoryPointer.new(:pointer)
|
80
|
+
graal_create_isolate(nil, isolate, thread).zero? || (raise CreateIsolateError)
|
81
|
+
yield thread.read_pointer
|
82
|
+
ensure
|
83
|
+
graal_tear_down_isolate(thread.read_pointer)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/graaf.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ffi'
|
4
|
+
require 'securerandom'
|
5
|
+
require_relative 'graaf/version'
|
6
|
+
require_relative 'graaf/create_isolate_params'
|
7
|
+
require_relative 'graaf/library'
|
8
|
+
require_relative 'graaf/builder'
|
9
|
+
|
10
|
+
# Graaf
|
11
|
+
module Graaf
|
12
|
+
# Graaf::Error
|
13
|
+
class Error < StandardError; end
|
14
|
+
|
15
|
+
# Graaf::CreateIsolateError
|
16
|
+
class CreateIsolateError < Error; end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
---
|
2
|
+
sources:
|
3
|
+
- type: git
|
4
|
+
name: ruby/gem_rbs_collection
|
5
|
+
revision: 8149bc3fc0f720d935dc0592dc8886e03052f65f
|
6
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
7
|
+
repo_dir: gems
|
8
|
+
path: ".gem_rbs_collection"
|
9
|
+
gems:
|
10
|
+
- name: securerandom
|
11
|
+
version: '0'
|
12
|
+
source:
|
13
|
+
type: stdlib
|
14
|
+
gemfile_lock_path: Gemfile.lock
|
data/rbs_collection.yaml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Download sources
|
2
|
+
sources:
|
3
|
+
- type: git
|
4
|
+
name: ruby/gem_rbs_collection
|
5
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
6
|
+
revision: main
|
7
|
+
repo_dir: gems
|
8
|
+
|
9
|
+
# You can specify local directories as sources also.
|
10
|
+
# - type: local
|
11
|
+
# path: path/to/your/local/repository
|
12
|
+
|
13
|
+
# A directory to install the downloaded RBSs
|
14
|
+
path: .gem_rbs_collection
|
15
|
+
|
16
|
+
gems:
|
17
|
+
# Skip loading rbs gem's RBS.
|
18
|
+
# It's unnecessary if you don't use rbs as a library.
|
19
|
+
- name: rbs
|
20
|
+
ignore: true
|
21
|
+
- name: securerandom
|
data/sig/graaf.rbs
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Graaf
|
2
|
+
VERSION: String
|
3
|
+
|
4
|
+
class Error < StandardError
|
5
|
+
end
|
6
|
+
|
7
|
+
class CreateIsolateError < Error
|
8
|
+
end
|
9
|
+
|
10
|
+
class Builder
|
11
|
+
def initialize: (java_paths: ::Array[::String], output_path: ::String) -> void
|
12
|
+
|
13
|
+
def execute: () -> void
|
14
|
+
|
15
|
+
def __dir__: () -> ::String
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader java_paths: ::Array[::String]
|
20
|
+
attr_reader output_path: ::String
|
21
|
+
attr_reader output_dir: ::String
|
22
|
+
attr_reader options: ::Array[::String]
|
23
|
+
|
24
|
+
def random_class_path: () -> ::String
|
25
|
+
end
|
26
|
+
|
27
|
+
class CreateIsolateParams < FFI::Struct
|
28
|
+
end
|
29
|
+
|
30
|
+
module Library
|
31
|
+
include FFI::Library
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
ALIAS_PREFIX: ::String
|
36
|
+
|
37
|
+
def private_class_method: (untyped) -> void
|
38
|
+
|
39
|
+
def graal_create_isolate: (CreateIsolateParams? params, FFI::MemoryPointer graal_isolate_t, FFI::MemoryPointer graal_isolatethread_t) -> ::Integer
|
40
|
+
|
41
|
+
def graal_attach_thread: (FFI::Pointer graal_isolate_t, FFI::MemoryPointer graal_isolatethread_t) -> ::Integer
|
42
|
+
|
43
|
+
def graal_detach_thread: (FFI::Pointer graal_isolatethread_t) -> ::Integer
|
44
|
+
|
45
|
+
def graal_tear_down_isolate: (FFI::Pointer graal_isolatethread_t) -> ::Integer
|
46
|
+
|
47
|
+
def graal_detach_all_threads_and_tear_down_isolate: (FFI::Pointer graal_isolatethread_t) -> ::Integer
|
48
|
+
|
49
|
+
def graaf_lib: (*::String) -> void
|
50
|
+
|
51
|
+
def graaf_attach_function: (::String func, ::Array[::Symbol] args, ?::Symbol? returns, ?::Hash[untyped, untyped]? options) -> void
|
52
|
+
|
53
|
+
def private_attach_function: (*untyped) -> void
|
54
|
+
|
55
|
+
def with_isolate: () { (FFI::Pointer) -> untyped } -> untyped
|
56
|
+
end
|
57
|
+
end
|
data/sig_private/ffi.rbs
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module FFI
|
2
|
+
module Type
|
3
|
+
class Mapped
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
module Library
|
8
|
+
def ffi_lib: (*::String) -> void
|
9
|
+
|
10
|
+
def attach_function: (*untyped) -> ::FFI::VariadicInvoker
|
11
|
+
end
|
12
|
+
|
13
|
+
class VariadicInvoker
|
14
|
+
end
|
15
|
+
|
16
|
+
class MemoryPointer
|
17
|
+
def initialize: (::Symbol type) -> void
|
18
|
+
|
19
|
+
def read_pointer: () -> Pointer
|
20
|
+
end
|
21
|
+
|
22
|
+
class Pointer
|
23
|
+
end
|
24
|
+
|
25
|
+
class Struct
|
26
|
+
def self.layout: (*::Symbol) -> void
|
27
|
+
|
28
|
+
def self.by_ref: () -> Type::Mapped
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: graaf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- shoma07
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-10-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby FFI for Built a Shared Library by GraalVM Native Image
|
14
|
+
email:
|
15
|
+
- 23730734+shoma07@users.noreply.github.com
|
16
|
+
executables:
|
17
|
+
- graaf
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".rspec"
|
22
|
+
- ".rubocop.yml"
|
23
|
+
- CHANGELOG.md
|
24
|
+
- CODE_OF_CONDUCT.md
|
25
|
+
- Dockerfile
|
26
|
+
- Gemfile
|
27
|
+
- Gemfile.lock
|
28
|
+
- LICENSE.txt
|
29
|
+
- README.md
|
30
|
+
- Rakefile
|
31
|
+
- Steepfile
|
32
|
+
- docker-compose.yml
|
33
|
+
- exe/graaf
|
34
|
+
- lib/graaf.rb
|
35
|
+
- lib/graaf/builder.rb
|
36
|
+
- lib/graaf/create_isolate_params.rb
|
37
|
+
- lib/graaf/library.rb
|
38
|
+
- lib/graaf/version.rb
|
39
|
+
- rbs_collection.lock.yaml
|
40
|
+
- rbs_collection.yaml
|
41
|
+
- sig/graaf.rbs
|
42
|
+
- sig_private/ffi.rbs
|
43
|
+
homepage: https://github.com/shoma07/graaf_rb
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata:
|
47
|
+
homepage_uri: https://github.com/shoma07/graaf_rb
|
48
|
+
source_code_uri: https://github.com/shoma07/graaf_rb
|
49
|
+
changelog_uri: https://github.com/shoma07/graaf_rb/blob/main/CHANGELOG.md
|
50
|
+
rubygems_mfa_required: 'true'
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 2.7.0
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubygems_version: 3.4.10
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: Ruby FFI for Built a Shared Library by GraalVM Native Image
|
70
|
+
test_files: []
|