Skip to content
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

feat: add method to set no_default_c/cxx_flags #219

Closed
Closed
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: 24 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ pub struct Config {
verbose_make: bool,
pic: Option<bool>,
c_cfg: Option<cc::Build>,
no_default_c_flags: bool,
cxx_cfg: Option<cc::Build>,
no_default_cxx_flags: bool,
env_cache: HashMap<String, Option<OsString>>,
}

Expand Down Expand Up @@ -205,7 +207,9 @@ impl Config {
verbose_make: false,
pic: None,
c_cfg: None,
no_default_c_flags: false,
cxx_cfg: None,
no_default_cxx_flags: false,
env_cache: HashMap::new(),
}
}
Expand Down Expand Up @@ -420,6 +424,18 @@ impl Config {
self
}

/// Disables the generation of default compiler cxx flags. The default compiler flags may cause conflicts in some cross compiling scenarios.

Choose a reason for hiding this comment

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

You've mixed up the docstrings.

Anyways, there must be a cleaner way without the duplication. What if the same applies for other language targets down the line (Fortran, ASM)

Copy link
Author

Choose a reason for hiding this comment

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

What's the meaning of cleaner way without the duplication. I think it's necessary to clear the default flags by languages instead of simply cleaning them for all the language targets

Copy link

@lessismordaunt lessismordaunt Dec 8, 2024

Choose a reason for hiding this comment

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

Come on, half the code is s/cxx/c/. At least use something like a mapping no_default_flags that can hold the option for different langs.

pub fn no_default_c_flags(&mut self, no_default_c_flags: bool) -> &mut Config {
self.no_default_c_flags = no_default_c_flags;
self
}

/// Disables the generation of default compiler c flags. The default compiler flags may cause conflicts in some cross compiling scenarios.
pub fn no_default_cxx_flags(&mut self, no_default_cxx_flags: bool) -> &mut Config {
self.no_default_cxx_flags = no_default_cxx_flags;
self
}

/// Run this configuration, compiling the library with all the configured
/// options.
///
Expand Down Expand Up @@ -515,7 +531,7 @@ impl Config {
.debug(false)
.warnings(false)
.host(&host)
.no_default_flags(ndk);
.no_default_flags(ndk | self.no_default_c_flags);
if !ndk {
c_cfg.target(&target);
}
Expand All @@ -527,7 +543,7 @@ impl Config {
.debug(false)
.warnings(false)
.host(&host)
.no_default_flags(ndk);
.no_default_flags(ndk | self.no_default_cxx_flags);
if !ndk {
cxx_cfg.target(&target);
}
Expand Down Expand Up @@ -791,9 +807,12 @@ impl Config {
cmd.arg(ccompiler);
}
};

set_compiler("C", &c_compiler, &self.cflags);
set_compiler("CXX", &cxx_compiler, &self.cxxflags);
if !self.no_default_c_flags {
set_compiler("C", &c_compiler, &self.cflags);
}
if !self.no_default_cxx_flags {
set_compiler("CXX", &cxx_compiler, &self.cxxflags);
}
set_compiler("ASM", &asm_compiler, &self.asmflags);
}

Expand Down