kar 6 → 8

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: 370a71b352efdc345562491f694552d0450a7eb7bb3b73f4e2f70d89f8ead35d
4
- data.tar.gz: 04d19c674fdd8afc2d7c588429642c641ec2ea0c431855d1ebc877d7f06f80b4
3
+ metadata.gz: f4c0a1aedbbe17daa95271d652ed514cc3dbd612a6e8ffae1245e66d55267614
4
+ data.tar.gz: 7d05b2efc9519d39dcfe3a063a99d1a9d63cc327b452c76bb5f43cea2233ea40
5
5
  SHA512:
6
- metadata.gz: ccc1f62a586e54a7d3c4b65181cbee1dac9752c6a59e47379e552da7230913db46f3ff9f6090e16004850898adf0efc1b37f6c06d26cbc37044b84462f8eef1a
7
- data.tar.gz: f21722ed42367ddb8be79c63bf1b528f1c80fd9cf84fe2e763dc2f7f9df18efffa153afe9d6dfb9adcec80119ad92f53f5609826784b26c610f0427e9492de22
6
+ metadata.gz: c949744f08208072d0171ee87002e65a9d2ab025790d4acb27637c32afb3f92d46ea0e3979f7cfd7ab091e740ce40d922e28753983342044d2f78f6f1bb3ed50
7
+ data.tar.gz: 146fbd5c31d7f79be868c7c97e248d5ab82d6e7bb5e74e05e78b6cee8ae5972f66d021911bce79b752a140b33ed5e0e1f8d3bccfaafde4a2adc2af18ffeab5de
data/CHANGELOG.md CHANGED
@@ -1,10 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
- # [6] - 2025-11-16
3
+ ## [7] - 2026-08-11
4
+
5
+ * Fix installation path of Cargo built file of CargoTask
6
+
7
+ ## [6] - 2025-11-16
4
8
 
5
9
  * Don't remove compiled files in CargoTask
6
10
 
7
- # [5] - 2025-11-14
11
+ ## [5] - 2025-11-14
8
12
 
9
13
  * Use open-uri for URITask
10
14
  * Add Cargo.lock generate task in CargoTask
data/kar.gemspec CHANGED
@@ -1,11 +1,11 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "kar"
3
- spec.version = "6"
3
+ spec.version = "8"
4
4
  spec.authors = ["Kitaiti Makoto"]
5
5
  spec.email = ["KitaitiMakoto@gmail.com"]
6
6
 
7
7
  spec.summary = "Rake utilities"
8
- spec.description = "Rake utilities such as task to download, DSL to define multiple tasks at onece, etc."
8
+ spec.description = "Rake utilities such as task to download, DSL to define multiple tasks at once, etc."
9
9
  spec.homepage = "https://gitlab.com/KitaitiMakoto/kar"
10
10
  spec.required_ruby_version = ">= 2.6.0"
11
11
  spec.license = "AGPL-3.0-or-later"
