Skip to content

Commit df52628

Browse files
author
Jonathan Turner
authored
Rollup merge of #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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 27 additions & 0 deletions
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

Lines changed: 27 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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
;;
Lines changed: 23 additions & 0 deletions
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+
}
Lines changed: 30 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 30 additions & 0 deletions
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

Lines changed: 21 additions & 0 deletions
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;

0 commit comments

Comments
 (0)