Skip to content

Add back Windows cross-compilation support #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
04bcdac
Ensure proper flags are used with GAS
Jake-Shadle Nov 12, 2020
031f820
Attempt to actually pass the assembler-with-cpp
Jake-Shadle Nov 12, 2020
91939d6
Uppercase other assembly files
Jake-Shadle Nov 12, 2020
6fdad9a
Oops
Jake-Shadle Nov 12, 2020
31a03e2
Revert change to .s extensions
Jake-Shadle Nov 13, 2020
1a0879d
Add workaround for clang-cl + -xassembler-with-cpp flag
Jake-Shadle Nov 13, 2020
573db08
Address feedback
Jake-Shadle Nov 13, 2020
1b02c9f
Fixup rebase
Jake-Shadle Feb 14, 2022
2b8fe30
Choose MASM or GAS based on existence of MS assemblers
Jake-Shadle Feb 14, 2022
4220121
Add test job for windows cross compilation
Jake-Shadle Feb 14, 2022
121a36f
Actually install wine, derp
Jake-Shadle Feb 14, 2022
ded3d3f
Fix script for old rust versions
Jake-Shadle Feb 14, 2022
dc6f5b7
Apparently one must lookujp the tool, so...meh, simplify
Jake-Shadle Feb 14, 2022
d6788b5
Fixup job
Jake-Shadle Feb 14, 2022
4e33fd9
Forgot github actions requires sudo
Jake-Shadle Feb 14, 2022
a71c5c1
Argh
Jake-Shadle Feb 14, 2022
51ae132
And again
Jake-Shadle Feb 14, 2022
0306349
Try forcing older stable
Jake-Shadle Feb 14, 2022
9adf478
Ignore i386
Jake-Shadle Feb 14, 2022
a3a9a42
Why is wine sucha PITA on Ubuntu
Jake-Shadle Feb 14, 2022
cf1cb31
Sigh
Jake-Shadle Feb 14, 2022
4b8ec5e
Why apt, why
Jake-Shadle Feb 14, 2022
592d374
Are you kiddin gme
Jake-Shadle Feb 14, 2022
34e8249
Well that got out of hand
Jake-Shadle Feb 14, 2022
7ca1f63
Just skip testing
Jake-Shadle Feb 14, 2022
bd85f2c
Oops
Jake-Shadle Feb 14, 2022
d911b45
Oops again
Jake-Shadle Feb 14, 2022
885f8af
TIL
Jake-Shadle Feb 14, 2022
d9d8de2
Stacker compiles C code
Jake-Shadle Feb 14, 2022
78eb6e2
Use correct install location
Jake-Shadle Feb 14, 2022
f454d8d
Fix key
Jake-Shadle Feb 14, 2022
8dde4ce
Address feedback
Jake-Shadle Feb 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- '*.mkd'
- 'LICENSE'
pull_request:
types: [opened, repoened, synchronize]
types: [opened, reopened, synchronize]

jobs:
native-test:
Expand Down Expand Up @@ -257,6 +257,60 @@ jobs:
command: build
args: --target=${{ matrix.rust_target }} --manifest-path=${{ matrix.manifest }}

cross-windows-build:
name: Cross-compile ${{ matrix.manifest }} for ${{ matrix.rust_target }} from x86_64-unknown-linux-gnu
runs-on: ubuntu-20.04
strategy:
fail-fast: true
matrix:
rust_target:
- x86_64-pc-windows-msvc
- i686-pc-windows-msvc
manifest: ['psm/Cargo.toml', 'Cargo.toml']
xwin_version: ["0.1.6"]
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
target: ${{ matrix.rust_target }}
- name: Add toolchain shims
run: |
set -eux
sudo ln -s clang-12 /usr/bin/clang-cl
sudo ln -s llvm-ar-12 /usr/bin/llvm-lib
sudo ln -s lld-link-12 /usr/bin/lld-link
- name: Install Windows SDK
run: |
set -eux
xwin_version=${{ matrix.xwin_version }}
xwin_prefix="xwin-$xwin_version-x86_64-unknown-linux-musl"

# Install xwin to cargo/bin via github release. Note you could also just use `cargo install xwin`.
curl --fail -L https://github.com/Jake-Shadle/xwin/releases/download/$xwin_version/$xwin_prefix.tar.gz | tar -xzv -C /home/runner/.cargo/bin --strip-components=1 $xwin_prefix/xwin

# Splat the CRT and SDK files to /tmp/xwin/crt and /tmp/xwin/sdk respectively
xwin --accept-license 1 splat --output /tmp/xwin
- name: Test
env:
CC: "clang-cl"
CXX: "clang-cl"
AR: "llvm-lib"
CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER: "lld-link"
CARGO_TARGET_I686_PC_WINDOWS_MSVC_LINKER: "lld-link"
# Note that we only disable unused-command-line-argument here since clang-cl
# doesn't implement all of the options supported by cl, but the ones it doesn't
# are _generally_ not interesting.
CFLAGS: "-Wno-unused-command-line-argument -fuse-ld=lld-link /imsvc/tmp/xwin/crt/include /imsvc/tmp/xwin/sdk/include/ucrt /imsvc/tmp/xwin/sdk/include/um /imsvc/tmp/xwin/sdk/include/shared"
# Inform the linker where to search for libraries
RUSTFLAGS: "-Lnative=/tmp/xwin/crt/lib/x86_64 -Lnative=/tmp/xwin/sdk/lib/um/x86_64 -Lnative=/tmp/xwin/sdk/lib/ucrt/x86_64"
run: |
set -eux
cargo build --target ${{ matrix.rust_target }} --manifest-path ${{ matrix.manifest }}

wasm-test:
name: Test stacker on WASM
runs-on: ubuntu-latest
Expand Down
22 changes: 17 additions & 5 deletions psm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,26 @@ fn find_assembly(
}

fn main() {
let arch = ::std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let env = ::std::env::var("CARGO_CFG_TARGET_ENV").unwrap();
let os = ::std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let endian = ::std::env::var("CARGO_CFG_TARGET_ENDIAN").unwrap();
use std::env::var;

let arch = var("CARGO_CFG_TARGET_ARCH").unwrap();
let env = var("CARGO_CFG_TARGET_ENV").unwrap();
let os = var("CARGO_CFG_TARGET_OS").unwrap();
let endian = var("CARGO_CFG_TARGET_ENDIAN").unwrap();

let mut cfg = cc::Build::new();

let msvc = cfg.get_compiler().is_like_msvc();
let asm = if let Some((asm, canswitch)) = find_assembly(&arch, &endian, &os, &env, msvc) {
// If we're targeting msvc, either via regular MS toolchain or clang-cl, we
// will _usually_ want to use the regular Microsoft assembler if it exists,
// which is done for us within cc, however it _probably_ won't exist if
// we're in a cross-compilation context pm a platform that can't natively
// run Windows executables, so in that case we instead use the the equivalent
// GAS assembly file instead. This logic can be removed once LLVM natively
// supports compiling MASM, but that is not stable yet
let masm = msvc && var("HOST").expect("HOST env not set").contains("windows");

let asm = if let Some((asm, canswitch)) = find_assembly(&arch, &endian, &os, &env, masm) {
println!("cargo:rustc-cfg=asm");
if canswitch {
println!("cargo:rustc-cfg=switchable_stack")
Expand Down