Skip to content

Specify CC flags for the armv6k target #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,35 @@ pub fn run_cargo(input: &Input, message_format: Option<String>) -> (ExitStatus,
let rustflags = format!("{rustflags} -l{libctru}");

command.env("RUSTFLAGS", rustflags);

// C Compilation Flags
let devkitpro = std::env::var("DEVKITPRO").unwrap_or_default();
let devkitarm = std::env::var("DEVKITARM").unwrap_or_default();

command.env("CRATE_CC_NO_DEFAULTS_armv6k-nintendo-3ds", "");

command.env(
"CC_armv6k-nintendo-3ds",
devkitarm.clone() + "/bin/arm-none-eabi-gcc",
);

command.env(
"CXX_armv6k-nintendo-3ds",
devkitarm.clone() + "/bin/arm-none-eabi-g++",
);

command.env(
"AR_armv6k-nintendo-3ds",
devkitarm.clone() + "/bin/arm-none-eabi-gcc-ar",
);

let cflags = format!(
"-march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft \
-ffunction-sections -fdata-sections -D_3DS -D__3DS__ -I{devkitpro}/libctru/include"
);

command.env("CFLAGS_armv6k-nintendo-3ds", &cflags);
command.env("CXXFLAGS_armv6k-nintendo-3ds", &cflags);
Copy link
Member

@ian-h-chamberlain ian-h-chamberlain Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For most of these, I would probably suggest not overriding them (or at least emitting a warning of some sort) if they are already set in cargo-3ds's environment, to allow users to override this default behavior with more specific flags if they want.

For CFLAGS/CXXFLAGS we could do something like we have for RUSTFLAGS and just append all of these builtin flags, so the user could do something like CFLAGS_armv6k_nintendo_3ds=-Wall cargo 3ds build easily enough if they wanted to.

The downside is that to be "truly correct" you'd need to parse all the different ones that cc does.

Edit: one other thing, you could set these as e.g. TARGET_CFLAGS or TARGET_CC since we know the target here should always be armv6k-nintendo-3ds, and this would allow users to override with the more specific CC_armv6k_nintendo_3ds if they want to.

There is a function try_flags_from_environment but I'm not sure it works the way this is intended to... perhaps users would just need to override flags in their own build.rs if they really wanted

}

if input.verbose {
Expand Down
Loading