Class: HelixRuntime::Project
- Inherits:
-
Object
- Object
- HelixRuntime::Project
show all
- Defined in:
- lib/helix_runtime/project.rb
Defined Under Namespace
Classes: OutdatedBuildError
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(root) ⇒ Project
Returns a new instance of Project.
17
18
19
20
21
|
# File 'lib/helix_runtime/project.rb', line 17
def initialize(root)
@root = find_root(root)
@debug_rust = ENV['DEBUG_RUST']
@build_root = @root
end
|
Instance Attribute Details
#build_root ⇒ Object
Returns the value of attribute build_root.
15
16
17
|
# File 'lib/helix_runtime/project.rb', line 15
def build_root
@build_root
end
|
#debug_rust ⇒ Object
Returns the value of attribute debug_rust.
14
15
16
|
# File 'lib/helix_runtime/project.rb', line 14
def debug_rust
@debug_rust
end
|
#helix_lib_dir ⇒ Object
Returns the value of attribute helix_lib_dir.
13
14
15
|
# File 'lib/helix_runtime/project.rb', line 13
def helix_lib_dir
@helix_lib_dir
end
|
#root ⇒ Object
Returns the value of attribute root.
12
13
14
|
# File 'lib/helix_runtime/project.rb', line 12
def root
@root
end
|
Instance Method Details
#autobuild ⇒ Object
65
66
67
|
# File 'lib/helix_runtime/project.rb', line 65
def autobuild
build if outdated_build?
end
|
#build ⇒ Object
123
124
125
|
# File 'lib/helix_runtime/project.rb', line 123
def build
cargo_build && copy_native
end
|
#build_path ⇒ Object
35
36
37
|
# File 'lib/helix_runtime/project.rb', line 35
def build_path
File.expand_path(debug_rust? ? 'target/debug' : 'target/release', build_root)
end
|
#cargo_build ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/helix_runtime/project.rb', line 69
def cargo_build
HelixRuntime.ensure_dll!
link_args = if IS_WINDOWS
if `rustc -vV` =~ /host:\s+i686/
'/SAFESEH:NO' end
else
'-Wl,-undefined,dynamic_lookup'
end
env = {}
env['HELIX_LIB_DIR'] = helix_lib_dir if helix_lib_dir
cargo_args = []
rustc_args = []
if ENV['DEBUG_RUST_MACROS']
rustc_args << "--pretty expanded"
rustc_args << "-Z unstable-options"
end
unless debug_rust?
cargo_args << ["--release"]
end
if ENV['VERBOSE']
cargo_args << " --verbose"
end
if link_args
rustc_args << "-C link-args=#{link_args}"
end
unless rustc_args.empty?
cargo_args << "-- #{rustc_args.join(' ')}"
end
run env, "cargo rustc #{cargo_args.join(' ')}"
end
|
#cargo_clean ⇒ Object
111
112
113
|
# File 'lib/helix_runtime/project.rb', line 111
def cargo_clean
run("cargo clean")
end
|
#cargo_toml_path ⇒ Object
31
32
33
|
# File 'lib/helix_runtime/project.rb', line 31
def cargo_toml_path
"#{root}/Cargo.toml"
end
|
#clobber ⇒ Object
127
128
129
130
|
# File 'lib/helix_runtime/project.rb', line 127
def clobber
cargo_clean
FileUtils.rm_f native_path
end
|
#copy_native ⇒ Object
115
116
117
118
119
120
121
|
# File 'lib/helix_runtime/project.rb', line 115
def copy_native
source = "#{build_path}/#{native_lib}"
raise "native source doesn't exist, run `cargo_build` first; source=#{source}" unless File.exist?(source)
FileUtils.mkdir_p(File.dirname(native_path))
FileUtils.cp source, native_path
true
end
|
#debug_rust? ⇒ Boolean
23
24
25
|
# File 'lib/helix_runtime/project.rb', line 23
def debug_rust?
!!debug_rust
end
|
#ensure_built! ⇒ Object
61
62
63
|
# File 'lib/helix_runtime/project.rb', line 61
def ensure_built!
raise OutdatedBuildError.new(name) if outdated_build?
end
|
#lib_path ⇒ Object
39
40
41
|
# File 'lib/helix_runtime/project.rb', line 39
def lib_path
"#{root}/lib/#{name}"
end
|
#libfile_prefix ⇒ Object
43
44
45
|
# File 'lib/helix_runtime/project.rb', line 43
def libfile_prefix
IS_WINDOWS ? '' : 'lib'
end
|
#name ⇒ Object
27
28
29
|
# File 'lib/helix_runtime/project.rb', line 27
def name
@name ||= Tomlrb.load_file(cargo_toml_path)["package"]["name"]
end
|
#native_lib ⇒ Object
51
52
53
|
# File 'lib/helix_runtime/project.rb', line 51
def native_lib
"#{libfile_prefix}#{name.gsub('-', '_')}.#{Platform.libext}"
end
|
#native_path ⇒ Object
47
48
49
|
# File 'lib/helix_runtime/project.rb', line 47
def native_path
"#{lib_path}/native.#{Platform.dlext}"
end
|
#outdated_build? ⇒ Boolean
55
56
57
58
59
|
# File 'lib/helix_runtime/project.rb', line 55
def outdated_build?
mtime = Dir["#{root}/src/**/*.rs"].map{|file| File.mtime(file) }.max
native = "#{root}/lib/#{name}/native.#{Platform.dlext}"
!File.exist?(native) || File.mtime(native) < mtime
end
|