Skip to content

Commit df52628

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#36727 - kallisti5:master, r=Aatch
Haiku: Initial work at OS support These changes should be non-invasive to non-Haiku platforms. These patches were hand reworked from Neil's original Rust 1.9.0 patches. I've done some style cleanup and design updates along the way. There are a few small additional patches to libc, rust-installer and compiler-rt that will be submitted once this one is accepted. Haiku can be compiled on Linux, and a full gcc cross-compiler with a Haiku target is available, which means bootstrapping should be fairly easy. The patches here have already successfully bootstrapped under our haiku x86_gcc2 architecture. http://rust-on-haiku.com/wiki/PortingRust I'll be focusing on our more modern gcc5 x86 and x86 architectures for now. As for support, we're not seeking official support for now. We understand Haiku isn't a top-tier OS choice, however having these patches upstream greatly reduces the amount of patchwork we have to do. Mesa has Haiku code upstream, and we submit patches to keep it going. Mesa doesn't test on Haiku and we're ok with that :-)
2 parents 9b72650 + 7c34d9c commit df52628

File tree

29 files changed

+510
-16
lines changed

29 files changed

+510
-16
lines changed

configure

+8
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,10 @@ case $CFG_OSTYPE in
437437
CFG_CPUTYPE=$(isainfo -n)
438438
;;
439439

440+
Haiku)
441+
CFG_OSTYPE=unknown-haiku
442+
;;
443+
440444
MINGW*)
441445
# msys' `uname` does not print gcc configuration, but prints msys
442446
# configuration. so we cannot believe `uname -m`:
@@ -532,6 +536,10 @@ case $CFG_CPUTYPE in
532536
CFG_CPUTYPE=x86_64
533537
;;
534538

539+
BePC)
540+
CFG_CPUTYPE=i686
541+
;;
542+
535543
*)
536544
err "unknown CPU type: $CFG_CPUTYPE"
537545
esac

mk/cfg/i686-unknown-haiku.mk

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# i686-unknown-haiku configuration
2+
CROSS_PREFIX_i686-unknown-haiku=i586-pc-haiku-
3+
CC_i686-unknown-haiku=$(CC)
4+
CXX_i686-unknown-haiku=$(CXX)
5+
CPP_i686-unknown-haiku=$(CPP)
6+
AR_i686-unknown-haiku=$(AR)
7+
CFG_LIB_NAME_i686-unknown-haiku=lib$(1).so
8+
CFG_STATIC_LIB_NAME_i686-unknown-haiku=lib$(1).a
9+
CFG_LIB_GLOB_i686-unknown-haiku=lib$(1)-*.so
10+
CFG_LIB_DSYM_GLOB_i686-unknown-haiku=lib$(1)-*.dylib.dSYM
11+
CFG_CFLAGS_i686-unknown-haiku := -m32 $(CFLAGS)
12+
CFG_GCCISH_CFLAGS_i686-unknown-haiku := -Wall -Werror -g -fPIC -m32 $(CFLAGS)
13+
CFG_GCCISH_CXXFLAGS_i686-unknown-haiku := -fno-rtti $(CXXFLAGS)
14+
CFG_GCCISH_LINK_FLAGS_i686-unknown-haiku := -shared -fPIC -ldl -pthread -lrt -g -m32
15+
CFG_GCCISH_PRE_LIB_FLAGS_i686-unknown-haiku := -Wl,-whole-archive
16+
CFG_GCCISH_POST_LIB_FLAGS_i686-unknown-haiku := -Wl,-no-whole-archive
17+
CFG_DEF_SUFFIX_i686-unknown-haiku := .linux.def
18+
CFG_LLC_FLAGS_i686-unknown-haiku :=
19+
CFG_INSTALL_NAME_i686-unknown-haiku =
20+
CFG_EXE_SUFFIX_i686-unknown-haiku =
21+
CFG_WINDOWSY_i686-unknown-haiku :=
22+
CFG_UNIXY_i686-unknown-haiku := 1
23+
CFG_PATH_MUNGE_i686-unknown-haiku := true
24+
CFG_LDPATH_i686-unknown-haiku :=
25+
CFG_RUN_i686-unknown-haiku=$(2)
26+
CFG_RUN_TARG_i686-unknown-haiku=$(call CFG_RUN_i686-unknown-haiku,,$(2))
27+
CFG_GNU_TRIPLE_i686-unknown-haiku := i686-unknown-haiku

