gem-ext-zig_builder 0.1.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gem/ext/zig_builder/version.rb +1 -1
- data/lib/gem/ext/zig_builder.rb +71 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67f8fea71de7a4772677938160444683b01d4d3aa96e55b1f719d108aa99c0d8
|
4
|
+
data.tar.gz: 06b828adf36c78a949231c482130021d91022fcf625635b23750e92417b8ae36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c2088d9a06d0efaf5e17cdbc421b967b05e55077f0c95428ac5b8e9c283b9181c13599848b4639cec0f9b9a9783d2b235075edc49b8ca22ab6d8802071a380e
|
7
|
+
data.tar.gz: 8ca3d7df154f3eadc672c88be8ea0ed3e88fa88dd7602528a9687c47fa067a3471c610268bcbc4cfa76e228df7748915f72c7bc77b54696eb75c376f428996e7
|
data/lib/gem/ext/zig_builder.rb
CHANGED
@@ -4,6 +4,7 @@ require 'rubygems/ext/builder'
|
|
4
4
|
require 'rubygems/command'
|
5
5
|
require 'shellwords'
|
6
6
|
require 'rbconfig'
|
7
|
+
require 'tmpdir'
|
7
8
|
|
8
9
|
class Gem::Ext::ZigBuilder < Gem::Ext::Builder
|
9
10
|
module PatchBuilderLookup
|
@@ -12,24 +13,81 @@ class Gem::Ext::ZigBuilder < Gem::Ext::Builder
|
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
ENV['PKG_CONFIG_PATH'] = "#{RbConfig::CONFIG['libdir']}/pkgconfig"
|
19
|
-
ENV['RUBY_PC' ] = "#{File.basename(RbConfig::CONFIG['ruby_pc'], '.pc')}"
|
16
|
+
class <<self
|
17
|
+
def build(extension, dest_path, results, args=[], lib_dir=nil, extension_dir=nil)
|
18
|
+
_set_vars
|
20
19
|
|
21
|
-
|
20
|
+
tmp_dir = Dir.mktmpdir
|
21
|
+
cmd = _build_command(tmp_dir)
|
22
|
+
env = _build_env
|
23
|
+
|
24
|
+
_run(cmd, results, 'zig', extension_dir, env)
|
25
|
+
_install_artifacts(tmp_dir, dest_path)
|
26
|
+
|
27
|
+
results
|
28
|
+
ensure
|
29
|
+
FileUtils.remove_entry tmp_dir if tmp_dir
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def _set_vars
|
35
|
+
@dlext = RbConfig::CONFIG['DLEXT']
|
36
|
+
@target_vendor = RbConfig::CONFIG['target_vendor']
|
37
|
+
@pkg_config_path = "#{RbConfig::CONFIG['libdir']}/pkgconfig"
|
38
|
+
@ruby_pc = "#{File.basename(RbConfig::CONFIG['ruby_pc'], '.pc')}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def _build_command(tmp_dir)
|
22
42
|
[].tap {|c|
|
23
43
|
c << 'zig' << 'build' << '-Doptimize=ReleaseSafe'
|
24
|
-
c << '--prefix-lib-dir' <<
|
44
|
+
c << '--prefix-lib-dir' << tmp_dir
|
25
45
|
c << 'test' << 'install'
|
26
|
-
}
|
27
|
-
|
28
|
-
'zig',
|
29
|
-
extension_dir
|
30
|
-
)
|
46
|
+
}
|
47
|
+
end
|
31
48
|
|
32
|
-
|
49
|
+
def _build_env
|
50
|
+
{
|
51
|
+
'PKG_CONFIG_PATH' => @pkg_config_path,
|
52
|
+
'RUBY_PC' => @ruby_pc,
|
53
|
+
}.tap do |env|
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def _run(command, results, command_name, dir, env)
|
58
|
+
case method(:run).parameters.count
|
59
|
+
when 3
|
60
|
+
# old versions do not support the 4th `dir` arg
|
61
|
+
# old versions do not support the 5th `env` arg
|
62
|
+
_pollute_env(env)
|
63
|
+
run(command, results, command_name)
|
64
|
+
when 4
|
65
|
+
# old versions do not support the 5th `env` arg
|
66
|
+
_pollute_env(env)
|
67
|
+
run(command, results, command_name, dir)
|
68
|
+
when 5
|
69
|
+
run(command, results, command_name, dir, env)
|
70
|
+
else
|
71
|
+
raise ArgumentError.new('wrong number of arguments')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def _pollute_env(env)
|
76
|
+
env.each do |k,v| ENV[k] = v end
|
77
|
+
end
|
78
|
+
|
79
|
+
def _install_artifacts(tmp_dir, dest_path)
|
80
|
+
Dir.chdir tmp_dir do
|
81
|
+
if @target_vendor == 'apple' && @dlext == 'bundle'
|
82
|
+
# zig builds a .dylib but ruby wants to load a .bundle
|
83
|
+
Dir.glob('*.dylib').each do |dylib|
|
84
|
+
FileUtils.mv dylib, "#{File.basename(dylib, '.dylib')}.bundle"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
FileUtils.mv Dir.glob("*.#@dlext"), dest_path
|
89
|
+
end
|
90
|
+
end
|
33
91
|
end
|
34
92
|
end
|
35
93
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem-ext-zig_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank J. Cameron
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ''
|
14
14
|
email:
|