Skip to content

Commit

Permalink
Merge pull request #63 from rust3ds/fix/dont-always-link
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-h-chamberlain committed Jun 19, 2024
2 parents 7fd38e2 + e3d83cd commit 30fef76
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 67 deletions.
36 changes: 0 additions & 36 deletions .github/actions/setup/action.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Checkout branch
uses: actions/checkout@v2

- uses: ./.github/actions/setup
- uses: rust3ds/actions/setup@v1
with:
toolchain: ${{ matrix.toolchain }}

Expand All @@ -53,7 +53,7 @@ jobs:
- name: Checkout branch
uses: actions/checkout@v3

- uses: ./.github/actions/setup
- uses: rust3ds/actions/setup@v1
with:
toolchain: ${{ matrix.toolchain }}

Expand Down
30 changes: 11 additions & 19 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub struct New {

impl CargoCmd {
/// Returns the additional arguments run by the "official" cargo subcommand.
pub fn cargo_args(&self) -> Vec<String> {
pub(crate) fn cargo_args(&self) -> Vec<String> {
match self {
CargoCmd::Build(build) => build.passthrough.cargo_args(),
CargoCmd::Run(run) => run.build_args.passthrough.cargo_args(),
Expand All @@ -185,7 +185,7 @@ impl CargoCmd {
/// This is not equivalent to the lowercase name of the [`CargoCmd`] variant.
/// Commands may use different commands under the hood to function (e.g. [`CargoCmd::Run`] uses `build`
/// if no custom runner is configured).
pub fn subcommand_name(&self) -> &str {
pub(crate) fn subcommand_name(&self) -> &str {
match self {
CargoCmd::Build(_) => "build",
CargoCmd::Run(run) => {
Expand All @@ -202,7 +202,7 @@ impl CargoCmd {
}

/// Whether or not this command should compile any code, and thus needs import the custom environment configuration (e.g. target spec).
pub fn should_compile(&self) -> bool {
pub(crate) fn should_compile(&self) -> bool {
matches!(
self,
Self::Build(_) | Self::Run(_) | Self::Test(_) | Self::Passthrough(_)
Expand All @@ -225,16 +225,6 @@ impl CargoCmd {
}
}

/// Whether or not the resulting executable should be sent to the 3DS with
/// `3dslink`.
pub fn should_link_to_device(&self) -> bool {
match self {
Self::Test(Test { no_run: true, .. }) => false,
Self::Run(run) | Self::Test(Test { run_args: run, .. }) => !run.use_custom_runner(),
_ => false,
}
}

pub const DEFAULT_MESSAGE_FORMAT: &'static str = "json-render-diagnostics";

pub fn extract_message_format(&mut self) -> Result<Option<String>, String> {
Expand Down Expand Up @@ -394,12 +384,12 @@ impl Callbacks for CargoCmd {

impl RemainingArgs {
/// Get the args to be passed to `cargo`.
pub fn cargo_args(&self) -> Vec<String> {
pub(crate) fn cargo_args(&self) -> Vec<String> {
self.split_args().0
}

/// Get the args to be passed to the executable itself (not `cargo`).
pub fn exe_args(&self) -> Vec<String> {
pub(crate) fn exe_args(&self) -> Vec<String> {
self.split_args().1
}

Expand Down Expand Up @@ -440,14 +430,16 @@ impl Callbacks for Run {
///
/// This callback handles launching the application via `3dslink`.
fn run_callback(&self, config: &CTRConfig) {
eprintln!("Running 3dslink");
link(config, self, self.build_args.verbose);
if !self.use_custom_runner() {
eprintln!("Running 3dslink");
link(config, self, self.build_args.verbose);
}
}
}

impl Run {
/// Get the args to pass to `3dslink` based on these options.
pub fn get_3dslink_args(&self) -> Vec<String> {
pub(crate) fn get_3dslink_args(&self) -> Vec<String> {
let mut args = Vec::new();

if let Some(address) = self.address {
Expand Down Expand Up @@ -495,7 +487,7 @@ impl Run {
/// - `.cargo/config.toml`
/// - Environment variables
/// - Command-line `--config` overrides
pub fn use_custom_runner(&self) -> bool {
pub(crate) fn use_custom_runner(&self) -> bool {
static HAS_RUNNER: OnceLock<bool> = OnceLock::new();

let &custom_runner_configured = HAS_RUNNER.get_or_init(|| {
Expand Down
2 changes: 1 addition & 1 deletion src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl UnitGraph {
/// build and the graph is output instead.
///
/// See <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#unit-graph>.
pub fn from_cargo(cargo_cmd: &Command, verbose: bool) -> Result<Self, Box<dyn Error>> {
pub(crate) fn from_cargo(cargo_cmd: &Command, verbose: bool) -> Result<Self, Box<dyn Error>> {
// Since Command isn't Clone, copy it "by hand", by copying its args and envs
let mut cmd = Command::new(cargo_cmd.get_program());

Expand Down
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn should_use_ctru_debuginfo(cargo_cmd: &Command, verbose: bool) -> bool {
///
/// For "build" commands (which compile code, such as `cargo 3ds build` or `cargo 3ds clippy`),
/// if there is no pre-built std detected in the sysroot, `build-std` will be used instead.
pub fn make_cargo_command(input: &Input, message_format: &Option<String>) -> Command {
pub(crate) fn make_cargo_command(input: &Input, message_format: &Option<String>) -> Command {
let devkitpro =
env::var("DEVKITPRO").expect("DEVKITPRO is not defined as an environment variable");
// TODO: should we actually prepend the user's RUSTFLAGS for linking order? not sure
Expand Down Expand Up @@ -195,7 +195,7 @@ fn print_command(command: &Command) {
}

/// Finds the sysroot path of the current toolchain
pub fn find_sysroot() -> PathBuf {
pub(crate) fn find_sysroot() -> PathBuf {
let sysroot = env::var("SYSROOT").ok().unwrap_or_else(|| {
let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string());

Expand Down Expand Up @@ -253,7 +253,7 @@ pub fn check_rust_version(input: &Input) {
/// Parses messages returned by "build" cargo commands (such as `cargo 3ds build` or `cargo 3ds run`).
/// The returned [`CTRConfig`] is then used for further building in and execution
/// in [`CTRConfig::build_smdh`], [`build_3dsx`], and [`link`].
pub fn get_artifact_config(package: Package, artifact: Artifact) -> CTRConfig {
pub(crate) fn get_artifact_config(package: Package, artifact: Artifact) -> CTRConfig {
// For now, assume a single "kind" per artifact. It seems to be the case
// when a single executable is built anyway but maybe not in all cases.
let name = match artifact.target.kind[0].as_ref() {
Expand Down Expand Up @@ -287,7 +287,7 @@ pub fn get_artifact_config(package: Package, artifact: Artifact) -> CTRConfig {

/// Builds the 3dsx using `3dsxtool`.
/// This will fail if `3dsxtool` is not within the running directory or in a directory found in $PATH
pub fn build_3dsx(config: &CTRConfig, verbose: bool) {
pub(crate) fn build_3dsx(config: &CTRConfig, verbose: bool) {
let mut command = Command::new("3dsxtool");
command
.arg(&config.target_path)
Expand Down Expand Up @@ -323,7 +323,7 @@ pub fn build_3dsx(config: &CTRConfig, verbose: bool) {

/// Link the generated 3dsx to a 3ds to execute and test using `3dslink`.
/// This will fail if `3dslink` is not within the running directory or in a directory found in $PATH
pub fn link(config: &CTRConfig, run_args: &Run, verbose: bool) {
pub(crate) fn link(config: &CTRConfig, run_args: &Run, verbose: bool) {
let mut command = Command::new("3dslink");
command
.arg(config.path_3dsx())
Expand Down Expand Up @@ -380,17 +380,17 @@ pub struct CTRConfig {

impl CTRConfig {
/// Get the path to the output `.3dsx` file.
pub fn path_3dsx(&self) -> Utf8PathBuf {
pub(crate) fn path_3dsx(&self) -> Utf8PathBuf {
self.target_path.with_extension("3dsx")
}

/// Get the path to the output `.smdh` file.
pub fn path_smdh(&self) -> Utf8PathBuf {
pub(crate) fn path_smdh(&self) -> Utf8PathBuf {
self.target_path.with_extension("smdh")
}

/// Get the absolute path to the romfs directory, defaulting to `romfs` if not specified.
pub fn romfs_dir(&self) -> Utf8PathBuf {
pub(crate) fn romfs_dir(&self) -> Utf8PathBuf {
self.manifest_dir
.join(self.romfs_dir.as_deref().unwrap_or(Utf8Path::new("romfs")))
}
Expand All @@ -401,7 +401,7 @@ impl CTRConfig {

/// Builds the smdh using `smdhtool`.
/// This will fail if `smdhtool` is not within the running directory or in a directory found in $PATH
pub fn build_smdh(&self, verbose: bool) {
pub(crate) fn build_smdh(&self, verbose: bool) {
let description = self
.description
.as_deref()
Expand Down

0 comments on commit 30fef76

Please sign in to comment.