Skip to content

Commit

Permalink
Remove -msys2 variant
Browse files Browse the repository at this point in the history
  • Loading branch information
Berrysoft committed Jan 3, 2025
1 parent 8b0a4ef commit 619a2a9
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 87 deletions.
63 changes: 3 additions & 60 deletions compiler/rustc_target/src/spec/base/cygwin.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
use std::borrow::Cow;

use crate::spec::{
Cc, DebuginfoKind, LinkerFlavor, Lld, SplitDebuginfo, Target, TargetOptions, cvs,
};
use crate::spec::{Cc, DebuginfoKind, LinkerFlavor, Lld, SplitDebuginfo, TargetOptions, cvs};

#[derive(Clone, Copy)]
pub(crate) enum CygwinVariant {
Cygwin,
MSYS2,
}

fn opts(env: CygwinVariant) -> TargetOptions {
pub(crate) fn opts() -> TargetOptions {
let mut pre_link_args = TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), &[
// FIXME: Disable ASLR for now to fix relocation error
"--disable-dynamicbase",
Expand All @@ -23,27 +15,17 @@ fn opts(env: CygwinVariant) -> TargetOptions {
"-Wl,--disable-dynamicbase",
"-Wl,--enable-auto-image-base",
]);
// cygwin runtime lib
let clib = match env {
CygwinVariant::Cygwin => "-lcygwin",
CygwinVariant::MSYS2 => "-lmsys-2.0",
};
let cygwin_libs = &[clib, "-lgcc", clib, "-luser32", "-lkernel32", "-lgcc_s"];
let cygwin_libs = &["-lcygwin", "-lgcc", "-lcygwin", "-luser32", "-lkernel32", "-lgcc_s"];
let mut late_link_args =
TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), cygwin_libs);
crate::spec::add_link_args(
&mut late_link_args,
LinkerFlavor::Gnu(Cc::Yes, Lld::No),
cygwin_libs,
);
let target_env = match env {
CygwinVariant::Cygwin => "",
CygwinVariant::MSYS2 => "msys2",
};
TargetOptions {
os: "cygwin".into(),
vendor: "pc".into(),
env: target_env.into(),
// FIXME(#13846) this should be enabled for cygwin
function_sections: false,
linker: Some("gcc".into()),
Expand All @@ -67,42 +49,3 @@ fn opts(env: CygwinVariant) -> TargetOptions {
..Default::default()
}
}

pub(crate) fn x86_64_target(env: CygwinVariant) -> Target {
let mut base = opts(env);
base.cpu = "x86-64".into();
// FIXME: Disable ASLR for now to fix relocation error
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), &[
"-m",
"i386pep",
"--disable-high-entropy-va",
]);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[
"-m64",
"-Wl,--disable-high-entropy-va",
]);
base.max_atomic_width = Some(64);
let linker = match env {
CygwinVariant::Cygwin => "x86_64-pc-cygwin-gcc",
CygwinVariant::MSYS2 => "x86_64-pc-msys-gcc",
};
let description = match env {
CygwinVariant::Cygwin => "64-bit x86 Cygwin",
CygwinVariant::MSYS2 => "64-bit x86 MSYS2",
};
base.linker = Some(linker.into());
Target {
llvm_target: "x86_64-pc-cygwin".into(),
pointer_width: 64,
data_layout:
"e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(),
arch: "x86_64".into(),
options: base,
metadata: crate::spec::TargetMetadata {
description: Some(description.into()),
tier: Some(3),
host_tools: Some(false),
std: Some(true),
},
}
}
1 change: 0 additions & 1 deletion compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,6 @@ supported_targets! {
("riscv64gc-unknown-nuttx-elf", riscv64gc_unknown_nuttx_elf),

("x86_64-pc-cygwin", x86_64_pc_cygwin),
("x86_64-pc-cygwin-msys2", x86_64_pc_cygwin_msys2),
}

/// Cow-Vec-Str: Cow<'static, [Cow<'static, str>]>
Expand Down
31 changes: 29 additions & 2 deletions compiler/rustc_target/src/spec/targets/x86_64_pc_cygwin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
use crate::spec::{Target, base};
use crate::spec::{Cc, LinkerFlavor, Lld, Target, base};

pub(crate) fn target() -> Target {
base::cygwin::x86_64_target(base::cygwin::CygwinVariant::Cygwin)
let mut base = base::cygwin::opts();
base.cpu = "x86-64".into();
// FIXME: Disable ASLR for now to fix relocation error
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), &[
"-m",
"i386pep",
"--disable-high-entropy-va",
]);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[
"-m64",
"-Wl,--disable-high-entropy-va",
]);
base.max_atomic_width = Some(64);
base.linker = Some("x86_64-pc-cygwin-gcc".into());
Target {
llvm_target: "x86_64-pc-cygwin".into(),
pointer_width: 64,
data_layout:
"e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(),
arch: "x86_64".into(),
options: base,
metadata: crate::spec::TargetMetadata {
description: Some("64-bit x86 Cygwin".into()),
tier: Some(3),
host_tools: Some(false),
std: Some(true),
},
}
}

This file was deleted.

