Skip to content

Commit

Permalink
Auto merge of #31078 - nbaksalyar:illumos, r=alexcrichton
Browse files Browse the repository at this point in the history
This pull request adds support for [Illumos](http://illumos.org/)-based operating systems: SmartOS, OpenIndiana, and others. For now it's x86-64 only, as I'm not sure if 32-bit installations are widespread. This PR is based on #28589 by @potatosalad, and also closes #21000, #25845, and #25846.

Required changes in libc are already merged: rust-lang/libc#138

Here's a snapshot required to build a stage0 compiler:
https://s3-eu-west-1.amazonaws.com/nbaksalyar/rustc-sunos-snapshot.tar.gz
It passes all checks from `make check`.

There are some changes I'm not quite sure about, e.g. macro usage in `src/libstd/num/f64.rs` and `DirEntry` structure in `src/libstd/sys/unix/fs.rs`, so any comments on how to rewrite it better would be greatly appreciated.

Also, LLVM configure script might need to be patched to build it successfully, or a pre-built libLLVM should be used. Some details can be found here: https://llvm.org/bugs/show_bug.cgi?id=25409

Thanks!

r? @brson
  • Loading branch information
bors committed Feb 3, 2016
2 parents 18c1781 + fae883c commit e3bcddb
Show file tree
Hide file tree
Showing 36 changed files with 412 additions and 38 deletions.
13 changes: 13 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/bin/sh

# /bin/sh on Solaris is not a POSIX compatible shell, but /usr/bin/bash is.
if [ `uname -s` = 'SunOS' -a "${POSIX_SHELL}" != "true" ]; then
POSIX_SHELL="true"
export POSIX_SHELL
exec /usr/bin/env bash $0 "$@"
fi
unset POSIX_SHELL # clear it so if we invoke other scripts, they run as bash as well

msg() {
echo "configure: $*"
}
Expand Down Expand Up @@ -416,6 +424,11 @@ case $CFG_OSTYPE in
CFG_OSTYPE=apple-darwin
;;

SunOS)
CFG_OSTYPE=sun-solaris
CFG_CPUTYPE=$(isainfo -n)
;;

MINGW*)
# msys' `uname` does not print gcc configuration, but prints msys
# configuration. so we cannot believe `uname -m`:
Expand Down
23 changes: 23 additions & 0 deletions mk/cfg/x86_64-sun-solaris.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# x86_64-sun-solaris configuration
CROSS_PREFIX_x86_64-sun-solaris=x86_64-sun-solaris2.11-
CC_x86_64-sun-solaris=$(CC)
CXX_x86_64-sun-solaris=$(CXX)
CPP_x86_64-sun-solaris=$(CPP)
AR_x86_64-sun-solaris=$(AR)
CFG_LIB_NAME_x86_64-sun-solaris=lib$(1).so
CFG_STATIC_LIB_NAME_x86_64-sun-solaris=lib$(1).a
CFG_LIB_GLOB_x86_64-sun-solaris=lib$(1)-*.so
CFG_LIB_DSYM_GLOB_x86_64-sun-solaris=$(1)-*.dylib.dSYM
CFG_JEMALLOC_CFLAGS_x86_64-sun-solaris := -I/usr/local/include $(CFLAGS)
CFG_GCCISH_CFLAGS_x86_64-sun-solaris := -Wall -Werror -g -D_POSIX_PTHREAD_SEMANTICS -fPIC -I/usr/local/include $(CFLAGS)
CFG_GCCISH_LINK_FLAGS_x86_64-sun-solaris := -shared -fPIC -g -pthread -lrt
CFG_GCCISH_DEF_FLAG_x86_64-sun-solaris := -Wl,--export-dynamic,--dynamic-list=
CFG_LLC_FLAGS_x86_64-sun-solaris :=
CFG_INSTALL_NAME_x86_64-sun-solaris =
CFG_EXE_SUFFIX_x86_64-sun-solaris :=
CFG_WINDOWSY_x86_64-sun-solaris :=
CFG_UNIXY_x86_64-sun-solaris := 1
CFG_LDPATH_x86_64-sun-solaris :=
CFG_RUN_x86_64-sun-solaris=$(2)
CFG_RUN_TARG_x86_64-sun-solaris=$(call CFG_RUN_x86_64-sun-solaris,,$(2))
CFG_GNU_TRIPLE_x86_64-sun-solaris := x86_64-sun-solaris
1 change: 1 addition & 0 deletions src/compiletest/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const OS_TABLE: &'static [(&'static str, &'static str)] = &[
("openbsd", "openbsd"),
("win32", "windows"),
("windows", "windows"),
("solaris", "solaris"),
];

