Skip to content

Commit a373426

Browse files
ograffUebelAndre
andauthored
Fix Compiling for release for windows (#3398)
Co-authored-by: UebelAndre <[email protected]>
1 parent d3d2f98 commit a373426

File tree

5 files changed

+51
-32
lines changed

5 files changed

+51
-32
lines changed

.github/workflows/cargo_bazel_release.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ defaults:
1414

1515
jobs:
1616
validation:
17-
runs-on: ubuntu-20.04
17+
runs-on: ubuntu-22.04
1818
steps:
19-
- uses: actions/checkout@v3
19+
- uses: actions/checkout@v4
2020
# TODO: Unfortunately it's not obvious how to restrict `workflow_dispatch` to a particular branch
2121
# so this step ensures releases are always done off of `main`.
2222
- name: Ensure branch is 'main'
@@ -31,9 +31,9 @@ jobs:
3131
fi
3232
builds:
3333
needs: validation
34-
runs-on: ubuntu-20.04
34+
runs-on: ubuntu-22.04
3535
steps:
36-
- uses: actions/checkout@v3
36+
- uses: actions/checkout@v4
3737
- name: Install rust toolchains for host
3838
run: |
3939
# Detect the current version of rust

.github/workflows/formatting.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
code-format-checks:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v4
1717
- name: Buildifier
1818
run: |
1919
wget "https://github.com/bazelbuild/buildtools/releases/download/v${BUILDIFIER_VERSION}/buildifier-linux-amd64" -O buildifier

.github/workflows/release.yaml

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
name: Release
33
on:
44
workflow_dispatch:
5+
merge_group:
6+
pull_request:
7+
branches:
8+
- main
9+
paths:
10+
- version.bzl
11+
- .github/workflows/release.yaml
512
push:
613
branches:
714
- main
@@ -17,22 +24,11 @@ env:
1724

1825
jobs:
1926
validation:
20-
runs-on: ubuntu-20.04
27+
runs-on: ubuntu-22.04
2128
steps:
22-
- uses: actions/checkout@v3
23-
# TODO: Unfortunately it's not obvious how to restrict `workflow_dispatch` to a particular branch
24-
# so this step ensures releases are always done off of `main`.
25-
- name: Ensure branch is 'main'
26-
run: |
27-
git fetch origin &> /dev/null
28-
branch="$(git rev-parse --abbrev-ref HEAD)"
29-
if [[ "${branch}" != "main" ]]; then
30-
echo "The release branch must be main. Got '${branch}'' instead." >&2
31-
exit 1
32-
else
33-
echo "Branch is '${branch}'"
34-
fi
29+
- uses: actions/checkout@v4
3530
- name: Ensure release does not already exist
31+
if: startsWith(github.ref, 'refs/heads/main') == false
3632
run: |
3733
git fetch origin &> /dev/null
3834
version="$(grep 'VERSION =' ${{ github.workspace }}/version.bzl | sed 's/VERSION = "//' | sed 's/"//')"
@@ -53,7 +49,7 @@ jobs:
5349
- os: macOS-13
5450
env:
5551
TARGET: "aarch64-apple-darwin"
56-
- os: ubuntu-20.04
52+
- os: ubuntu-22.04
5753
env:
5854
TARGET: "aarch64-unknown-linux-gnu"
5955
- os: windows-2022
@@ -62,20 +58,20 @@ jobs:
6258
- os: macOS-13
6359
env:
6460
TARGET: "x86_64-apple-darwin"
65-
- os: ubuntu-20.04
61+
- os: ubuntu-22.04
6662
env:
6763
TARGET: "x86_64-pc-windows-gnu"
6864
- os: windows-2022
6965
env:
7066
TARGET: "x86_64-pc-windows-msvc"
71-
- os: ubuntu-20.04
67+
- os: ubuntu-22.04
7268
env:
7369
TARGET: "x86_64-unknown-linux-gnu"
74-
- os: ubuntu-20.04
70+
- os: ubuntu-22.04
7571
env:
7672
TARGET: "x86_64-unknown-linux-musl"
7773
steps:
78-
- uses: actions/checkout@v3
74+
- uses: actions/checkout@v4
7975
- name: Install rust toolchains for host
8076
run: |
8177
# Detect the current version of rust
@@ -99,6 +95,8 @@ jobs:
9995
- name: Setup Windows Bazelrc
10096
run: |
10197
echo "startup --output_user_root=C:/tmp" > ./user.bazelrc
98+
echo "startup --windows_enable_symlinks" > ./user.bazelrc
99+
echo "build --enable_runfiles" > ./user.bazelrc
102100
if: startswith(matrix.os, 'Windows')
103101
- name: Build cargo-bazel binaries
104102
run: |
@@ -117,10 +115,11 @@ jobs:
117115
path: ${{ github.workspace }}/crate_universe/target/artifacts/${{ matrix.env.TARGET }}
118116
if-no-files-found: error
119117
release:
118+
if: startsWith(github.ref, 'refs/heads/main')
120119
needs: builds
121-
runs-on: ubuntu-20.04
120+
runs-on: ubuntu-22.04
122121
steps:
123-
- uses: actions/checkout@v3
122+
- uses: actions/checkout@v4
124123
- uses: actions/download-artifact@v4
125124
with:
126125
path: ${{ github.workspace }}/crate_universe/target/artifacts

crate_universe/tools/cross_installer/BUILD.bazel

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ rust_binary(
2323
edition = "2021",
2424
proc_macro_deps = all_crate_deps(proc_macro = True),
2525
rustc_env = {
26-
"CARGO": "$(rootpath @rules_rust//rust/toolchain:current_cargo_files)",
27-
"CROSS_BIN": "$(rootpath :cross)",
28-
"CROSS_CONFIG": "$(rootpath :Cross.toml)",
26+
"CARGO": "$(rlocationpath @rules_rust//rust/toolchain:current_cargo_files)",
27+
"CROSS_BIN": "$(rlocationpath :cross)",
28+
"CROSS_CONFIG_RLOCATION": "$(rlocationpath :Cross.toml)",
2929
},
30-
deps = all_crate_deps(normal = True),
30+
deps = all_crate_deps(normal = True) + ["@rules_rust//rust/runfiles"],
3131
)
3232

3333
filegroup(

crate_universe/tools/cross_installer/src/main.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! A utility for cross compiling binaries using Cross
22
3+
use runfiles::{rlocation, Runfiles};
34
use std::path::{Path, PathBuf};
45
use std::process::{self, Command};
56
use std::{env, fs};
@@ -22,7 +23,13 @@ struct Options {
2223
fn prepare_workspace(workspace_root: &Path) {
2324
// Unfortunately, cross runs into issues when cross compiling incrementally.
2425
// To avoid this, the workspace must be cleaned
25-
let cargo = env::current_dir().unwrap().join(env!("CARGO"));
26+
let r = Runfiles::create().unwrap();
27+
let cargo = rlocation!(r, env!("CARGO")).unwrap();
28+
29+
if !cargo.exists() {
30+
panic!("Cargo binary not found at {}", cargo.display());
31+
}
32+
2633
Command::new(cargo)
2734
.current_dir(workspace_root)
2835
.arg("clean")
@@ -32,7 +39,19 @@ fn prepare_workspace(workspace_root: &Path) {
3239

3340
/// Execute a build for the provided platform
3441
fn execute_cross(working_dir: &Path, target_triple: &str) {
35-
let cross = env::current_dir().unwrap().join(env!("CROSS_BIN"));
42+
let r = Runfiles::create().unwrap();
43+
let cross = rlocation!(r, env!("CROSS_BIN")).unwrap();
44+
45+
if !cross.exists() {
46+
panic!("Cross binary not found at {}", cross.display());
47+
}
48+
49+
let cross_config = rlocation!(r, env!("CROSS_CONFIG_RLOCATION")).unwrap();
50+
51+
if !cross_config.exists() {
52+
panic!("Cross config not found at {}", cross_config.display());
53+
}
54+
3655
let status = Command::new(cross)
3756
.current_dir(working_dir)
3857
.arg("build")
@@ -43,6 +62,7 @@ fn execute_cross(working_dir: &Path, target_triple: &str) {
4362
.arg(format!("--target={target_triple}"))
4463
// https://github.com/cross-rs/cross/issues/1447
4564
.env("CROSS_NO_WARNINGS", "0")
65+
.env("CROSS_CONFIG", cross_config)
4666
.status()
4767
.unwrap();
4868

0 commit comments

Comments
 (0)