Skip to content

Build aarch64-apple-darwin binaries on CI #6989

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

Merged
merged 1 commit into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
114 changes: 96 additions & 18 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ env:
RUSTUP_MAX_RETRIES: 10

jobs:
dist:
name: dist
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-16.04, windows-latest, macos-latest]
dist-windows:
name: dist (Windows)
runs-on: windows-latest

steps:
- name: Checkout repository
Expand All @@ -30,8 +27,7 @@ jobs:
# which takes a long time. The fastest way to do this is to rename the
# existing folder, as deleting it takes about as much time as not doing
# anything and just updating rust-docs.
- name: Rename existing rust toolchain (Windows)
if: matrix.os == 'windows-latest'
- name: Rename existing rust toolchain
run: Rename-Item C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc.old

- name: Install Rust toolchain
Expand All @@ -41,38 +37,116 @@ jobs:
profile: minimal
override: true

- name: Dist
run: cargo xtask dist
env:
RA_TARGET: x86_64-pc-windows-msvc

- name: Upload artifacts
uses: actions/upload-artifact@v1
with:
name: dist-windows-latest
path: ./dist

dist-ubuntu:
name: dist (Ubuntu 16.04)
runs-on: ubuntu-16.04

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true

- name: Install Nodejs
if: matrix.os == 'ubuntu-16.04'
uses: actions/setup-node@v1
with:
node-version: 12.x

- name: Dist
if: matrix.os == 'ubuntu-16.04' && github.ref == 'refs/heads/release'
if: github.ref == 'refs/heads/release'
run: cargo xtask dist --client 0.2.$GITHUB_RUN_NUMBER
env:
RA_TARGET: x86_64-unknown-linux-gnu

- name: Dist
if: matrix.os == 'ubuntu-16.04' && github.ref != 'refs/heads/release'
if: github.ref != 'refs/heads/release'
run: cargo xtask dist --nightly --client 0.3.$GITHUB_RUN_NUMBER-nightly
env:
RA_TARGET: x86_64-unknown-linux-gnu

- name: Nightly analysis-stats check
if: github.ref != 'refs/heads/release'
run: ./dist/rust-analyzer-x86_64-unknown-linux-gnu analysis-stats .

- name: Upload artifacts
uses: actions/upload-artifact@v1
with:
name: dist-ubuntu-16.04
path: ./dist

dist-macos-latest:
name: dist (MacOS latest)
runs-on: macos-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true

- name: Dist
if: matrix.os != 'ubuntu-16.04'
run: cargo xtask dist
env:
RA_TARGET: x86_64-apple-darwin

- name: Nightly analysis-stats check
if: matrix.os == 'ubuntu-16.04' && github.ref != 'refs/heads/release'
run: ./dist/rust-analyzer-linux analysis-stats .
- name: Upload artifacts
uses: actions/upload-artifact@v1
with:
name: dist-macos-latest
path: ./dist

dist-macos-11:
name: dist (MacOS 11.0)
runs-on: macos-11.0

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Rust toolchain (beta)
uses: actions-rs/toolchain@v1
with:
toolchain: beta
target: aarch64-apple-darwin
profile: minimal
override: true

- name: Dist
run: cargo xtask dist
env:
RA_TARGET: aarch64-apple-darwin

- name: Upload artifacts
uses: actions/upload-artifact@v1
with:
name: dist-${{ matrix.os }}
name: dist-macos-11.0
path: ./dist

publish:
name: publish
runs-on: ubuntu-16.04
needs: ['dist']
needs: ['dist-windows', 'dist-ubuntu', 'dist-macos-latest', 'dist-macos-11']
steps:
- name: Install Nodejs
uses: actions/setup-node@v1
Expand All @@ -91,6 +165,10 @@ jobs:
- run: echo "HEAD_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
- run: 'echo "HEAD_SHA: $HEAD_SHA"'

- uses: actions/download-artifact@v1
with:
name: dist-macos-11.0
path: dist
- uses: actions/download-artifact@v1
with:
name: dist-macos-latest
Expand All @@ -103,7 +181,7 @@ jobs:
with:
name: dist-windows-latest
path: dist
- run: ls -all ./dist
- run: ls -al ./dist

- name: Publish Release
uses: ./.github/actions/github-release
Expand Down
72 changes: 58 additions & 14 deletions xtask/src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,74 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> {
}

fn dist_server() -> Result<()> {
if cfg!(target_os = "linux") {
let target = get_target();
if target.contains("-linux-gnu") {
env::set_var("CC", "clang");
}
cmd!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release").run()?;

let (src, dst) = if cfg!(target_os = "linux") {
("./target/release/rust-analyzer", "./dist/rust-analyzer-linux")
} else if cfg!(target_os = "windows") {
("./target/release/rust-analyzer.exe", "./dist/rust-analyzer-windows.exe")
} else if cfg!(target_os = "macos") {
("./target/release/rust-analyzer", "./dist/rust-analyzer-mac")
} else {
panic!("Unsupported OS")
};

let src = Path::new(src);
let dst = Path::new(dst);
let toolchain = toolchain(&target);
cmd!("cargo +{toolchain} build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target} --release").run()?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this works..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THe +{toolchain} syntax? Yeah, it should work


let suffix = exe_suffix(&target);
let src =
Path::new("target").join(&target).join("release").join(format!("rust-analyzer{}", suffix));
let dst = Path::new("dist").join(format!("rust-analyzer-{}{}", target, suffix));
cp(&src, &dst)?;
gzip(&src, &dst.with_extension("gz"))?;

// FIXME: the old names are temporarily kept for client compatibility, but they should be removed
// Remove this block after a couple of releases
match target.as_ref() {
"x86_64-unknown-linux-gnu" => {
cp(&src, "dist/rust-analyzer-linux")?;
gzip(&src, Path::new("dist/rust-analyzer-linux.gz"))?;
}
"x86_64-pc-windows-msvc" => {
cp(&src, "dist/rust-analyzer-windows.exe")?;
gzip(&src, Path::new("dist/rust-analyzer-windows.gz"))?;
}
"x86_64-apple-darwin" => {
cp(&src, "dist/rust-analyzer-mac")?;
gzip(&src, Path::new("dist/rust-analyzer-mac.gz"))?;
}
_ => {}
}

Ok(())
}

fn get_target() -> String {
match env::var("RA_TARGET") {
Ok(target) => target,
_ => {
if cfg!(target_os = "linux") {
"x86_64-unknown-linux-gnu".to_string()
} else if cfg!(target_os = "windows") {
"x86_64-pc-windows-msvc".to_string()
} else if cfg!(target_os = "macos") {
"x86_64-apple-darwin".to_string()
} else {
panic!("Unsupported OS, maybe try setting RA_TARGET")
}
}
}
}

fn exe_suffix(target: &str) -> String {
if target.contains("-windows-") {
".exe".into()
} else {
"".into()
}
}

fn toolchain(target: &str) -> String {
match target {
"aarch64-apple-darwin" => "beta".to_string(),
_ => "stable".to_string(),
}
}

fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> {
let mut encoder = GzEncoder::new(File::create(dest_path)?, Compression::best());
let mut input = io::BufReader::new(File::open(src_path)?);
Expand Down