This repository has been archived by the owner on Jun 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.rb
78 lines (67 loc) · 1.89 KB
/
cli.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env ruby
require 'thor'
require 'fileutils'
class CLI < Thor
include Thor::Actions
def initialize(*args)
super(*args)
@curr_dir = File.expand_path('.', __dir__)
end
desc 'launch [ARGS]', 'launch program in docker image'
def launch(*args)
uid = `id -u`.strip
gid = `id -g`.strip
args_line = args.collect(&:inspect).join(' ')
# linux cargo home
cargo_home = File.join(Dir.home, '.cargo-linux')
FileUtils.mkdir_p(cargo_home)
# puts "cargo_home = #{cargo_home}"
cmdline = [
%(docker run),
%(--rm),
%(--userns host),
%(--user "#{uid}:#{gid}"),
%(-e "CARGO_HOME=/cargo"),
%(-v "#{cargo_home}:/cargo:rw"),
%(-v "#{@curr_dir}:/project:ro"),
%(-v "#{@curr_dir}/target:/project/target:rw"),
%(-w /project),
%(-it rust),
args_line
].join(' ')
if ENV['DRY_RUN'] == '1'
puts cmdline
else
run cmdline
end
end
desc 'build_linux', 'run cargo build --release --target x86_64-unknown-linux-gnu'
def build_linux(*args)
launch('cargo', 'build', '--release', '--target', 'x86_64-unknown-linux-gnu', *args)
end
desc 'build_yscript', 'build yscript for linux'
def build_yscript(*args)
build_linux('-p', 'yscript')
inside(@curr_dir) do
run %(cp ./target/x86_64-unknown-linux-gnu/release/yscript ./containers/bin/yscript)
end
end
desc 'build_yeditor', 'build yeditor for linux'
def build_yeditor(*args)
build_linux('-p', 'yeditor')
end
desc 'watch [PROJECT]', 'watch project changes and run'
def watch(project = 'yeditor')
project_dir = File.join(@curr_dir, project)
inside(project_dir) do
# run %(systemfd --no-pid -s tcp::127.0.0.1:4000 -- cargo watch -x run)
run %(cargo watch -x run)
end
end
end
CLI.start if caller.empty?
##
## Usage:
## Drop this cli.rb file beside Cargo.toml and run
## ./cli.rb build_linux
##