calcsheet-native 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 24c9944f46380b2013bd15f70dbe021f4ce3405957be54ee7051296dbf8f92a7
4
+ data.tar.gz: a2c957b36974b768d4c1bdf51c982d1c208ce36ca9e566afbf74e68b181eba94
5
+ SHA512:
6
+ metadata.gz: 27bec1c0bb46629cd1caff21c105b2022ccbe21f393dc1a95a37c8eb342a103ffd5dfd04a0933e320b440aab4bcf2565324fa14f57a49c367fa522a355fcff25
7
+ data.tar.gz: 8504e11364610d90744222fd790e8eae2f3e61276140fd2877ca646da5095b2d7df5ee69713c1bb3408d52800648fcd22098453e0d0f329f61e8022d202d3c87
data/CHANGELOG.md ADDED
@@ -0,0 +1,36 @@
1
+ # Changelog
2
+
3
+ All notable changes to this gem are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this gem adheres to
6
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2026-10-28
11
+
12
+ First release, for calcsheet 0.2 and 0.3 (protocol 1), with precompiled gems for `x86_64-linux`, `aarch64-linux`,
13
+ `x86_64-linux-musl`, `aarch64-linux-musl`, `arm64-darwin`, `x86_64-darwin` and `x64-mingw-ucrt` (Ruby 3.3, 3.4 and
14
+ 4.0) beside the source gem.
15
+
16
+ ### Added
17
+
18
+ - The gem skeleton: a Rust extension built with magnus and rb_sys, `Calcsheet::Native::PROTOCOL` 1 and
19
+ `Calcsheet::Native.backends`.
20
+ - The native CSV backend: a Rust tokenizer that accepts and refuses what the stdlib CSV parser does, run without the
21
+ GVL, under calcsheet's own CSV reader (dialect, encodings, numbering, checks and conversion). About twice as fast
22
+ as the Ruby backend on large files, with the same memory.
23
+ - The native XLSX backend: the XML of each sheet is read in Rust, without the GVL, for a plain subset of XML and the
24
+ values calcsheet accepts; anything else is read again by calcsheet's own parser, so results and errors are always
25
+ the Ruby backend's. The archive, its limits, the workbook, styles and shared strings stay calcsheet's. About 1.7
26
+ times as fast as the Ruby backend, with the same memory.
27
+ - The native ODS backend, built the same way: the XML of each table is read in Rust, the Scanner that finds tables
28
+ and rows, the archive and the cell styles stay calcsheet's. About twice as fast as the Ruby backend, with the same
29
+ memory.
30
+ - XLSX shared strings read in Rust, in one table shared by the sheets, and a faster XML lexer: with YJIT, XLSX
31
+ reads in 8.5 s per million rows instead of 10.3 s, ODS in 12.3 s instead of 13.6 s.
32
+ - An ODS read finds its sheet without listing every sheet (calcsheet's ADR 013): with YJIT, 9.1 s per million rows
33
+ instead of 12.3 s, and about 40 MB of peak memory instead of 100.
34
+
35
+ [Unreleased]: https://gitlab.opinioni.net/demetra-developers/rubygems/calcsheet-native/-/compare/v0.1.0...develop
36
+ [0.1.0]: https://gitlab.opinioni.net/demetra-developers/rubygems/calcsheet-native/-/tags/v0.1.0
data/Cargo.lock ADDED
@@ -0,0 +1,283 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "1.1.5"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "bindgen"
16
+ version = "0.72.1"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895"
19
+ dependencies = [
20
+ "bitflags",
21
+ "cexpr",
22
+ "clang-sys",
23
+ "itertools",
24
+ "proc-macro2",
25
+ "quote",
26
+ "regex",
27
+ "rustc-hash",
28
+ "shlex",
29
+ "syn",
30
+ ]
31
+
32
+ [[package]]
33
+ name = "bitflags"
34
+ version = "2.13.2"
35
+ source = "registry+https://github.com/rust-lang/crates.io-index"
36
+ checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
37
+
38
+ [[package]]
39
+ name = "calcsheet_native"
40
+ version = "0.1.0"
41
+ dependencies = [
42
+ "magnus",
43
+ "memchr",
44
+ "rb-sys",
45
+ ]
46
+
47
+ [[package]]
48
+ name = "cexpr"
49
+ version = "0.6.0"
50
+ source = "registry+https://github.com/rust-lang/crates.io-index"
51
+ checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
52
+ dependencies = [
53
+ "nom",
54
+ ]
55
+
56
+ [[package]]
57
+ name = "cfg-if"
58
+ version = "1.0.5"
59
+ source = "registry+https://github.com/rust-lang/crates.io-index"
60
+ checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
61
+
62
+ [[package]]
63
+ name = "clang-sys"
64
+ version = "1.9.1"
65
+ source = "registry+https://github.com/rust-lang/crates.io-index"
66
+ checksum = "157a8ba7b480713b56f4c09fd13fc3e0a22a5dfab8097ba61cbc5feef950788a"
67
+ dependencies = [
68
+ "glob",
69
+ "libc",
70
+ "libloading",
71
+ ]
72
+
73
+ [[package]]
74
+ name = "either"
75
+ version = "1.19.0"
76
+ source = "registry+https://github.com/rust-lang/crates.io-index"
77
+ checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
78
+
79
+ [[package]]
80
+ name = "glob"
81
+ version = "0.3.4"
82
+ source = "registry+https://github.com/rust-lang/crates.io-index"
83
+ checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"
84
+
85
+ [[package]]
86
+ name = "itertools"
87
+ version = "0.13.0"
88
+ source = "registry+https://github.com/rust-lang/crates.io-index"
89
+ checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
90
+ dependencies = [
91
+ "either",
92
+ ]
93
+
94
+ [[package]]
95
+ name = "lazy_static"
96
+ version = "1.5.1"
97
+ source = "registry+https://github.com/rust-lang/crates.io-index"
98
+ checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb"
99
+
100
+ [[package]]
101
+ name = "libc"
102
+ version = "0.2.190"
103
+ source = "registry+https://github.com/rust-lang/crates.io-index"
104
+ checksum = "ce5d3ddc6d3fa000eb1536d85e147bfe31aacaba692ed6a876f95cb7c855be78"
105
+
106
+ [[package]]
107
+ name = "libloading"
108
+ version = "0.8.9"
109
+ source = "registry+https://github.com/rust-lang/crates.io-index"
110
+ checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
111
+ dependencies = [
112
+ "cfg-if",
113
+ "windows-link",
114
+ ]
115
+
116
+ [[package]]
117
+ name = "magnus"
118
+ version = "0.9.2"
119
+ source = "registry+https://github.com/rust-lang/crates.io-index"
120
+ checksum = "b9068710e00d21be762edca59b9c4c8946dbdb29820d4f76ad559afea07982c9"
121
+ dependencies = [
122
+ "magnus-macros",
123
+ "rb-sys",
124
+ "rb-sys-env",
125
+ "seq-macro",
126
+ ]
127
+
128
+ [[package]]
129
+ name = "magnus-macros"
130
+ version = "0.9.1"
131
+ source = "registry+https://github.com/rust-lang/crates.io-index"
132
+ checksum = "9dafde2eeb66f090e0f326112323eb8324b12cb32b5d1210e541d3df6b0ce77e"
133
+ dependencies = [
134
+ "proc-macro2",
135
+ "quote",
136
+ "syn",
137
+ ]
138
+
139
+ [[package]]
140
+ name = "memchr"
141
+ version = "2.8.3"
142
+ source = "registry+https://github.com/rust-lang/crates.io-index"
143
+ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
144
+
145
+ [[package]]
146
+ name = "minimal-lexical"
147
+ version = "0.2.1"
148
+ source = "registry+https://github.com/rust-lang/crates.io-index"
149
+ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
150
+
151
+ [[package]]
152
+ name = "nom"
153
+ version = "7.1.3"
154
+ source = "registry+https://github.com/rust-lang/crates.io-index"
155
+ checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
156
+ dependencies = [
157
+ "memchr",
158
+ "minimal-lexical",
159
+ ]
160
+
161
+ [[package]]
162
+ name = "proc-macro2"
163
+ version = "1.0.107"
164
+ source = "registry+https://github.com/rust-lang/crates.io-index"
165
+ checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
166
+ dependencies = [
167
+ "unicode-ident",
168
+ ]
169
+
170
+ [[package]]
171
+ name = "quote"
172
+ version = "1.0.47"
173
+ source = "registry+https://github.com/rust-lang/crates.io-index"
174
+ checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
175
+ dependencies = [
176
+ "proc-macro2",
177
+ ]
178
+
179
+ [[package]]
180
+ name = "rb-sys"
181
+ version = "0.9.130"
182
+ source = "registry+https://github.com/rust-lang/crates.io-index"
183
+ checksum = "02faf625bb10ba893e3ae620f19c9fb1b5f8fcae0fe4eb86bb3f2230fad75edb"
184
+ dependencies = [
185
+ "rb-sys-build",
186
+ ]
187
+
188
+ [[package]]
189
+ name = "rb-sys-build"
190
+ version = "0.9.130"
191
+ source = "registry+https://github.com/rust-lang/crates.io-index"
192
+ checksum = "05be6f9c86fe5482808162826f6c047d093b3670582296c770de1d94f8066694"
193
+ dependencies = [
194
+ "bindgen",
195
+ "lazy_static",
196
+ "proc-macro2",
197
+ "quote",
198
+ "regex",
199
+ "shell-words",
200
+ "syn",
201
+ ]
202
+
203
+ [[package]]
204
+ name = "rb-sys-env"
205
+ version = "0.2.3"
206
+ source = "registry+https://github.com/rust-lang/crates.io-index"
207
+ checksum = "cca7ad6a7e21e72151d56fe2495a259b5670e204c3adac41ee7ef676ea08117a"
208
+
209
+ [[package]]
210
+ name = "regex"
211
+ version = "1.13.1"
212
+ source = "registry+https://github.com/rust-lang/crates.io-index"
213
+ checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d"
214
+ dependencies = [
215
+ "aho-corasick",
216
+ "memchr",
217
+ "regex-automata",
218
+ "regex-syntax",
219
+ ]
220
+
221
+ [[package]]
222
+ name = "regex-automata"
223
+ version = "0.4.18"
224
+ source = "registry+https://github.com/rust-lang/crates.io-index"
225
+ checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2"
226
+ dependencies = [
227
+ "aho-corasick",
228
+ "memchr",
229
+ "regex-syntax",
230
+ ]
231
+
232
+ [[package]]
233
+ name = "regex-syntax"
234
+ version = "0.8.11"
235
+ source = "registry+https://github.com/rust-lang/crates.io-index"
236
+ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
237
+
238
+ [[package]]
239
+ name = "rustc-hash"
240
+ version = "2.1.3"
241
+ source = "registry+https://github.com/rust-lang/crates.io-index"
242
+ checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
243
+
244
+ [[package]]
245
+ name = "seq-macro"
246
+ version = "0.3.6"
247
+ source = "registry+https://github.com/rust-lang/crates.io-index"
248
+ checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc"
249
+
250
+ [[package]]
251
+ name = "shell-words"
252
+ version = "1.1.1"
253
+ source = "registry+https://github.com/rust-lang/crates.io-index"
254
+ checksum = "dc6fe69c597f9c37bfeeeeeb33da3530379845f10be461a66d16d03eca2ded77"
255
+
256
+ [[package]]
257
+ name = "shlex"
258
+ version = "1.3.0"
259
+ source = "registry+https://github.com/rust-lang/crates.io-index"
260
+ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
261
+
262
+ [[package]]
263
+ name = "syn"
264
+ version = "2.0.119"
265
+ source = "registry+https://github.com/rust-lang/crates.io-index"
266
+ checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
267
+ dependencies = [
268
+ "proc-macro2",
269
+ "quote",
270
+ "unicode-ident",
271
+ ]
272
+
273
+ [[package]]
274
+ name = "unicode-ident"
275
+ version = "1.0.26"
276
+ source = "registry+https://github.com/rust-lang/crates.io-index"
277
+ checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954"
278
+
279
+ [[package]]
280
+ name = "windows-link"
281
+ version = "0.2.1"
282
+ source = "registry+https://github.com/rust-lang/crates.io-index"
283
+ checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
data/Cargo.toml ADDED
@@ -0,0 +1,7 @@
1
+ [workspace]
2
+ resolver = "2"
3
+ members = ["ext/calcsheet_native"]
4
+
5
+ [profile.release]
6
+ codegen-units = 1
7
+ lto = "thin"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Demetra Opinioni.net Srl
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,65 @@
1
+ # calcsheet-native
2
+
3
+ Native reader backends for [calcsheet](https://gitlab.opinioni.net/demetra-developers/rubygems/calcsheet): a Rust
4
+ core reads CSV, XLSX and ODS (inflating, tokenizing, limits) without the GVL and hands raw cells to calcsheet, which
5
+ converts them exactly as its Ruby backends do. With the same file and the same options both backends must give the
6
+ same rows, cell errors and exceptions; the only allowed differences are listed in
7
+ [docs/parity-exceptions.md](docs/parity-exceptions.md).
8
+
9
+ ## Status
10
+
11
+ Released on rubygems.org. CSV, XLSX and ODS are read natively. Precompiled gems exist for `x86_64-linux`,
12
+ `aarch64-linux`, `x86_64-linux-musl`, `aarch64-linux-musl`, `arm64-darwin`, `x86_64-darwin` and `x64-mingw-ucrt`, each
13
+ for Ruby 3.3, 3.4 and 4.0; any other platform installs the source gem, which needs the Rust toolchain and libclang
14
+ (see Development).
15
+
16
+ Seconds per million rows of 11 columns (Ruby 4.0, x86_64; XLSX and ODS measured on 100,000 rows), end to end
17
+ with the values converted; the peak memory is the same with both backends:
18
+
19
+ | File | Ruby | Ruby + YJIT | Native | Native + YJIT |
20
+ |---|---|---|---|---|
21
+ | CSV | 7.5 s | 3.9 s | 3.7 s | 2.0 s |
22
+ | XLSX | 27.8 s | 16.9 s | 12.0 s | 8.5 s |
23
+ | ODS | 35.7 s | 17.7 s | 14.8 s | 9.1 s |
24
+
25
+ With YJIT, the conversion of the cells in Ruby (calcsheet's ADR 011) is 30 to 45% of the native time. Two reads in
26
+ two threads take 1.7 to 2 times as long as one.
27
+
28
+ ## Usage
29
+
30
+ Add it next to calcsheet; nothing else changes in the application:
31
+
32
+ ```ruby
33
+ gem "calcsheet", "~> 0.3"
34
+ gem "calcsheet-native"
35
+ ```
36
+
37
+ It needs calcsheet 0.2 or 0.3 (protocol 1). calcsheet uses it under `backend: :auto` (the default) for the formats it reads, and falls back to the Ruby backends,
38
+ with one warning, when it is installed but unusable.
39
+
40
+ ## Development
41
+
42
+ Requirements: Ruby 3.3 or later, the Rust toolchain of `rust-toolchain.toml` (rustup installs it) and libclang
43
+ (Debian: `libclang-dev`), which rb_sys uses to generate the Ruby bindings.
44
+
45
+ ```sh
46
+ bundle install
47
+ bundle exec rake compile
48
+ bundle exec rake # compile, specs, calcsheet's suite on the native backends, RuboCop
49
+ cargo fmt --check && cargo clippy --all-targets -- -D warnings
50
+ ```
51
+
52
+ The Gemfile takes calcsheet from the tag of its release, whose suite `rake parity` runs (the published gem leaves
53
+ it out).
54
+
55
+ A release builds the precompiled gems and the source gem into `pkg/` with Docker, from a checkout of its tag, then
56
+ pushes each of them (rubygems.org asks for the security key of every push):
57
+
58
+ ```sh
59
+ bin/build-native-gems
60
+ for gem in pkg/*.gem; do gem push "$gem"; done
61
+ ```
62
+
63
+ ## License
64
+
65
+ MIT, see [LICENSE.txt](LICENSE.txt).
@@ -0,0 +1,14 @@
1
+ [package]
2
+ name = "calcsheet_native"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+ license = "MIT"
6
+ publish = false
7
+
8
+ [lib]
9
+ crate-type = ["cdylib"]
10
+
11
+ [dependencies]
12
+ magnus = "=0.9.2"
13
+ memchr = "=2.8.3"
14
+ rb-sys = "=0.9.130"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "rb_sys/mkmf"
5
+
6
+ create_rust_makefile("calcsheet/native/calcsheet_native")