From 606b8f634b5e4c32b704df3662f130c681bc28bc Mon Sep 17 00:00:00 2001 From: Mathieu Strypsteen Date: Tue, 24 Dec 2024 19:15:42 +0100 Subject: [PATCH] More changes to support my OS --- compiler/rustc_target/src/spec/base/mod.rs | 1 + compiler/rustc_target/src/spec/base/os.rs | 11 ++++++++++ compiler/rustc_target/src/spec/crt_objects.rs | 4 ++++ compiler/rustc_target/src/spec/mod.rs | 1 + .../src/spec/targets/x86_64_unknown_os.rs | 20 +++++++++++++++++++ library/std/Cargo.toml | 2 +- library/std/build.rs | 1 + library/std/src/sys/pal/mod.rs | 3 +++ library/std/src/sys/pal/{os => osstd}/args.rs | 0 .../std/src/sys/pal/{os => osstd}/common.rs | 0 library/std/src/sys/pal/{os => osstd}/env.rs | 0 library/std/src/sys/pal/{os => osstd}/fs.rs | 0 library/std/src/sys/pal/{os => osstd}/io.rs | 0 library/std/src/sys/pal/{os => osstd}/mod.rs | 0 library/std/src/sys/pal/{os => osstd}/net.rs | 0 library/std/src/sys/pal/{os => osstd}/os.rs | 0 library/std/src/sys/pal/{os => osstd}/pipe.rs | 0 .../std/src/sys/pal/{os => osstd}/process.rs | 0 .../std/src/sys/pal/{os => osstd}/stdio.rs | 0 .../std/src/sys/pal/{os => osstd}/thread.rs | 0 library/std/src/sys/pal/{os => osstd}/time.rs | 0 library/std/src/sys/thread_local/mod.rs | 1 + 22 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 compiler/rustc_target/src/spec/base/os.rs create mode 100644 compiler/rustc_target/src/spec/targets/x86_64_unknown_os.rs rename library/std/src/sys/pal/{os => osstd}/args.rs (100%) rename library/std/src/sys/pal/{os => osstd}/common.rs (100%) rename library/std/src/sys/pal/{os => osstd}/env.rs (100%) rename library/std/src/sys/pal/{os => osstd}/fs.rs (100%) rename library/std/src/sys/pal/{os => osstd}/io.rs (100%) rename library/std/src/sys/pal/{os => osstd}/mod.rs (100%) rename library/std/src/sys/pal/{os => osstd}/net.rs (100%) rename library/std/src/sys/pal/{os => osstd}/os.rs (100%) rename library/std/src/sys/pal/{os => osstd}/pipe.rs (100%) rename library/std/src/sys/pal/{os => osstd}/process.rs (100%) rename library/std/src/sys/pal/{os => osstd}/stdio.rs (100%) rename library/std/src/sys/pal/{os => osstd}/thread.rs (100%) rename library/std/src/sys/pal/{os => osstd}/time.rs (100%) diff --git a/compiler/rustc_target/src/spec/base/mod.rs b/compiler/rustc_target/src/spec/base/mod.rs index 28d10dcf2ff..ad56dedd4d1 100644 --- a/compiler/rustc_target/src/spec/base/mod.rs +++ b/compiler/rustc_target/src/spec/base/mod.rs @@ -21,6 +21,7 @@ pub(crate) mod msvc; pub(crate) mod netbsd; pub(crate) mod nto_qnx; pub(crate) mod openbsd; +pub(crate) mod os; pub(crate) mod redox; pub(crate) mod solaris; pub(crate) mod solid; diff --git a/compiler/rustc_target/src/spec/base/os.rs b/compiler/rustc_target/src/spec/base/os.rs new file mode 100644 index 00000000000..a20080c54ca --- /dev/null +++ b/compiler/rustc_target/src/spec/base/os.rs @@ -0,0 +1,11 @@ +use crate::spec::{PanicStrategy, RelocModel, TargetOptions, crt_objects}; + +pub(crate) fn opts() -> TargetOptions { + TargetOptions { + os: "os".into(), + relocation_model: RelocModel::Static, + panic_strategy: PanicStrategy::Abort, + pre_link_objects: crt_objects::pre_os(), + ..Default::default() + } +} diff --git a/compiler/rustc_target/src/spec/crt_objects.rs b/compiler/rustc_target/src/spec/crt_objects.rs index e3b6430a463..700543b4c99 100644 --- a/compiler/rustc_target/src/spec/crt_objects.rs +++ b/compiler/rustc_target/src/spec/crt_objects.rs @@ -122,3 +122,7 @@ pub(super) fn pre_wasi_self_contained() -> CrtObjects { pub(super) fn post_wasi_self_contained() -> CrtObjects { new(&[]) } + +pub(super) fn pre_os() -> CrtObjects { + all("crt0.o") +} diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 82e11a3afce..22ebc3bf3a0 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1946,6 +1946,7 @@ supported_targets! { ("riscv32imafc-unknown-nuttx-elf", riscv32imafc_unknown_nuttx_elf), ("riscv64imac-unknown-nuttx-elf", riscv64imac_unknown_nuttx_elf), ("riscv64gc-unknown-nuttx-elf", riscv64gc_unknown_nuttx_elf), + ("x86_64-unknown-os", x86_64_unknown_os), } diff --git a/compiler/rustc_target/src/spec/targets/x86_64_unknown_os.rs b/compiler/rustc_target/src/spec/targets/x86_64_unknown_os.rs new file mode 100644 index 00000000000..376456ea28d --- /dev/null +++ b/compiler/rustc_target/src/spec/targets/x86_64_unknown_os.rs @@ -0,0 +1,20 @@ +use crate::spec::{Target, TargetMetadata, base}; + +pub(crate) fn target() -> Target { + let mut base = base::os::opts(); + base.cpu = "x86-64".into(); + Target { + llvm_target: "x86_64-unknown-none".into(), + metadata: TargetMetadata { + description: None, + tier: None, + host_tools: Some(false), + std: Some(true), + }, + pointer_width: 64, + arch: "x86_64".into(), + data_layout: + "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(), + options: base, + } +} diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 5f8dcde189b..d8c2462a0eb 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -151,5 +151,5 @@ check-cfg = [ # of declared features, we therefor expect any feature cfg 'cfg(feature, values(any()))', # #[cfg(bootstrap)] rtems - 'cfg(target_os, values("rtems"))', + 'cfg(target_os, values("rtems", "os"))', ] diff --git a/library/std/build.rs b/library/std/build.rs index 032326556bd..fc40cf92f41 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -56,6 +56,7 @@ fn main() { || target_os == "zkvm" || target_os == "rtems" || target_os == "nuttx" + || target_os == "os" // See src/bootstrap/src/core/build_steps/synthetic_targets.rs || env::var("RUSTC_BOOTSTRAP_SYNTHETIC_TARGET").is_ok() diff --git a/library/std/src/sys/pal/mod.rs b/library/std/src/sys/pal/mod.rs index 9be018c8a53..adabbdae88b 100644 --- a/library/std/src/sys/pal/mod.rs +++ b/library/std/src/sys/pal/mod.rs @@ -61,6 +61,9 @@ cfg_if::cfg_if! { } else if #[cfg(target_os = "zkvm")] { mod zkvm; pub use self::zkvm::*; + } else if #[cfg(target_os = "os")] { + mod osstd; + pub use self::osstd::*; } else { mod unsupported; pub use self::unsupported::*; diff --git a/library/std/src/sys/pal/os/args.rs b/library/std/src/sys/pal/osstd/args.rs similarity index 100% rename from library/std/src/sys/pal/os/args.rs rename to library/std/src/sys/pal/osstd/args.rs diff --git a/library/std/src/sys/pal/os/common.rs b/library/std/src/sys/pal/osstd/common.rs similarity index 100% rename from library/std/src/sys/pal/os/common.rs rename to library/std/src/sys/pal/osstd/common.rs diff --git a/library/std/src/sys/pal/os/env.rs b/library/std/src/sys/pal/osstd/env.rs similarity index 100% rename from library/std/src/sys/pal/os/env.rs rename to library/std/src/sys/pal/osstd/env.rs diff --git a/library/std/src/sys/pal/os/fs.rs b/library/std/src/sys/pal/osstd/fs.rs similarity index 100% rename from library/std/src/sys/pal/os/fs.rs rename to library/std/src/sys/pal/osstd/fs.rs diff --git a/library/std/src/sys/pal/os/io.rs b/library/std/src/sys/pal/osstd/io.rs similarity index 100% rename from library/std/src/sys/pal/os/io.rs rename to library/std/src/sys/pal/osstd/io.rs diff --git a/library/std/src/sys/pal/os/mod.rs b/library/std/src/sys/pal/osstd/mod.rs similarity index 100% rename from library/std/src/sys/pal/os/mod.rs rename to library/std/src/sys/pal/osstd/mod.rs diff --git a/library/std/src/sys/pal/os/net.rs b/library/std/src/sys/pal/osstd/net.rs similarity index 100% rename from library/std/src/sys/pal/os/net.rs rename to library/std/src/sys/pal/osstd/net.rs diff --git a/library/std/src/sys/pal/os/os.rs b/library/std/src/sys/pal/osstd/os.rs similarity index 100% rename from library/std/src/sys/pal/os/os.rs rename to library/std/src/sys/pal/osstd/os.rs diff --git a/library/std/src/sys/pal/os/pipe.rs b/library/std/src/sys/pal/osstd/pipe.rs similarity index 100% rename from library/std/src/sys/pal/os/pipe.rs rename to library/std/src/sys/pal/osstd/pipe.rs diff --git a/library/std/src/sys/pal/os/process.rs b/library/std/src/sys/pal/osstd/process.rs similarity index 100% rename from library/std/src/sys/pal/os/process.rs rename to library/std/src/sys/pal/osstd/process.rs diff --git a/library/std/src/sys/pal/os/stdio.rs b/library/std/src/sys/pal/osstd/stdio.rs similarity index 100% rename from library/std/src/sys/pal/os/stdio.rs rename to library/std/src/sys/pal/osstd/stdio.rs diff --git a/library/std/src/sys/pal/os/thread.rs b/library/std/src/sys/pal/osstd/thread.rs similarity index 100% rename from library/std/src/sys/pal/os/thread.rs rename to library/std/src/sys/pal/osstd/thread.rs diff --git a/library/std/src/sys/pal/os/time.rs b/library/std/src/sys/pal/osstd/time.rs similarity index 100% rename from library/std/src/sys/pal/os/time.rs rename to library/std/src/sys/pal/osstd/time.rs diff --git a/library/std/src/sys/thread_local/mod.rs b/library/std/src/sys/thread_local/mod.rs index 31d3b439060..81f2d4b7907 100644 --- a/library/std/src/sys/thread_local/mod.rs +++ b/library/std/src/sys/thread_local/mod.rs @@ -28,6 +28,7 @@ cfg_if::cfg_if! { all(target_family = "wasm", not(target_feature = "atomics")), target_os = "uefi", target_os = "zkvm", + target_os = "os", ))] { mod statik; pub use statik::{EagerStorage, LazyStorage, thread_local_inner};