mk/cfg/x86_64-unknown-haiku.mk

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# x86_64-unknown-haiku configuration
2+
CROSS_PREFIX_x86_64-unknown-haiku=x86_64-unknown-haiku-
3+
CC_x86_64-unknown-haiku=$(CC)
4+
CXX_x86_64-unknown-haiku=$(CXX)
5+
CPP_x86_64-unknown-haiku=$(CPP)
6+
AR_x86_64-unknown-haiku=$(AR)
7+
CFG_LIB_NAME_x86_64-unknown-haiku=lib$(1).so
8+
CFG_STATIC_LIB_NAME_x86_64-unknown-haiku=lib$(1).a
9+
CFG_LIB_GLOB_x86_64-unknown-haiku=lib$(1)-*.so
10+
CFG_LIB_DSYM_GLOB_x86_64-unknown-haiku=lib$(1)-*.dylib.dSYM
11+
CFG_CFLAGS_x86_64-unknown-haiku := -m64 $(CFLAGS)
12+
CFG_GCCISH_CFLAGS_x86_64-unknown-haiku := -Wall -Werror -g -fPIC -m64 $(CFLAGS)
13+
CFG_GCCISH_CXXFLAGS_x86_64-unknown-haiku := -fno-rtti $(CXXFLAGS)
14+
CFG_GCCISH_LINK_FLAGS_x86_64-unknown-haiku := -shared -fPIC -ldl -pthread -lrt -g -m64
15+
CFG_GCCISH_PRE_LIB_FLAGS_x86_64-unknown-haiku := -Wl,-whole-archive
16+
CFG_GCCISH_POST_LIB_FLAGS_x86_64-unknown-haiku := -Wl,-no-whole-archive
17+
CFG_DEF_SUFFIX_x86_64-unknown-haiku := .linux.def
18+
CFG_LLC_FLAGS_x86_64-unknown-haiku :=
19+
CFG_INSTALL_NAME_x86_64-unknown-haiku =
20+
CFG_EXE_SUFFIX_x86_64-unknown-haiku =
21+
CFG_WINDOWSY_x86_64-unknown-haiku :=
22+
CFG_UNIXY_x86_64-unknown-haiku := 1
23+
CFG_PATH_MUNGE_x86_64-unknown-haiku := true
24+
CFG_LDPATH_x86_64-unknown-haiku :=
25+
CFG_RUN_x86_64-unknown-haiku=$(2)
26+
CFG_RUN_TARG_x86_64-unknown-haiku=$(call CFG_RUN_x86_64-unknown-haiku,,$(2))
27+
CFG_GNU_TRIPLE_x86_64-unknown-haiku := x86_64-unknown-haiku

mk/main.mk

+4
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,14 @@ ifeq ($$(OSTYPE_$(3)),apple-darwin)
512512
else
513513
ifeq ($$(CFG_WINDOWSY_$(3)),1)
514514
LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := PATH
515+
else
516+
ifeq ($$(OSTYPE_$(3)),unknown-haiku)
517+
LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := LIBRARY_PATH
515518
else
516519
LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := LD_LIBRARY_PATH
517520
endif
518521
endif
522+
endif
519523

520524
LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3) := \
521525
$$(CURDIR)/$$(HLIB$(1)_H_$(3)):$$(CFG_LLVM_INST_DIR_$(3))/lib

src/etc/local_stage0.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LIB_PREFIX=lib
1818