1 change: 0 additions & 1 deletion src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
- [\*-win7-windows-msvc](platform-support/win7-windows-msvc.md)
- [x86_64-fortanix-unknown-sgx](platform-support/x86_64-fortanix-unknown-sgx.md)
- [x86_64-pc-cygwin](platform-support/x86_64-pc-cygwin.md)
- [x86_64-pc-cygwin-msys2](platform-support/x86_64-pc-cygwin.md)
- [x86_64-pc-solaris](platform-support/solaris.md)
- [x86_64-unknown-linux-none.md](platform-support/x86_64-unknown-linux-none.md)
- [x86_64-unknown-none](platform-support/x86_64-unknown-none.md)
Expand Down
1 change: 0 additions & 1 deletion src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ target | std | host | notes
[`x86_64-apple-tvos`](platform-support/apple-tvos.md) | ✓ | | x86 64-bit tvOS
[`x86_64-apple-watchos-sim`](platform-support/apple-watchos.md) | ✓ | | x86 64-bit Apple WatchOS simulator
[`x86_64-pc-cygwin`](platform-support/x86_64-pc-cygwin.md) | ? | | 64-bit x86 Cygwin |
[`x86_64-pc-cygwin-msys2`](platform-support/x86_64-pc-cygwin.md) | ? | | 64-bit x86 MSYS2 |
[`x86_64-pc-nto-qnx710`](platform-support/nto-qnx.md) | ✓ | | x86 64-bit QNX Neutrino 7.1 RTOS |
[`x86_64-unikraft-linux-musl`](platform-support/unikraft-linux-musl.md) | ✓ | | 64-bit Unikraft with musl 1.2.3
`x86_64-unknown-dragonfly` | ✓ | ✓ | 64-bit DragonFlyBSD
Expand Down
21 changes: 8 additions & 13 deletions src/doc/rustc/src/platform-support/x86_64-pc-cygwin.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

**Tier: 3**

Windows targets supporting Cygwin and MSYS2.
The `*-cygwin-*` targets are **not** intended as native targets for applications,
Windows targets supporting Cygwin.
The `*-cygwin` targets are **not** intended as native target for applications,
a developer writing Windows applications should use the `*-pc-windows-*` targets instead, which are *native* Windows.

Cygwin is only intended as an emulation layer for Unix-only programs which do not support the native Windows targets.
Expand All @@ -14,19 +14,14 @@ Cygwin is only intended as an emulation layer for Unix-only programs which do no

## Requirements

This target is cross compiled. Different `target_env` needs different linker:
- `x86_64-pc-cygwin`: `x86_64-pc-cygwin-gcc`
- `x86_64-pc-cygwin-msys2`: `x86_64-pc-msys-gcc`
This target is cross compiled. It needs `x86_64-pc-cygwin-gcc` as linker.

The difference between two targets are small.
The `target_os` of these targets are `cygwin`, and they are `unix`.

To gain high performance, users are recommended to use *more* native targets, e.g., `x86_64-pc-windows-*`.
The `target_os` of the target is `cygwin`, and it is `unix`.

## Building the target

For cross-compilation you want LLVM with [llvm/llvm-project#121439](https://github.com/llvm/llvm-project/pull/121439) applied to fix the LLVM codegen on importing external global variables from DLLs.
No native builds on Cygwin or MSYS2 now. It should be possible theoretically though, but might need a lot of patches.
For cross-compilation you want LLVM with [llvm/llvm-project#121439 (merged)](https://github.com/llvm/llvm-project/pull/121439) applied to fix the LLVM codegen on importing external global variables from DLLs.
No native builds on Cygwin now. It should be possible theoretically though, but might need a lot of patches.

## Building Rust programs

Expand All @@ -37,8 +32,8 @@ this target, you will either need to build Rust with the target enabled (see

## Testing

Created binaries work fine on Windows with Cygwin or MSYS2.
Created binaries work fine on Windows with Cygwin.

## Cross-compilation toolchains and C code

Compatible C code can be built with GCC shipped with Cygwin or MSYS2. Clang is untested.
Compatible C code can be built with GCC shipped with Cygwin. Clang is untested.
3 changes: 0 additions & 3 deletions tests/assembly/targets/targets-pe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@
//@ revisions: x86_64_pc_cygwin
//@ [x86_64_pc_cygwin] compile-flags: --target x86_64-pc-cygwin
//@ [x86_64_pc_cygwin] needs-llvm-components: x86
//@ revisions: x86_64_pc_cygwin_msys2
//@ [x86_64_pc_cygwin_msys2] compile-flags: --target x86_64-pc-cygwin-msys2
//@ [x86_64_pc_cygwin_msys2] needs-llvm-components: x86

// Sanity-check that each target can produce assembly code.

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/check-cfg/well-known-values.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
LL | target_env = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_env` are: ``, `gnu`, `msvc`, `msys2`, `musl`, `newlib`, `nto70`, `nto71`, `ohos`, `p1`, `p2`, `relibc`, `sgx`, and `uclibc`
= note: expected values for `target_env` are: ``, `gnu`, `msvc`, `musl`, `newlib`, `nto70`, `nto71`, `ohos`, `p1`, `p2`, `relibc`, `sgx`, and `uclibc`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration

warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
Expand Down

0 comments on commit 619a2a9

Please sign in to comment.