kupcad 0.1.10-aarch64-linux-gnu → 0.1.12-aarch64-linux-gnu

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82e26a65027a0647398cab5538abf8c8561b6d66f5be6a7893eaac119de6a393
4
- data.tar.gz: 7206c1f2981b43e624a17af53310774a4e495c3138c307c3d66f4375d7e1a71a
3
+ metadata.gz: ea196661e86965a640b82a3b2d5ff64f485c47a643bf6ee629e94c832fdf0d03
4
+ data.tar.gz: 6477c96d4f2a868d3a79ce5606b17762780ce0370e4db8dd02fc09c06e2e6eb8
5
5
  SHA512:
6
- metadata.gz: 9cae768cb5d6234a632e17a68d62f6932193d5eca1be964c77737eda25964216f5804e00d1371d646f4e0eb75542d507e214dd93747228ef55d3537a90b331e4
7
- data.tar.gz: cde9eeefc3d07f18362b8e44c07082865804029da0fd483573457659a21cb21dd33aff878d32f4259d88880515c36a69ee462299485870a56ee4ebc93e7d56b8
6
+ metadata.gz: e3e81394a31a203638a0e1b53663f0b64ded96ae594d1a289767fd2f01f5c76941573f2aa7d8ae3b880ba04025e4d81de083a98e41da4040c7fae91ff600ff48
7
+ data.tar.gz: 8b7629424c5f497aa301b73781e5f4356611e1bf4192fce06f43c70583143fabf368625618a1212494bcfd70a831942b72583268996beea2ae23562a8c1770a4
data/README.md CHANGED
@@ -26,12 +26,14 @@ model.report.warnings.each { |w| warn "#{w.line}: #{w.message}" }
26
26
  `:dxf`), and the run's `report`, what the script printed and the `Kupcad::RunWarning`s it
27
27
  warned of, where.
28
28
  - `params:` the parameters' values by name, as `kupcad build -p` takes them:
29
- `{ width: 60, thread: :m4, holes: [[5, 5], [35, 5]] }`. Values are checked against each
30
- parameter's rules.
29
+ `{ width: 60, thread: :m4, holes: [[5, 5], [35, 5]] }`, each what JSON has a type for (a
30
+ String or a Symbol, an Integer or a Float, true, false, nil, an Array or a Hash of them).
31
+ Values are checked against each parameter's rules.
31
32
  - `files:` the files the script imports, by their path from its folder, each a String, text
32
33
  or binary: `{ 'lib/gears.kup' => File.read('lib/gears.kup'), 'parts/base.stl' =>
33
34
  File.binread(...) }`. A script reads no other file, and its exports (`export_stl`) write
34
35
  nothing.
36
+ - `nil` for `params:` or `files:` is none, as leaving them out is.
35
37
  - `memory_limit:` the most memory, in bytes, the script may hold: its values and its
36
38
  geometry graph, not the kernel's meshes; no limit by default.
37
39
  - `timeout:` the most time, in seconds, the build may take, to the millisecond; no limit by
@@ -58,7 +60,9 @@ US-ASCII one as UTF-8, which is what libkupcad reads); a file's content is passe
58
60
  thin"`), and its `report` holds what the script printed until then.
59
61
  - `ArgumentError` for a format that isn't one, a limit that isn't positive, parameter values
60
62
  JSON can't hold (NaN), or values that aren't by name (an Array).
61
- - `TypeError` for a source, or a file's content, that isn't a String (a `Pathname`: read it).
63
+ - `TypeError` for parameter values JSON has no type for (a `Rational`, a `BigDecimal`, a `Set`:
64
+ JSON would write them as text), saying which, or a source, or a file's content, that isn't a
65
+ String (a `Pathname`: read it).
62
66
  - `NoMemoryError` when the process itself runs out of memory, and `Kupcad::Error` itself when
63
67
  libkupcad fails on its own, a bug of KupCAD's.
64
68
 
@@ -75,11 +79,13 @@ To run scripts you don't trust, or keep a crash away from a web server, run the
75
79
  ## Platforms
76
80
 
77
81
  Each platform gem carries its libkupcad: Linux (x86_64, aarch64; glibc 2.28 or later), macOS
