-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
711 lines (614 loc) · 24.1 KB
/
main.rs
File metadata and controls
711 lines (614 loc) · 24.1 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
use anyhow::{Context, Result, bail};
use cargo_metadata::{
Message as CargoMessage, MetadataCommand,
semver::{BuildMetadata, Prerelease},
};
use rustc_version::{Channel, Version};
use std::{
collections::HashSet,
env, fmt, fs,
io::ErrorKind,
process::{Command, Stdio},
};
mod fix_imports;
const CONFIG_NAME: &str = "Psp.toml";
#[derive(serde_derive::Deserialize, Default)]
struct PspConfig {
/// Title shown in the XMB menu.
title: Option<String>,
/// Path to 24bit 144x80 PNG icon shown in the XMB menu.
xmb_icon_png: Option<String>,
/// Path to animated icon shown in the XMB menu.
///
/// The PSP expects a 29.97fps 144x80 PMF video file (custom Sony format).
xmb_icon_pmf: Option<String>,
/// Path to 24bit 480x272 PNG background shown in the XMB menu.
xmb_background_png: Option<String>,
/// Overlay background shown in the XMB menu.
///
/// Exactly like `xmb_background_png`, but it is overlayed on top.
xmb_background_overlay_png: Option<String>,
/// Path to ATRAC3 audio file played in the XMB menu.
///
/// Must be 66kbps, under 500KB and under 55 seconds.
xmb_music_at3: Option<String>,
/// Path to associated PSAR data stored in the EBOOT.
psar: Option<String>,
/// Product number of the game, in the format `ABCD-12345`.
///
/// Example: UCJS-10001
disc_id: Option<String>,
/// Version of the game, e.g. "1.00".
disc_version: Option<String>,
// TODO: enum
/// Language of the game. "JP" indicates Japanese, even though this is not
/// the proper ISO 639 code...
language: Option<String>,
// TODO: enum
/// Parental Control level needed to access the file. 1-11
/// - 1 = General audience
/// - 5 = 12 year old
/// - 7 = 15 year old
/// - 9 = 18 year old
parental_level: Option<u32>,
/// PSP Firmware Version required by the game (e.g. "6.61").
psp_system_ver: Option<String>,
// TODO: document values
/// Bitmask of allowed regions. (0x8000 is region 2?)
region: Option<u32>,
/// Japanese localized title.
title_jp: Option<String>,
/// French localized title.
title_fr: Option<String>,
/// Spanish localized title.
title_es: Option<String>,
/// German localized title.
title_de: Option<String>,
/// Italian localized title.
title_it: Option<String>,
/// Dutch localized title.
title_nl: Option<String>,
/// Portugese localized title.
title_pt: Option<String>,
/// Russian localized title.
title_ru: Option<String>,
/// Used by the firmware updater to denote the firmware version it updates to.
updater_version: Option<String>,
}
#[derive(Ord, PartialOrd, PartialEq, Eq, Debug)]
struct CommitDate {
year: i32,
month: i32,
day: i32,
}
impl CommitDate {
fn parse(date: &str) -> Option<Self> {
let mut iter = date.split('-');
let year = iter.next()?.parse().ok()?;
let month = iter.next()?.parse().ok()?;
let day = iter.next()?.parse().ok()?;
Some(Self { year, month, day })
}
}
impl fmt::Display for CommitDate {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:04}-{:02}-{:02}", self.year, self.month, self.day)
}
}
impl core::ops::Add<CommitDate> for CommitDate {
type Output = CommitDate;
fn add(self, rhs: CommitDate) -> Self::Output {
Self {
year: self.year + rhs.year,
month: self.month + rhs.month,
day: self.day + rhs.day,
}
}
}
// Minimum 2023-03-27, remember to update both commit date and version too,
// below. Note that the `day` field lags by one day, as the toolchain always
// contains the previous days' nightly rustc.
const MINIMUM_COMMIT_DATE: CommitDate = CommitDate {
year: 2025,
month: 3,
day: 18,
};
const MINIMUM_RUSTC_VERSION: Version = Version {
major: 1,
minor: 87,
patch: 0,
pre: Prerelease::EMPTY,
build: BuildMetadata::EMPTY,
};
/// Generate a custom target JSON from the built-in `mipsel-sony-psp` spec
/// with `metadata.std` set to `true`. This prevents rustc from setting the
/// `restricted_std` cfg, allowing third-party crates (serde, toml, etc.) to
/// use std without `#![feature(restricted_std)]`.
///
/// Returns the path to the generated JSON file.
fn generate_std_target_json() -> Result<std::path::PathBuf> {
let dest_dir = env::current_dir()
.context("failed to get current dir")?
.join("target");
fs::create_dir_all(&dest_dir).context("failed to create target dir")?;
let json_path = dest_dir.join("mipsel-sony-psp-std.json");
// Get the built-in target spec from rustc.
// Respect RUSTC env var for toolchain-aware invocation (e.g. cargo +nightly).
let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string());
let output = Command::new(&rustc)
.args([
"-Z",
"unstable-options",
"--print",
"target-spec-json",
"--target",
"mipsel-sony-psp",
])
.output()
.context("failed to run `rustc --print target-spec-json`")?;
if !output.status.success() {
bail!("`rustc --print target-spec-json` failed");
}
let spec_str = String::from_utf8(output.stdout).context("target spec JSON is not UTF-8")?;
// Parse, patch metadata.std to true, and write back.
let mut spec: serde_json::Value =
serde_json::from_str(&spec_str).context("failed to parse target spec JSON")?;
if let Some(metadata) = spec.get_mut("metadata").and_then(|m| m.as_object_mut()) {
metadata.insert("std".to_string(), serde_json::Value::Bool(true));
}
let patched =
serde_json::to_string_pretty(&spec).context("failed to serialize patched target spec")?;
fs::write(&json_path, &patched).context("failed to write custom target JSON")?;
eprintln!(
"[NOTE]: Generated custom target spec with std=true at {}",
json_path.display(),
);
Ok(json_path)
}
/// Prepare a merged sysroot that overlays PSP PAL files on top of the
/// Check if any workspace member depends on `psp` with the `std` feature enabled.
/// Returns `true` if so, enabling automatic std sysroot preparation.
fn detect_psp_std_feature() -> bool {
let output = Command::new(env::var_os("CARGO").unwrap_or_else(|| "cargo".into()))
.arg("metadata")
.arg("--format-version=1")
.arg("--no-deps")
.stderr(Stdio::null())
.stdout(Stdio::piped())
.output()
.ok();
let output = match output {
Some(o) if o.status.success() => o,
_ => return false,
};
let json = match std::str::from_utf8(&output.stdout) {
Ok(s) => s,
Err(_) => return false,
};
let metadata = match MetadataCommand::parse(json) {
Ok(m) => m,
Err(_) => return false,
};
let workspace_members: HashSet<_> = metadata.workspace_members.iter().collect();
metadata
.packages
.iter()
.filter(|p| workspace_members.contains(&p.id))
.flat_map(|p| &p.dependencies)
.any(|dep| dep.name == "psp" && dep.features.iter().any(|f| f == "std"))
}
/// standard rust-src component. The merged directory is placed at
/// `target/psp-std-sysroot/` and reused across builds.
fn prepare_psp_sysroot() -> Result<()> {
use std::path::Path;
use std::time::SystemTime;
// Locate the installed rust-src component.
// Respect RUSTC env var for toolchain-aware invocation (e.g. cargo +nightly).
let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string());
let sysroot_output = Command::new(&rustc)
.arg("--print")
.arg("sysroot")
.output()
.context("failed to run `rustc --print sysroot`")?;
if !sysroot_output.status.success() {
bail!("`rustc --print sysroot` failed");
}
let sysroot =
String::from_utf8(sysroot_output.stdout).context("rustc sysroot path is not UTF-8")?;
let sysroot = sysroot.trim();
let rust_src = Path::new(sysroot).join("lib/rustlib/src/rust");
if !rust_src.join("library/std").exists() {
bail!(
"rust-src component not found at {}.\n\
Please run: rustup component add rust-src",
rust_src.display()
);
}
// Locate our PSP overlay source.
// Walk up from the current dir to find the repo root containing rust-std-src/.
let overlay_src = find_repo_root()?.join("rust-std-src");
if !overlay_src.join("library").exists() {
bail!(
"PSP std overlay not found at {}.\n\
Expected rust-std-src/library/ in the repository root.",
overlay_src.display()
);
}
let dest = env::current_dir()
.context("failed to get current dir")?
.join("target")
.join("psp-std-sysroot");
// Check if we can skip re-creating the sysroot.
let marker = dest.join(".psp-sysroot-stamp");
if marker.exists() {
// Re-create if overlay or rust-src is newer than the marker.
let marker_time = fs::metadata(&marker)
.and_then(|m| m.modified())
.unwrap_or(SystemTime::UNIX_EPOCH);
let overlay_modified = newest_mtime(&overlay_src)?;
let rust_src_modified = fs::metadata(rust_src.join("library/Cargo.lock"))
.and_then(|m| m.modified())
.unwrap_or_else(|_| SystemTime::now());
if overlay_modified <= marker_time && rust_src_modified <= marker_time {
eprintln!("[NOTE]: PSP sysroot is up-to-date, skipping preparation.");
return Ok(());
}
}
eprintln!("[NOTE]: Preparing PSP std sysroot at {}", dest.display());
// Clean and recreate.
if dest.exists() {
fs::remove_dir_all(&dest).context("failed to remove old sysroot")?;
}
fs::create_dir_all(&dest).context("failed to create sysroot dir")?;
// Copy the base rust-src files we need.
copy_dir_recursive(&rust_src.join("library"), &dest.join("library"))?;
// Copy the src directory if it exists (some toolchains include it).
let src_dir = rust_src.join("src");
if src_dir.exists() {
copy_dir_recursive(&src_dir, &dest.join("src"))?;
}
// Overlay our PSP-specific files on top.
copy_dir_recursive(&overlay_src.join("library"), &dest.join("library"))?;
// Patch std's lib.rs to make it unconditionally stable.
//
// Cargo's -Zbuild-std ALWAYS passes `--cfg restricted_std` for custom
// targets, which makes std an unstable library that requires
// `#![feature(restricted_std)]` in every downstream crate (including
// third-party crates like serde). The `metadata.std` field in the target
// JSON is informational only -- cargo ignores it.
//
// We patch the two conditional stability attributes:
// #![cfg_attr(not(restricted_std), stable(...))] -> #![stable(...)]
// #![cfg_attr(restricted_std, unstable(...))] -> removed
patch_std_stability(&dest.join("library/std/src/lib.rs"))?;
// Write a timestamp marker.
fs::write(&marker, "").context("failed to write sysroot stamp")?;
eprintln!("[NOTE]: PSP std sysroot prepared successfully.");
Ok(())
}
/// Patch `library/std/src/lib.rs` so std is unconditionally stable.
///
/// Cargo's `-Zbuild-std` passes `--cfg restricted_std` for every custom
/// target. That cfg selects the `unstable(feature = "restricted_std")`
/// stability attribute, which forces every downstream crate to carry
/// `#![feature(restricted_std)]` -- including third-party crates.
///
/// This function rewrites the two conditional attributes:
/// `#![cfg_attr(not(restricted_std), stable(...))]` -> `#![stable(...)]`
/// `#![cfg_attr(restricted_std, unstable(...))]` -> disabled
fn patch_std_stability(lib_rs: &std::path::Path) -> Result<()> {
let content = fs::read_to_string(lib_rs)
.with_context(|| format!("failed to read {}", lib_rs.display()))?;
// Replace the conditional stable attribute with an unconditional one.
let patched = content.replace(
"#![cfg_attr(not(restricted_std), stable(feature = \"rust1\", since = \"1.0.0\"))]",
"#![stable(feature = \"rust1\", since = \"1.0.0\")]",
);
// Disable the restricted_std unstable attribute by changing the condition
// to `any()` (always false), so it never applies even with --cfg restricted_std.
let patched = patched.replace(
"cfg_attr(\n restricted_std,\n unstable(\n feature = \"restricted_std\",",
"cfg_attr(\n any(), /* patched: PSP std is stable */\n unstable(\n feature = \"restricted_std\",",
);
if patched == content {
eprintln!(
"[WARN]: Could not find restricted_std attributes to patch in {}",
lib_rs.display()
);
} else {
fs::write(lib_rs, &patched)
.with_context(|| format!("failed to write patched {}", lib_rs.display()))?;
eprintln!("[NOTE]: Patched std stability attributes (removed restricted_std gate).");
}
Ok(())
}
/// Find the repository root by walking up from the current directory,
/// looking for a directory containing `rust-std-src/`.
fn find_repo_root() -> Result<std::path::PathBuf> {
let mut dir = env::current_dir().context("failed to get current dir")?;
loop {
if dir.join("rust-std-src").exists() {
return Ok(dir);
}
if !dir.pop() {
bail!(
"could not find repository root (looking for rust-std-src/ directory).\n\
Make sure you're building from within the rust-psp repository."
);
}
}
}
/// Recursively copy a directory. If files exist at the destination, they are
/// overwritten (this is used for the overlay step).
fn copy_dir_recursive(src: &std::path::Path, dst: &std::path::Path) -> Result<()> {
if !dst.exists() {
fs::create_dir_all(dst)
.with_context(|| format!("failed to create dir {}", dst.display()))?;
}
for entry in
fs::read_dir(src).with_context(|| format!("failed to read dir {}", src.display()))?
{
let entry = entry?;
let file_type = entry.file_type()?;
let src_path = entry.path();
let dst_path = dst.join(entry.file_name());
if file_type.is_dir() {
copy_dir_recursive(&src_path, &dst_path)?;
} else {
fs::copy(&src_path, &dst_path).with_context(|| {
format!(
"failed to copy {} -> {}",
src_path.display(),
dst_path.display()
)
})?;
}
}
Ok(())
}
/// Get the newest modification time of any file under a directory.
fn newest_mtime(dir: &std::path::Path) -> Result<std::time::SystemTime> {
let mut newest = std::time::SystemTime::UNIX_EPOCH;
for entry in
fs::read_dir(dir).with_context(|| format!("failed to read dir {}", dir.display()))?
{
let entry = entry?;
let file_type = entry.file_type()?;
let path = entry.path();
if file_type.is_dir() {
let sub = newest_mtime(&path)?;
if sub > newest {
newest = sub;
}
} else if let Ok(meta) = fs::metadata(&path)
&& let Ok(mtime) = meta.modified()
&& mtime > newest
{
newest = mtime;
}
}
Ok(newest)
}
fn main() -> Result<()> {
let rustc_version = rustc_version::version_meta().context("failed to query rustc version")?;
if rustc_version.channel > Channel::Nightly {
bail!(
"cargo-psp requires a nightly rustc version.\n\
Please run `rustup override set nightly` to use nightly in the \
current directory."
);
}
let old_version = MINIMUM_RUSTC_VERSION
> Version {
// Remove `-nightly` pre-release tag for comparison.
pre: Prerelease::EMPTY,
..rustc_version.semver.clone()
};
let old_commit = match rustc_version.commit_date {
None => false,
Some(date) => {
MINIMUM_COMMIT_DATE
> CommitDate::parse(&date)
.context("could not parse `rustc --version` commit date")?
},
};
if old_version || old_commit {
bail!(
"cargo-psp requires rustc nightly version >= {}\n\
Please run `rustup update nightly` to upgrade your nightly version",
MINIMUM_COMMIT_DATE
+ CommitDate {
year: 0,
month: 0,
day: 1
},
);
}
let config: PspConfig = match fs::read_to_string(CONFIG_NAME) {
Ok(value) => toml::from_str(&value)
.context("failed to parse Psp.toml -- please ensure it is formatted correctly")?,
Err(e) if e.kind() == ErrorKind::NotFound => PspConfig::default(),
Err(e) => return Err(e).context("failed to read Psp.toml")?,
};
// Skip `cargo psp`
let args = env::args().skip(2);
let build_std = env::var("RUST_PSP_BUILD_STD").is_ok() || detect_psp_std_feature();
let build_std_flag = if build_std {
eprintln!("[NOTE]: Building with full std support for PSP.");
"build-std=std,core,alloc,panic_unwind,panic_abort"
} else {
"build-std=core,compiler_builtins,alloc,panic_unwind,panic_abort"
};
// When building full std, prepare a merged sysroot that overlays PSP PAL
// files and generate a custom target JSON with metadata.std = true so that
// rustc does not apply the restricted_std stability gate to downstream crates.
let target_arg: std::ffi::OsString = if build_std {
prepare_psp_sysroot().context("failed to prepare PSP std sysroot")?;
let json_path =
generate_std_target_json().context("failed to generate custom target JSON")?;
json_path.into_os_string()
} else {
"mipsel-sony-psp".into()
};
let cargo = env::var_os("CARGO").unwrap_or_else(|| "cargo".into());
let mut build_cmd = Command::new(&cargo);
build_cmd
.arg("build")
.arg("-Z")
.arg(build_std_flag)
.arg("--target")
.arg(&target_arg)
.arg("--message-format=json-render-diagnostics");
// Newer nightlies (post Jan 2026) destabilized custom JSON target specs
// and require -Zjson-target-spec when using a .json target path.
if build_std {
build_cmd.arg("-Z").arg("json-target-spec");
}
build_cmd.args(args).stdout(Stdio::piped());
if build_std {
// __CARGO_TESTS_ONLY_SRC_ROOT must point to the workspace root
// containing Cargo.toml (i.e. the library/ directory).
let sysroot_dir = env::current_dir()
.context("failed to get current dir")?
.join("target")
.join("psp-std-sysroot")
.join("library");
build_cmd.env("__CARGO_TESTS_ONLY_SRC_ROOT", &sysroot_dir);
}
let mut build_process = build_cmd.spawn().context("failed to spawn `cargo build`")?;
let lone = {
let output = Command::new(cargo)
.arg("metadata")
.arg("--format-version=1")
.arg("-Z")
.arg(build_std_flag)
.stderr(Stdio::inherit())
.output()
.context("failed to run `cargo metadata`")?;
if !output.status.success() {
bail!(
"`cargo metadata` command exited with status: {:?}",
output.status
);
}
let metadata = MetadataCommand::parse(
std::str::from_utf8(&output.stdout)
.context("`cargo metadata` returned non-UTF-8 bytes")?,
)
.context("failed to parse `cargo metadata` stdout")?;
let workspace_members: HashSet<_> = metadata.workspace_members.iter().collect();
let total_executables = metadata
.packages
.iter()
.filter(|p| workspace_members.contains(&p.id))
.flat_map(|p| &p.targets)
.filter(|t| t.crate_types.iter().any(|ct| *ct == "bin".into()))
.count();
total_executables == 1
};
let reader = std::io::BufReader::new(
build_process
.stdout
.take()
.context("failed to capture cargo build stdout")?,
);
let built_executables: Vec<_> = CargoMessage::parse_stream(reader)
.filter_map(|msg| msg.ok())
.flat_map(|msg| match msg {
CargoMessage::CompilerArtifact(art) => art.executable,
_ => None,
})
.collect();
let status = build_process
.wait()
.context("failed to wait for `cargo build`")?;
if !status.success() {
bail!("`cargo build` command exited with status: {:?}", status);
}
// TODO: Error if no bin is ever found.
for elf_path in built_executables {
let prx_path = elf_path.with_extension("prx");
let [sfo_path, pbp_path] = ["PARAM.SFO", "EBOOT.PBP"].map(|e| {
if lone {
elf_path.with_file_name(e)
} else {
elf_path.with_extension(e)
}
});
fix_imports::fix(&elf_path).context("fix_imports failed")?;
let status = Command::new("prxgen")
.arg(&elf_path)
.arg(&prx_path)
.status()
.context("failed to run prxgen")?;
if !status.success() {
bail!("prxgen failed: {}", status);
}
let config_args = vec![
("-s", "DISC_ID", config.disc_id.clone()),
("-s", "DISC_VERSION", config.disc_version.clone()),
("-s", "LANGUAGE", config.language.clone()),
(
"-d",
"PARENTAL_LEVEL",
config.parental_level.as_ref().map(u32::to_string),
),
("-s", "PSP_SYSTEM_VER", config.psp_system_ver.clone()),
("-d", "REGION", config.region.as_ref().map(u32::to_string)),
("-s", "TITLE_0", config.title_jp.clone()),
("-s", "TITLE_2", config.title_fr.clone()),
("-s", "TITLE_3", config.title_es.clone()),
("-s", "TITLE_4", config.title_de.clone()),
("-s", "TITLE_5", config.title_it.clone()),
("-s", "TITLE_6", config.title_nl.clone()),
("-s", "TITLE_7", config.title_pt.clone()),
("-s", "TITLE_8", config.title_ru.clone()),
("-s", "UPDATER_VER", config.updater_version.clone()),
];
let status = Command::new("mksfo")
// Add the optional config args
.args({
config_args
.into_iter()
// Filter through all the values that are not `None`
.filter_map(|(f, k, v)| v.map(|v| (f, k, v)))
// Map into 2 arguments, e.g. "-s" "NAME=VALUE"
.flat_map(|(flag, key, value)| vec![flag.into(), format!("{}={}", key, value)])
})
.arg(
config
.title
.as_ref()
.map(|s| s.as_ref())
.or_else(|| elf_path.file_stem())
.context("could not determine title: no title in Psp.toml and ELF path has no file stem")?,
)
.arg(&sfo_path)
.status()
.context("failed to run mksfo")?;
if !status.success() {
bail!("mksfo failed: {}", status);
}
let status = Command::new("pack-pbp")
.arg(&pbp_path)
.arg(&sfo_path)
.arg(config.xmb_icon_png.as_deref().unwrap_or("NULL"))
.arg(config.xmb_icon_pmf.as_deref().unwrap_or("NULL"))
.arg(
config
.xmb_background_overlay_png
.as_deref()
.unwrap_or("NULL"),
)
.arg(config.xmb_background_png.as_deref().unwrap_or("NULL"))
.arg(config.xmb_music_at3.as_deref().unwrap_or("NULL"))
.arg(&prx_path)
.arg(config.psar.as_deref().unwrap_or("NULL"))
.status()
.context("failed to run pack-pbp")?;
if !status.success() {
bail!("pack-pbp failed: {}", status);
}
}
Ok(())
}