const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
Expand Down
2 changes: 1 addition & 1 deletion src/etc/local_stage0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ LIB_PREFIX=lib

OS=`uname -s`
case $OS in
("Linux"|"FreeBSD"|"DragonFly"|"Bitrig"|"OpenBSD")
("Linux"|"FreeBSD"|"DragonFly"|"Bitrig"|"OpenBSD"|"SunOS")
BIN_SUF=
LIB_SUF=.so
;;
Expand Down
1 change: 1 addition & 0 deletions src/etc/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def scrub(b):
"macos": ["bin/rustc"],
"netbsd": ["bin/rustc"],
"openbsd": ["bin/rustc"],
"solaris": ["bin/rustc"],
"winnt": ["bin/rustc.exe"],
}

Expand Down
8 changes: 8 additions & 0 deletions src/librustc_back/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ mod freebsd_base;
mod linux_base;
mod openbsd_base;
mod netbsd_base;
mod solaris_base;
mod windows_base;
mod windows_msvc_base;

Expand Down Expand Up @@ -155,6 +156,10 @@ pub struct TargetOptions {
/// Whether the target toolchain is like OSX's. Only useful for compiling against iOS/OS X, in
/// particular running dsymutil and some other stuff like `-dead_strip`. Defaults to false.
pub is_like_osx: bool,
/// Whether the target toolchain is like Solaris's.
/// Only useful for compiling against Illumos/Solaris,
/// as they have a different set of linker flags. Defaults to false.
pub is_like_solaris: bool,
/// Whether the target toolchain is like Windows'. Only useful for compiling against Windows,
/// only really used for figuring out how to find libraries, since Windows uses its own
/// library naming convention. Defaults to false.
Expand Down Expand Up @@ -227,6 +232,7 @@ impl Default for TargetOptions {
staticlib_suffix: ".a".to_string(),
target_family: None,
is_like_osx: false,
is_like_solaris: false,
is_like_windows: false,
is_like_android: false,
is_like_msvc: false,
Expand Down Expand Up @@ -447,6 +453,8 @@ impl Target {
armv7_apple_ios,
armv7s_apple_ios,

x86_64_sun_solaris,

x86_64_pc_windows_gnu,
i686_pc_windows_gnu,

Expand Down
26 changes: 26 additions & 0 deletions src/librustc_back/target/solaris_base.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::TargetOptions;
use std::default::Default;

pub fn opts() -> TargetOptions {
TargetOptions {
linker: "cc".to_string(),
dynamic_linking: true,
executables: true,
has_rpath: true,
is_like_solaris: true,
archive_format: "gnu".to_string(),
exe_allocation_crate: super::maybe_jemalloc(),

.. Default::default()
}
}
27 changes: 27 additions & 0 deletions src/librustc_back/target/x86_64_sun_solaris.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use target::Target;

pub fn target() -> Target {
let mut base = super::solaris_base::opts();
base.pre_link_args.push("-m64".to_string());

Target {
llvm_target: "x86_64-pc-solaris".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "64".to_string(),
arch: "x86_64".to_string(),
target_os: "solaris".to_string(),
target_env: "".to_string(),
target_vendor: "sun".to_string(),
options: base,
}
}
3 changes: 3 additions & 0 deletions src/librustc_trans/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ impl<'a> Linker for GnuLinker<'a> {
// insert it here.
if self.sess.target.target.options.is_like_osx {
self.cmd.arg("-Wl,-dead_strip");
} else if self.sess.target.target.options.is_like_solaris {
self.cmd.arg("-Wl,-z");
self.cmd.arg("-Wl,ignore");

// If we're building a dylib, we don't use --gc-sections because LLVM
// has already done the best it can do, and we also don't want to
Expand Down
19 changes: 19 additions & 0 deletions src/librustdoc/flock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ mod imp {
pub const F_SETLKW: libc::c_int = 9;
}

#[cfg(target_os = "solaris")]
mod os {
use libc;

pub struct flock {
pub l_type: libc::c_short,
pub l_whence: libc::c_short,
pub l_start: libc::off_t,
pub l_len: libc::off_t,
pub l_sysid: libc::c_int,
pub l_pid: libc::pid_t,
}

pub const F_WRLCK: libc::c_short = 2;
pub const F_UNLCK: libc::c_short = 3;
pub const F_SETLK: libc::c_int = 6;
pub const F_SETLKW: libc::c_int = 7;
}

pub struct Lock {
fd: libc::c_int,
}
Expand Down
6 changes: 4 additions & 2 deletions src/libstd/dynamic_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ mod tests {
target_os = "dragonfly",
target_os = "bitrig",
target_os = "netbsd",
target_os = "openbsd"))]
target_os = "openbsd",
target_os = "solaris"))]
#[allow(deprecated)]
fn test_errors_do_not_crash() {
use path::Path;
Expand All @@ -195,7 +196,8 @@ mod tests {
target_os = "dragonfly",
target_os = "bitrig",
target_os = "netbsd",
target_os = "openbsd"))]
target_os = "openbsd",
target_os = "solaris"))]
mod dl {
use prelude::v1::*;

Expand Down
12 changes: 12 additions & 0 deletions src/libstd/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ pub mod consts {
/// - bitrig
/// - netbsd
/// - openbsd
/// - solaris
/// - android
/// - windows
#[stable(feature = "env", since = "1.0.0")]
Expand Down Expand Up @@ -800,6 +801,17 @@ mod os {
pub const EXE_EXTENSION: &'static str = "";
}

#[cfg(target_os = "solaris")]
mod os {
pub const FAMILY: &'static str = "unix";
pub const OS: &'static str = "solaris";
pub const DLL_PREFIX: &'static str = "lib";
pub const DLL_SUFFIX: &'static str = ".so";
pub const DLL_EXTENSION: &'static str = "so";
pub const EXE_SUFFIX: &'static str = "";
pub const EXE_EXTENSION: &'static str = "";
}

#[cfg(target_os = "windows")]
mod os {
pub const FAMILY: &'static str = "windows";
Expand Down
31 changes: 28 additions & 3 deletions src/libstd/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ impl f64 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn ln(self) -> f64 {
unsafe { intrinsics::logf64(self) }
self.log_wrapper(|n| { unsafe { intrinsics::logf64(n) } })
}

/// Returns the logarithm of the number with respect to an arbitrary base.
Expand Down Expand Up @@ -546,7 +546,7 @@ impl f64 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn log2(self) -> f64 {
unsafe { intrinsics::log2f64(self) }
self.log_wrapper(|n| { unsafe { intrinsics::log2f64(n) } })
}

/// Returns the base 10 logarithm of the number.
Expand All @@ -562,7 +562,7 @@ impl f64 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn log10(self) -> f64 {
unsafe { intrinsics::log10f64(self) }
self.log_wrapper(|n| { unsafe { intrinsics::log10f64(n) } })
}

/// Converts radians to degrees.
Expand Down Expand Up @@ -1065,6 +1065,31 @@ impl f64 {
pub fn atanh(self) -> f64 {
0.5 * ((2.0 * self) / (1.0 - self)).ln_1p()
}

// Solaris/Illumos requires a wrapper around log, log2, and log10 functions
// because of their non-standard behavior (e.g. log(-n) returns -Inf instead
// of expected NaN).
fn log_wrapper<F: Fn(f64) -> f64>(self, log_fn: F) -> f64 {
if !cfg!(target_os = "solaris") {
log_fn(self)
} else {
if self.is_finite() {
if self > 0.0 {
log_fn(self)
} else if self == 0.0 {
NEG_INFINITY // log(0) = -Inf
} else {
NAN // log(-n) = NaN
}
} else if self.is_nan() {
self // log(NaN) = NaN
} else if self > 0.0 {
self // log(Inf) = Inf
} else {
NAN // log(-Inf) = NaN
}
}
}
}

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions src/libstd/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ pub use sys::ext as windows;
#[cfg(target_os = "nacl")] pub mod nacl;
#[cfg(target_os = "netbsd")] pub mod netbsd;
#[cfg(target_os = "openbsd")] pub mod openbsd;
#[cfg(target_os = "solaris")] pub mod solaris;

pub mod raw;
21 changes: 21 additions & 0 deletions src/libstd/os/solaris/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! Solaris-specific definitions

#![stable(feature = "raw_ext", since = "1.1.0")]

pub mod raw;

#[stable(feature = "raw_ext", since = "1.1.0")]
pub mod fs {
#[stable(feature = "raw_ext", since = "1.1.0")]
pub use sys::fs::MetadataExt;
}
Loading

0 comments on commit e3bcddb

Please sign in to comment.