Skip to content

rustbuild: Fix compile on OSX for 10.7 #32598

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

Merged
merged 1 commit into from
Apr 2, 2016
Merged
Show file tree
Hide file tree
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
27 changes: 21 additions & 6 deletions src/bootstrap/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,13 @@ impl Build {
if !target.contains("msvc") {
cargo.env(format!("CC_{}", target), self.cc(target))
.env(format!("AR_{}", target), self.ar(target))
.env(format!("CFLAGS_{}", target), self.cflags(target));
.env(format!("CFLAGS_{}", target), self.cflags(target).join(" "));
}

// If we're building for OSX, inform the compiler and the linker that
// we want to build a compiler runnable on 10.7
if target.contains("apple-darwin") {
cargo.env("MACOSX_DEPLOYMENT_TARGET", "10.7");
}

// Environment variables *required* needed throughout the build
Expand Down Expand Up @@ -481,11 +487,20 @@ impl Build {
self.cc[target].0.path()
}

fn cflags(&self, target: &str) -> String {
self.cc[target].0.args().iter()
.map(|s| s.to_string_lossy())
.collect::<Vec<_>>()
.join(" ")
fn cflags(&self, target: &str) -> Vec<String> {
let mut base = self.cc[target].0.args().iter()
.map(|s| s.to_string_lossy().into_owned())
.collect::<Vec<_>>();

// If we're compiling on OSX then we add a few unconditional flags
// indicating that we want libc++ (more filled out than libstdc++) and
// we want to compile for 10.7. This way we can ensure that
// LLVM/jemalloc/etc are all properly compiled.
if target.contains("apple-darwin") {
base.push("-stdlib=libc++".into());
base.push("-mmacosx-version-min=10.7".into());
Copy link
Member

Choose a reason for hiding this comment

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

I think this is implied by the environment variable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah unfortunately I'll have to remove that b/c cmake right now chokes on the env var (at least locally). It seems to work if this is passed by flag instead though?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think they're equivalent ways of setting the version.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right to clang they're equivalent, but unfortunately not to cmake. Right now we're getting scary warnings on the bots:

CMake Warning at /usr/local/Cellar/cmake/3.5.0/share/cmake/Modules/Platform/Darwin-Initialize.cmake:97 (message):
  CMAKE_OSX_DEPLOYMENT_TARGET is '10.7' but the matching SDK does not exist
  at:

   "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk"

  Instead using SDK:

   "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk".
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.5.0/share/cmake/Modules/CMakeSystemSpecificInitialize.cmake:18 (include)
  CMakeLists.txt:54 (project)

and for me locally with just the command line tools installed it's a hard error. Neither the warning nor the error happens with the argument version though.

}
return base
}

fn ar(&self, target: &str) -> &Path {
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/build/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ pub fn llvm(build: &Build, target: &str) {
.define("CMAKE_CXX_COMPILER", build.cxx(target));
}
cfg.build_arg("-j").build_arg(build.jobs().to_string());

cfg.define("CMAKE_C_FLAGS", build.cflags(target).join(" "));
cfg.define("CMAKE_CXX_FLAGS", build.cflags(target).join(" "));
}

// FIXME: we don't actually need to build all LLVM tools and all LLVM
Expand Down
18 changes: 12 additions & 6 deletions src/rustc/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.