This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcommon.toml
185 lines (150 loc) · 5.84 KB
/
common.toml
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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
### ENVIRONMENT VARIABLES ######################################################
# You'll probably want to overwrite $TITLE and $TITLEID with values specific
# to your project. Set $STATIC_DIR to change the directory for static files:
# default is `static`.
[env]
# Project information
TITLE = "Rust Project"
TITLEID = "RUST00001"
# Build configuration
STATIC_DIR = "static"
CARGO_TARGET_DIR = { script = ["echo ${CARGO_TARGET_DIR:=target}"] }
RUST_TARGET_PATH = { script = ["echo ${RUST_TARGET_PATH:=$(echo \"$(rustc --print sysroot)/share/targets\")}"]}
# Compilation specific
RUST_TARGET = "armv7-vita-eabihf"
CARGO_OUT_DIR = "${CARGO_TARGET_DIR}/${RUST_TARGET}/release"
TARGET_CC="arm-vita-eabi-gcc"
TARGET_LINKER = "arm-vita-eabi-gcc"
TARGET_LINKER_FLAGS = "-Wl,-q"
TARGET_LINKER_SPECS = "${CARGO_OUT_DIR}/specs"
### CLEAN ######################################################################
[tasks.clean-common]
description = "Clean the `common.toml` file from the project directory."
script_runner = "@shell"
script = ["rm -f common.toml"]
[tasks.clean]
dependencies = ["clean-common"]
### DEFAULT: VPK ###############################################################
[tasks.default]
alias = "vpk"
### COMPILER SPECS #############################################################
[tasks.patch-cc-specs]
description = "Remove default `libc` linkage from the linker specs."
script_runner = "@rust"
script = [
"""
use std::io::Write;
fn main() {
// create target specs directory
let specs_file = std::path::PathBuf::from(env!("TARGET_LINKER_SPECS"));
std::fs::create_dir(specs_file.parent().expect("invalid path to specs file"));
// dump linker specs
let out = std::process::Command::new(env!("TARGET_LINKER"))
.arg("-dumpspecs")
.stdout(std::process::Stdio::piped())
.output()
.expect("failed to extract linker specs");
// remove libc linker flags
let specs = String::from_utf8(out.stdout)
.expect("linker did not produce UTF-8 output")
.replace("%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}", "")
.replace("crt0%O%s", "");
// write to specs_file
let x = std::fs::File::create(specs_file)
.expect("could not open specs file")
.write_all(specs.as_bytes())
.expect("could not write specs file");
}
"""
]
[tasks.get-target-specs]
description = "Download target specs from the `vita-rust/common` git repository."
env = { TARGET_JSON_URL = "https://github.com/vita-rust/common/raw/master/${RUST_TARGET}.json"}
condition = { env_set = ["RUST_TARGET_PATH"] }
condition_script = [ 'test ! -f "${RUST_TARGET_PATH}/${RUST_TARGET}.json"' ]
script = [
'mkdir -p "${RUST_TARGET_PATH}"',
'curl -SsL "${TARGET_JSON_URL}" > "${RUST_TARGET_PATH}/${RUST_TARGET}.json"',
]
### BUILD ######################################################################
[tasks.xbuild]
description = "Build the project using `xargo`."
dependencies = ["get-target-specs"]
install_crate = "xargo"
command = "xargo"
args = ["build", "--target=armv7-vita-eabihf", "--release", "-vv", "--all-features"]
### DISTRIBUTION TASKS #########################################################
[tasks.elf]
description = "Build an ELF executable using the `vitasdk` linker."
dependencies = ["xbuild", "patch-cc-specs"]
script = [
"""
${TARGET_LINKER} ${TARGET_LINKER_FLAGS} \
-specs="${TARGET_LINKER_SPECS}" \
-L"${CARGO_OUT_DIR}" \
-l"${CARGO_MAKE_CRATE_FS_NAME}" \
-o"${CARGO_OUT_DIR}/${CARGO_MAKE_CRATE_NAME}.elf"
"""
]
[tasks.strip]
description = "Strip the produced ELF executable."
dependencies = ["elf"]
command = "arm-vita-eabi-strip"
args = ["-g", '${CARGO_OUT_DIR}/lib${CARGO_MAKE_CRATE_FS_NAME}.a']
[tasks.velf]
description = "Build an VELF executable from the obtained ELF file."
dependencies = ["strip"]
command = "vita-elf-create"
args = ['${CARGO_OUT_DIR}/${CARGO_MAKE_CRATE_NAME}.elf', '${CARGO_OUT_DIR}/${CARGO_MAKE_CRATE_NAME}.velf']
[tasks.eboot-bin]
description = "Build an `eboot.bin` file fromt the obtained VELF file."
dependencies = ["velf"]
command = "vita-make-fself"
args = ["-s", '${CARGO_OUT_DIR}/${CARGO_MAKE_CRATE_NAME}.velf', '${CARGO_OUT_DIR}/eboot.bin']
[tasks.param-sfo]
description = "Build the `param.sfo` manifest using with given TITLE and TITLEID."
command = "vita-mksfoex"
args = ["-s", 'TITLE_ID=${TITLEID}', '${TITLE}', '${CARGO_OUT_DIR}/param.sfo']
[tasks.manifest]
description = "List all static resources into a manifest file."
script = [
'mkdir -p "${CARGO_OUT_DIR}"',
'''
if [ -d "${STATIC_DIR}" ]; then
find "${STATIC_DIR}" -type f > "${CARGO_OUT_DIR}/MANIFEST"
else
touch "${CARGO_OUT_DIR}/MANIFEST"
fi
'''
]
[tasks.vpk]
description = "Build a VPK distribution of the project executable and resources."
dependencies = ["eboot-bin", "param-sfo", "manifest"]
script_runner = "@rust"
script = [
'''
use std::io::BufRead;
use std::fs::File;
fn main() {
let crate_name = env!("CARGO_MAKE_CRATE_NAME");
let static_dir = env!("STATIC_DIR");
let out_dir = std::path::PathBuf::from(env!("CARGO_OUT_DIR"));
let mut cmd = ::std::process::Command::new("vita-pack-vpk");
cmd.arg("-s").arg(out_dir.join("param.sfo"));
cmd.arg("-b").arg(out_dir.join("eboot.bin"));
// Add files from MANIFEST
if let Ok(file) = File::open(out_dir.join("MANIFEST")) {
let mut reader = ::std::io::BufReader::new(file);
let mut lines = reader.lines();
while let Some(Ok(line)) = lines.next() {
let p1 = ::std::path::PathBuf::from(line); // path on FS
let p2 = p1.strip_prefix(static_dir).unwrap(); // path in VPK
cmd.arg("--add").arg(format!("{}={}", p1.display(), p2.display()));
}
}
cmd.arg(out_dir.join(format!("{}.vpk", crate_name)))
.output()
.expect("command failed.");
}
'''
]