1919
OS=`uname -s`
2020
case $OS in
21-
("Linux"|"FreeBSD"|"DragonFly"|"Bitrig"|"OpenBSD"|"SunOS")
21+
("Linux"|"FreeBSD"|"DragonFly"|"Bitrig"|"OpenBSD"|"SunOS"|"Haiku")
2222
BIN_SUF=
2323
LIB_SUF=.so
2424
;;
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use target::TargetOptions;
12+
use std::default::Default;
13+
14+
pub fn opts() -> TargetOptions {
15+
TargetOptions {
16+
linker: "cc".to_string(),
17+
dynamic_linking: true,
18+
executables: true,
19+
has_rpath: true,
20+
linker_is_gnu: true,
21+
.. Default::default()
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use target::{Target, TargetResult};
12+
13+
pub fn target() -> TargetResult {
14+
let mut base = super::haiku_base::opts();
15+
base.cpu = "pentium4".to_string();
16+
base.max_atomic_width = 64;
17+
base.pre_link_args.push("-m32".to_string());
18+
19+
Ok(Target {
20+
llvm_target: "i686-unknown-haiku".to_string(),
21+
target_endian: "little".to_string(),
22+
target_pointer_width: "32".to_string(),
23+
data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(),
24+
arch: "x86".to_string(),
25+
target_os: "haiku".to_string(),
26+
target_env: "".to_string(),
27+
target_vendor: "unknown".to_string(),
28+
options: base,
29+
})
30+
}

src/librustc_back/target/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ mod apple_ios_base;
5656
mod bitrig_base;
5757
mod dragonfly_base;
5858
mod freebsd_base;
59+
mod haiku_base;
5960
mod linux_base;
6061
mod linux_musl_base;
6162
mod openbsd_base;
@@ -165,6 +166,9 @@ supported_targets! {
165166
("x86_64-unknown-netbsd", x86_64_unknown_netbsd),
166167
("x86_64-rumprun-netbsd", x86_64_rumprun_netbsd),
167168

169+
("i686_unknown_haiku", i686_unknown_haiku),
170+
("x86_64_unknown_haiku", x86_64_unknown_haiku),
171+
168172
("x86_64-apple-darwin", x86_64_apple_darwin),
169173
("i686-apple-darwin", i686_apple_darwin),
170174

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use target::{Target, TargetResult};
12+
13+
pub fn target() -> TargetResult {
14+
let mut base = super::haiku_base::opts();
15+
base.cpu = "x86-64".to_string();
16+
base.max_atomic_width = 64;
17+
base.pre_link_args.push("-m64".to_string());
18+
19+
Ok(Target {
20+
llvm_target: "x86_64-unknown-haiku".to_string(),
21+
target_endian: "little".to_string(),
22+
target_pointer_width: "64".to_string(),
23+
data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(),
24+
arch: "x86_64".to_string(),
25+
target_os: "haiku".to_string(),
26+
target_env: "".to_string(),
27+
target_vendor: "unknown".to_string(),
28+
options: base,
29+
})
30+
}

src/librustc_data_structures/flock.rs

+21
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,27 @@ mod imp {
9494
pub const F_SETLKW: libc::c_int = 9;
9595
}
9696

97+
#[cfg(target_os = "haiku")]
98+
mod os {
99+
use libc;
100+
101+
pub struct flock {
102+
pub l_type: libc::c_short,
103+
pub l_whence: libc::c_short,
104+
pub l_start: libc::off_t,
105+
pub l_len: libc::off_t,
106+
pub l_pid: libc::pid_t,
107+
108+
// not actually here, but brings in line with freebsd
109+
pub l_sysid: libc::c_int,
110+
}
111+
112+
pub const F_UNLCK: libc::c_short = 0x0200;
113+
pub const F_WRLCK: libc::c_short = 0x0400;
114+
pub const F_SETLK: libc::c_int = 0x0080;
115+
pub const F_SETLKW: libc::c_int = 0x0100;
116+
}
117+
97118
#[cfg(any(target_os = "macos", target_os = "ios"))]
98119
mod os {
99120
use libc;

src/libstd/env.rs

+11
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,17 @@ mod os {
903903
pub const EXE_EXTENSION: &'static str = "js";
904904
}
905905

906+
#[cfg(target_os = "haiku")]
907+
mod os {
908+
pub const FAMILY: &'static str = "unix";
909+
pub const OS: &'static str = "haiku";
910+
pub const DLL_PREFIX: &'static str = "lib";
911+
pub const DLL_SUFFIX: &'static str = ".so";
912+
pub const DLL_EXTENSION: &'static str = "so";
913+
pub const EXE_SUFFIX: &'static str = "";
914+
pub const EXE_EXTENSION: &'static str = "";
915+
}
916+
906917
#[cfg(target_arch = "x86")]
907918
mod arch {
908919
pub const ARCH: &'static str = "x86";

src/libstd/os/haiku/fs.rs

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![stable(feature = "metadata_ext", since = "1.1.0")]
12+
13+
use libc;
14+
15+
use fs::Metadata;
16+
use sys_common::AsInner;
17+
18+
#[allow(deprecated)]
19+
use os::haiku::raw;
20+
21+
/// OS-specific extension methods for `fs::Metadata`
22+
#[stable(feature = "metadata_ext", since = "1.1.0")]
23+
pub trait MetadataExt {
24+
/// Gain a reference to the underlying `stat` structure which contains
25+
/// the raw information returned by the OS.
26+
///
27+
/// The contents of the returned `stat` are **not** consistent across
28+
/// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the
29+
/// cross-Unix abstractions contained within the raw stat.
30+
#[stable(feature = "metadata_ext", since = "1.1.0")]
31+
#[rustc_deprecated(since = "1.8.0",
32+
reason = "deprecated in favor of the accessor \
33+
methods of this trait")]
34+
#[allow(deprecated)]
35+
fn as_raw_stat(&self) -> &raw::stat;
36+
37+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
38+
fn st_dev(&self) -> u64;
39+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
40+
fn st_ino(&self) -> u64;
41+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
42+
fn st_mode(&self) -> u32;
43+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
44+
fn st_nlink(&self) -> u64;
45+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
46+
fn st_uid(&self) -> u32;
47+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
48+
fn st_gid(&self) -> u32;
49+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
50+
fn st_rdev(&self) -> u64;
51+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
52+
fn st_size(&self) -> u64;
53+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
54+
fn st_atime(&self) -> i64;
55+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
56+
fn st_atime_nsec(&self) -> i64;
57+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
58+
fn st_mtime(&self) -> i64;
59+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
60+
fn st_mtime_nsec(&self) -> i64;
61+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
62+
fn st_ctime(&self) -> i64;
63+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
64+
fn st_ctime_nsec(&self) -> i64;
65+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
66+
fn st_crtime(&self) -> i64;
67+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
68+
fn st_crtime_nsec(&self) -> i64;
69+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
70+
fn st_blksize(&self) -> u64;
71+
#[stable(feature = "metadata_ext2", since = "1.8.0")]
72+
fn st_blocks(&self) -> u64;
73+
}
74+
75+
#[stable(feature = "metadata_ext", since = "1.1.0")]
76+
impl MetadataExt for Metadata {
77+
#[allow(deprecated)]
78+
fn as_raw_stat(&self) -> &raw::stat {
79+
unsafe {
80+
&*(self.as_inner().as_inner() as *const libc::stat
81+
as *const raw::stat)
82+
}
83+
}
84+
fn st_dev(&self) -> u64 {
85+
self.as_inner().as_inner().st_dev as u64
86+
}
87+
fn st_ino(&self) -> u64 {
88+
self.as_inner().as_inner().st_ino as u64
89+
}
90+
fn st_mode(&self) -> u32 {
91+
self.as_inner().as_inner().st_mode as u32
92+
}
93+
fn st_nlink(&self) -> u64 {
94+
self.as_inner().as_inner().st_nlink as u64
95+
}
96+
fn st_uid(&self) -> u32 {
97+
self.as_inner().as_inner().st_uid as u32
98+
}
99+
fn st_gid(&self) -> u32 {
100+
self.as_inner().as_inner().st_gid as u32
101+
}
102+
fn st_rdev(&self) -> u64 {
103+
self.as_inner().as_inner().st_rdev as u64
104+
}
105+
fn st_size(&self) -> u64 {
106+
self.as_inner().as_inner().st_size as u64
107+
}
108+
fn st_atime(&self) -> i64 {
109+
self.as_inner().as_inner().st_atime as i64
110+
}
111+
fn st_atime_nsec(&self) -> i64 {
112+
self.as_inner().as_inner().st_atime_nsec as i64
113+
}
114+
fn st_mtime(&self) -> i64 {
115+
self.as_inner().as_inner().st_mtime as i64
116+
}
117+
fn st_mtime_nsec(&self) -> i64 {
118+
self.as_inner().as_inner().st_mtime_nsec as i64
119+
}
120+
fn st_ctime(&self) -> i64 {
121+
self.as_inner().as_inner().st_ctime as i64
122+
}
123+
fn st_ctime_nsec(&self) -> i64 {
124+
self.as_inner().as_inner().st_ctime_nsec as i64
125+
}
126+
fn st_crtime(&self) -> i64 {
127+
self.as_inner().as_inner().st_crtime as i64
128+
}
129+
fn st_crtime_nsec(&self) -> i64 {
130+
self.as_inner().as_inner().st_crtime_nsec as i64
131+
}
132+
fn st_blksize(&self) -> u64 {
133+
self.as_inner().as_inner().st_blksize as u64
134+
}
135+
fn st_blocks(&self) -> u64 {
136+
self.as_inner().as_inner().st_blocks as u64
137+
}
138+
}

0 commit comments

Comments
 (0)