78
- (arm64, x86_64) and Windows (x64, aarch64), with `THIRD_PARTY_NOTICES.md` and the license texts
79
- of what it is built from beside it, in `lib/kupcad/native/`. Elsewhere (musl, BSD), build
80
- libkupcad with `zig build lib` in the kupcad repository's `core/`, install the gem from
81
- `bindings/ruby/` (`gem build kupcad.gemspec && gem install kupcad-*.gem`, a gem without the
82
- library) and point `KUPCAD_LIBRARY` at the library.
82
+ (arm64, x86_64) and Windows (x64, aarch64), for any Ruby from 3.2, with `THIRD_PARTY_NOTICES.md`
83
+ and the license texts of what it is built from beside it, in `lib/kupcad/native/`; each is
84
+ attested as built by the kupcad repository's release from its tag (`gh attestation verify
85
+ kupcad-<version>-<platform>.gem --repo kupcad/kupcad`). Elsewhere (musl, BSD), build libkupcad
86
+ with `zig build lib` in the kupcad repository's `core/`, install the gem from `bindings/ruby/`
87
+ (`gem build kupcad.gemspec && gem install kupcad-*.gem`, a gem without the library) and point
88
+ `KUPCAD_LIBRARY` at the library.
83
89
 
84
90
  ## Development
85
91
 
@@ -11,7 +11,6 @@ file in a release archive, a gem or a wheel, at the path given (in the repositor
11
11
  | [Manifold](https://github.com/elalish/manifold) | the mesh geometry kernel | Apache-2.0 | The Manifold Authors | `licenses/manifold/LICENSE` |
12
12
  | [oneTBB](https://github.com/oneapi-src/oneTBB) | parallel geometry (not in the WebAssembly build) | Apache-2.0; its third-party parts as listed | Intel Corporation | `licenses/onetbb/LICENSE.txt`, `licenses/onetbb/third-party-programs.txt` |
13
13
  | [Draco](https://github.com/google/draco) | glTF mesh compression | Apache-2.0 | The Draco Authors | `licenses/draco/LICENSE` |
14
- | [Eigen](https://gitlab.com/libeigen/eigen) | linear algebra in the B-Rep engine | MPL-2.0 (a few files under the licenses listed) | Eigen's authors | `licenses/eigen/LICENSE`, `licenses/eigen/LICENSES/` |
15
14
  | [SQLite](https://sqlite.org) | the package cache | public domain | none | none needed |
16
15
  | [tatfi](https://git.sr.ht/~asibahi/tatfi) | reading the fonts | MPL-2.0 | tatfi's authors | `licenses/tatfi/LICENSE` |
17
16
  | [HarfBuzz](https://github.com/harfbuzz/harfbuzz) | shaping text: kerning, ligatures, joining forms and marks | MIT ("Old MIT"); its Universal Shaping Engine tables from Microsoft's data, MIT | HarfBuzz's authors; Microsoft Corporation | `licenses/harfbuzz/COPYING`, `licenses/harfbuzz/ms-use/COPYING` |
Binary file
File without changes
data/lib/kupcad/native.rb CHANGED
@@ -19,7 +19,35 @@ module Kupcad
19
19
  "(this is #{RUBY_PLATFORM}). Set KUPCAD_LIBRARY to a libkupcad you built (`zig build lib` in " \
20
20
  "the kupcad repository's core/), or run the kupcad CLI."
21
21
  end
22
- ffi_lib path
22
+
23
+ # ffi opens a library on Windows with LoadLibraryExA, which reads the path in the system's
24
+ # code page, not as the UTF-8 Ruby gives it: a path past ASCII (C:\Users\José\...) wasn't
25
+ # found. There the library is loaded by its path in UTF-16 first, as ffi loads one by its
26
+ # path (its own folder searched for what it needs), then ffi opens it by its file name, which
27
+ # Windows resolves to the module of that name already loaded, searching no folder.
28
+ if FFI::Platform.windows?
29
+ # Windows' loader, which takes a path in UTF-16
30
+ module Kernel32
31
+ extend FFI::Library
32
+
33
+ ffi_lib 'kernel32'
34
+ ffi_convention :stdcall
35
+
36
+ LOAD_WITH_ALTERED_SEARCH_PATH = 0x8
37
+
38
+ attach_function :LoadLibraryExW, %i[buffer_in pointer uint32], :pointer
39
+ end
40
+ private_constant :Kernel32
41
+
42
+ wide = "#{File.expand_path(path).tr('/', '\\')}\0".encode(Encoding::UTF_16LE)
43
+ if Kernel32.LoadLibraryExW(wide, nil, Kernel32::LOAD_WITH_ALTERED_SEARCH_PATH).null?
44
+ raise LoadError, "#{path} can't be loaded: Windows error #{FFI::LastError.winapi_error}"
45
+ end
46
+
47
+ ffi_lib File.basename(path)
48
+ else
49
+ ffi_lib path
50
+ end
23
51
 
24
52
  # First, so a library of another ABI is refused as one, not for a function it lacks
25
53
  attach_function :kupcad_abi_version, [], :uint32
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Kupcad
6
+ # The parameters' values as the JSON libkupcad takes them (`kupcad build -p`'s), each checked
7
+ # first: JSON.generate writes a value it has no type for as its to_s, so a Rational became the
8
+ # String "5/2", which a number parameter refused and a string parameter took.
9
+ module Params
10
+ # What a value, or a key of a Hash among them, may be besides an Array or a Hash: the values
11
+ # JSON has a type for
12
+ SCALARS = [String, Symbol, Integer, Float, TrueClass, FalseClass, NilClass].freeze
13
+
14
+ # How deep JSON.generate nests values before it refuses them: the check stops there
15
+ DEPTH = JSON::State.new.max_nesting
16
+
17
+ module_function
18
+
19
+ # `params` as JSON, '' for none (nil, or empty). Raises TypeError for a value JSON has no
20
+ # type for, saying where, and ArgumentError for one it can't hold (NaN) or nested too deep.
21
+ def json(params)
22
+ check(params, 'params')
23
+ params.nil? || (params.respond_to?(:empty?) && params.empty?) ? '' : JSON.generate(params)
24
+ rescue JSON::GeneratorError, JSON::NestingError => e
25
+ raise ArgumentError, "parameters: #{e.message}"
26
+ end
27
+
28
+ # Raises TypeError for a value in `value`, or a key of a Hash among them, that JSON has no type
29
+ # for, saying where (`where`, as Ruby reads it: params[:holes][1]). Past DEPTH it stops:
30
+ # JSON.generate refuses what is that deep, and going on would only use up the stack.
31
+ def check(value, where, depth = 0)
32
+ return if depth > DEPTH
33
+
34
+ case value
35
+ when Hash
36
+ value.each do |key, item|
37
+ check_scalar(key, "a key of #{where}")
38
+ check(item, "#{where}[#{key.inspect}]", depth + 1)
39
+ end
40
+ when Array then value.each_with_index { |item, index| check(item, "#{where}[#{index}]", depth + 1) }
41
+ else check_scalar(value, where)
42
+ end
43
+ end
44
+
45
+ def check_scalar(value, where)
46
+ return if SCALARS.any? { |type| value.is_a?(type) }
47
+
48
+ raise TypeError, "#{where} is #{value.class}, which JSON has no type for (it has Strings, Symbols, Integers, " \
49
+ 'Floats, true, false, nil, Arrays and Hashes)'
50
+ end
51
+ private_class_method :check, :check_scalar
52
+ end
53
+ private_constant :Params
54
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Kupcad
4
4
  # The KupCAD release the gem comes from, and the libkupcad it carries
5
- VERSION = '0.1.10'
5
+ VERSION = '0.1.12'
6
6
  end
data/lib/kupcad.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'json'
4
4
  require_relative 'kupcad/version'
5
5
  require_relative 'kupcad/native'
6
+ require_relative 'kupcad/params'
6
7
 
7
8
  # KupCAD from Ruby: build the model of a KupCAD script, with its parameters, in any format the
8
9
  # CLI exports, and format, lint and read the parameters of scripts. It runs libkupcad, the
@@ -93,18 +94,20 @@ module Kupcad
93
94
  # Runs `source` and builds its model in `format` (one of FORMATS), a Model.
94
95
  #
95
96
  # params: the parameters' values by name, as `kupcad build -p` takes them
96
- # ({ width: 60, label: 'A', holes: [[5, 5], [35, 5]] }).
97
+ # ({ width: 60, label: 'A', holes: [[5, 5], [35, 5]] }); nil for none.
97
98
  # files: the files the script imports, by their path from its folder, text or binary
98
- # ({ 'lib/gears.kup' => File.read('lib/gears.kup'), 'parts/base.stl' => File.binread(...) }).
99
+ # ({ 'lib/gears.kup' => File.read('lib/gears.kup'), 'parts/base.stl' => File.binread(...) });
100
+ # nil for none.
99
101
  # memory_limit: the most memory, in bytes, the script may hold; nil for no limit.
100
102
  # timeout: the most time, in seconds, the build may take; nil (or Float::INFINITY) for no
101
103
  # limit. The time is checked every few thousand instructions and between geometry
102
104
  # operations.
103
105
  # draco: compress a GLB's or a glTF's meshes with Draco.
104
106
  #
105
- # Raises ScriptError when the script fails, with what it printed and warned of until then,
106
- # ArgumentError for a format that isn't one, a limit that isn't positive, or parameter
107
- # values JSON can't hold, and TypeError for a source or a file's content that isn't a String.
107
+ # Raises ScriptError when the script fails, with what it printed and warned of until then;
108
+ # ArgumentError for a format that isn't one, a limit that isn't positive, or parameter values
109
+ # JSON can't hold (NaN) or that aren't by name (an Array); and TypeError for values JSON has
110
+ # no type for (a Rational, a Set), or a source or a file's content that isn't a String.
108
111
  def build(source, format: :stl, params: {}, files: {}, memory_limit: nil, timeout: nil, draco: false)
109
112
  format = format.to_sym
110
113
  unless FORMATS.include?(format)
@@ -112,7 +115,7 @@ module Kupcad
112
115
  end
113
116
 
114
117
  data, report = call(:kupcad_build, *Native.buffer(utf8(source, 'source')), format.to_s,
115
- *Native.buffer(params_json(params)), *Native.buffer(pack(files)),
118
+ *Native.buffer(Params.json(params)), *Native.buffer(pack(files || {})),
116
119
  limit(memory_limit, 'memory_limit'), milliseconds(timeout), draco ? true : false)
117
120
  Model.new(data:, format:, report: Report.from_json(report))
118
121
  end
@@ -152,12 +155,6 @@ module Kupcad
152
155
  RAW_ENCODINGS.include?(text.encoding) ? text : text.encode(Encoding::UTF_8)
153
156
  end
154
157
 
155
- def params_json(params)
156
- params.empty? ? '' : JSON.generate(params)
157
- rescue JSON::GeneratorError, JSON::NestingError => e
158
- raise ArgumentError, "parameters: #{e.message}"
159
- end
160
-
161
158
  # A limit as the library takes it, 0 for none; one past what it holds is none either
162
159
  def limit(value, name)
163
160
  return 0 if value.nil?
@@ -0,0 +1,9 @@
1
+ module Kupcad
2
+ # The parameters' values as the JSON libkupcad takes them, each checked first (private to the gem)
3
+ module Params
4
+ SCALARS: Array[Module]
5
+ DEPTH: Integer
6
+
7
+ def self.json: (untyped params) -> String
8
+ end
9
+ end
data/sig/kupcad.rbs CHANGED
@@ -2,6 +2,10 @@ module Kupcad
2
2
  VERSION: String
3
3
  FORMATS: Array[Symbol]
4
4
 
5
+ # A parameter value: what JSON has a type for (Kupcad.build raises TypeError for anything else)
6
+ type json_scalar = String | Symbol | Integer | Float | bool | nil
7
+ type json_value = json_scalar | Array[json_value] | Hash[json_scalar, json_value]
8
+
5
9
  class Error < StandardError
6
10
  end
7
11
 
@@ -56,6 +60,6 @@ module Kupcad
56
60
  def self.format: (String source) -> String
57
61
  def self.check: (String source) -> Array[Finding]
58
62
  def self.params: (String source) -> Hash[Symbol, untyped]
59
- def self.build: (String source, ?format: Symbol | String, ?params: Hash[Symbol | String, untyped],
60
- ?files: Hash[_ToS, String], ?memory_limit: Integer?, ?timeout: Numeric?, ?draco: boolish) -> Model
63
+ def self.build: (String source, ?format: Symbol | String, ?params: Hash[Symbol | String, json_value]?,
64
+ ?files: Hash[_ToS, String]?, ?memory_limit: Integer?, ?timeout: Numeric?, ?draco: boolish) -> Model
61
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kupcad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.12
5
5
  platform: aarch64-linux-gnu
6
6
  authors:
7
7
  - Oleksii Vasyliev
@@ -43,12 +43,6 @@ files:
43
43
  - lib/kupcad/native/licenses/NotoSymbols-OFL.txt
44
44
  - lib/kupcad/native/licenses/RobotoSerif-OFL.txt
45
45
  - lib/kupcad/native/licenses/draco/LICENSE
46
- - lib/kupcad/native/licenses/eigen/LICENSE
47
- - lib/kupcad/native/licenses/eigen/LICENSES/Apache-2.0.txt
48
- - lib/kupcad/native/licenses/eigen/LICENSES/BSD-3-Clause-Open-MPI.txt
49
- - lib/kupcad/native/licenses/eigen/LICENSES/BSD-3-Clause.txt
50
- - lib/kupcad/native/licenses/eigen/LICENSES/LicenseRef-MINPACK.txt
51
- - lib/kupcad/native/licenses/eigen/LICENSES/MPL-2.0.txt
52
46
  - lib/kupcad/native/licenses/harfbuzz/COPYING
53
47
  - lib/kupcad/native/licenses/harfbuzz/ms-use/COPYING
54
48
  - lib/kupcad/native/licenses/lsp-kit-MIT.txt
@@ -58,8 +52,10 @@ files:
58
52
  - lib/kupcad/native/licenses/sheenbidi/LICENSE
59
53
  - lib/kupcad/native/licenses/tatfi/LICENSE
60
54
  - lib/kupcad/native/licenses/zig-MIT.txt
55
+ - lib/kupcad/params.rb
61
56
  - lib/kupcad/version.rb
62
57
  - sig/kupcad.rbs
58
+ - sig/kupcad/params.rbs
63
59
  homepage: https://kupcad.org
64
60
  licenses:
65
61
  - AGPL-3.0-only