@@ -0,0 +1,67 @@
1
+ class Kar::CargoTask::CargoBuilder < Gem::Ext::CargoBuilder
2
+ # Original Gem::Ext::CargoBuilder removes compiled files after installation.
3
+ # It is ideal for installation, but not for development.
4
+ # We override the behavior to keep the compiled files.
5
+ def build(extension, dest_path, results, args = [], lib_dir = nil, cargo_dir = Dir.pwd,
6
+ target_rbconfig = Gem.target_rbconfig, n_jobs: nil)
7
+ require "tempfile"
8
+ require "fileutils"
9
+
10
+ if target_rbconfig.path
11
+ warn "--target-rbconfig is not yet supported for Rust extensions. Ignoring"
12
+ end
13
+
14
+ # Where's the Cargo.toml of the crate we're building
15
+ cargo_toml = File.join(cargo_dir, "Cargo.toml")
16
+ # What's the crate's name
17
+ crate_name = cargo_crate_name(cargo_dir, cargo_toml, results)
18
+
19
+ begin
20
+ # Mimic tmp_dest to make diff with superclass's #build clean
21
+ tmp_dest = cargo_dir
22
+
23
+ # Run the build
24
+ cmd = cargo_command(cargo_toml, tmp_dest, args, crate_name)
25
+ runner.call(cmd, results, "cargo", cargo_dir, build_env)
26
+
27
+ # Where do we expect Cargo to write the compiled library
28
+ dylib_path = cargo_dylib_path(tmp_dest, crate_name)
29
+
30
+ # Helpful error if we didn't find the compiled library
31
+ raise DylibNotFoundError, tmp_dest unless File.exist?(dylib_path)
32
+
33
+ # Cargo and Ruby differ on how the library should be named, rename from
34
+ # what Cargo outputs to what Ruby expects
35
+ dlext_name = "#{crate_name}.#{makefile_config("DLEXT")}"
36
+ dlext_path = File.join(File.dirname(dylib_path), dlext_name)
37
+ FileUtils.cp(dylib_path, dlext_path)
38
+
39
+ nesting = extension_nesting(extension)
40
+
41
+ if Gem.install_extension_in_lib && lib_dir
42
+ nested_lib_dir = File.join(lib_dir, nesting)
43
+ FileUtils.mkdir_p nested_lib_dir
44
+ FileUtils.cp_r dlext_path, nested_lib_dir, remove_destination: true
45
+ end
46
+
47
+ # move to final destination
48
+ nested_dest_path = File.join(dest_path, nesting)
49
+ FileUtils.mkdir_p nested_dest_path
50
+ FileUtils.cp_r dlext_path, nested_dest_path, remove_destination: true
51
+ ensure
52
+ #noop
53
+ end
54
+
55
+ results
56
+ end
57
+
58
+ # This intentionally duplicates part of #build to keep that method close to
59
+ # the upstream CargoBuilder implementation and make updates easy to review with diff.
60
+ def dl_path(extension, dest_path, cargo_dir)
61
+ cargo_toml = File.join(cargo_dir, "Cargo.toml")
62
+ crate_name = cargo_crate_name(cargo_dir, cargo_toml, [])
63
+ dlext_name = "#{crate_name}.#{makefile_config("DLEXT")}"
64
+ nesting = extension_nesting(extension)
65
+ File.join(dest_path, nesting, dlext_name)
66
+ end
67
+ end
data/lib/kar/cargotask.rb CHANGED
@@ -23,16 +23,16 @@ module Kar
23
23
  file dl_path => [lock_file] + src do |t|
24
24
  results = Results.new
25
25
  begin
26
- CargoBuilder.new.build t.source, ext_dir, results, [], lib_dir, File.expand_path(ext_dir)
26
+ builder.build manifest, lib_dir, results, [], nil, cargo_dir
27
27
  rescue => error
28
28
  $stderr.puts results unless verbose?
29
29
  fail
30
30
  end
31
31
  end
32
- CLEAN.include dl_name, dl_path
32
+ CLEAN.include dl_path
33
33
 
34
34
  file lock_file => manifest do |t|
35
- sh "cargo", "generate-lockfile", "--manifest-path", t.source
35
+ sh "cargo", "generate-lockfile", "--manifest-path", t.source, "--offline"
36
36
  end
37
37
 
38
38
  namespace :cargo do
@@ -47,12 +47,25 @@ module Kar
47
47
 
48
48
  desc "Check Rust sources and manifests"
49
49
  task check: "cargo:check:#{@target}"
50
+
51
+ namespace :fmt do
52
+ task @target => manifest do |t|
53
+ sh "cargo", "fmt", "--manifest-path", manifest, "--quiet"
54
+ end
55
+ end
56
+
57
+ desc "Format Rust sources"
58
+ task fmt: "cargo:fmt:#{@target}"
50
59
  end
51
60
 
52
61
  desc "Build all extensions in Rust"
53
62
  task cargo: "cargo:#{@target}"
54
63
  end
55
64
 
65
+ def builder
66
+ @builder ||= CargoBuilder.new
67
+ end
68
+
56
69
  def gemspec
57
70
  @gemspec ||= Gem::Specification.load("#{@target}.gemspec")
58
71
  end
@@ -65,6 +78,10 @@ module Kar
65
78
  @lock_file ||= manifest.ext(".lock")
66
79
  end
67
80
 
81
+ def cargo_dir
82
+ @cargo_dir ||= File.expand_path(ext_dir)
83
+ end
84
+
68
85
  def ext_dir
69
86
  @ext_dir ||= File.dirname(manifest)
70
87
  end
@@ -74,16 +91,12 @@ module Kar
74
91
  @lib_dir ||= gemspec.require_paths[1]
75
92
  end
76
93
 
77
- def dl_name
78
- @dl_name ||= "#{gemspec.name}.#{RbConfig::CONFIG["DLEXT"]}"
79
- end
80
-
81
94
  def dl_path
82
- @dl_path ||= File.join(lib_dir, dl_name)
95
+ @dl_path ||= builder.dl_path(manifest, lib_dir, cargo_dir)
83
96
  end
84
97
 
85
98
  def src
86
- @src ||= FileList["#{ext_dir}/src/**/*.rs"]
99
+ @src ||= FileList["#{ext_dir}/src/**/*.rs", "#{ext_dir}/build.rs"]
87
100
  end
88
101
 
89
102
  class Results
@@ -111,56 +124,7 @@ module Kar
111
124
  Rake.verbose == true
112
125
  end
113
126
  end
114
-
115
- class CargoBuilder < Gem::Ext::CargoBuilder
116
- # Original Gem::Ext::CargoBuilder removes compiled files after installation.
117
- # It is ideal for installation, but not for development.
118
- # We override the behavior to keep the compiled files.
119
- def build(extension, dest_path, results, args = [], lib_dir = nil, cargo_dir = Dir.pwd,
120
- target_rbconfig=Gem.target_rbconfig)
121
- require "tempfile"
122
- require "fileutils"
123
-
124
- if target_rbconfig.path
125
- warn "--target-rbconfig is not yet supported for Rust extensions. Ignoring"
126
- end
127
-
128
- # Where's the Cargo.toml of the crate we're building
129
- cargo_toml = File.join(cargo_dir, "Cargo.toml")
130
- # What's the crate's name
131
- crate_name = cargo_crate_name(cargo_dir, cargo_toml, results)
132
-
133
- # Run the build
134
- cmd = cargo_command(cargo_toml, cargo_dir, args, crate_name)
135
- runner.call(cmd, results, "cargo", cargo_dir, build_env)
136
-
137
- # Where do we expect Cargo to write the compiled library
138
- dylib_path = cargo_dylib_path(cargo_dir, crate_name)
139
-
140
- # Helpful error if we didn't find the compiled library
141
- raise DylibNotFoundError, cargo_dir unless File.exist?(dylib_path)
142
-
143
- # Cargo and Ruby differ on how the library should be named, rename from
144
- # what Cargo outputs to what Ruby expects
145
- dlext_name = "#{crate_name}.#{makefile_config("DLEXT")}"
146
- dlext_path = File.join(File.dirname(dylib_path), dlext_name)
147
- FileUtils.cp(dylib_path, dlext_path)
148
-
149
- nesting = extension_nesting(extension)
150
-
151
- if Gem.install_extension_in_lib && lib_dir
152
- nested_lib_dir = File.join(lib_dir, nesting)
153
- FileUtils.mkdir_p nested_lib_dir
154
- FileUtils.cp_r dlext_path, nested_lib_dir, remove_destination: true
155
- end
156
-
157
- # move to final destination
158
- nested_dest_path = File.join(dest_path, nesting)
159
- FileUtils.mkdir_p nested_dest_path
160
- FileUtils.cp_r dlext_path, nested_dest_path, remove_destination: true
161
-
162
- results
163
- end
164
- end
165
127
  end
166
128
  end
129
+
130
+ require_relative "cargotask/cargo_builder"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kar
3
3
  version: !ruby/object:Gem::Version
4
- version: '6'
4
+ version: '8'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kitaiti Makoto
@@ -66,7 +66,7 @@ dependencies:
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  description: Rake utilities such as task to download, DSL to define multiple tasks
69
- at onece, etc.
69
+ at once, etc.
70
70
  email:
71
71
  - KitaitiMakoto@gmail.com
72
72
  executables: []
@@ -80,6 +80,7 @@ files:
80
80
  - kar.gemspec
81
81
  - lib/kar.rb
82
82
  - lib/kar/cargotask.rb
83
+ - lib/kar/cargotask/cargo_builder.rb
83
84
  - lib/kar/dsl.rb
84
85
  - lib/kar/uritask.rb
85
86
  - sig/kar.rbs
@@ -104,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
105
  - !ruby/object:Gem::Version
105
106
  version: '0'
106
107
  requirements: []
107
- rubygems_version: 3.7.2
108
+ rubygems_version: 4.0.16
108
109
  specification_version: 4
109
110
  summary: Rake utilities
110
111
  test_files: []