Skip to content

Commit

Permalink
Update release process to support current app layout.
Browse files Browse the repository at this point in the history
  • Loading branch information
turbobot-temp authored and nathanhammond committed Dec 12, 2022
1 parent 8150bda commit 0d1eaa4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/build_rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ jobs:
target: "aarch64-unknown-linux-gnu"
lib-cache-key: turbo-lib-cross-${{ inputs.release_branch }}
rustflags: 'RUSTFLAGS="-C linker=aarch64-linux-gnu-gcc"'
setup: "sudo apt-get install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu"
setup: "sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu"
- host: windows-latest
target: x86_64-pc-windows-gnu
lib-cache-key: turbo-lib-cross-${{ inputs.release_branch }}
setup: "mv cli/libturbo/turbo-windows_windows_amd64_v1/lib/turbo.exe cli/libturbo/turbo-windows_windows_amd64_v1/lib/libturbo.a && mv cli/libturbo/turbo-windows_windows_amd64_v1/lib/turbo.h cli/libturbo/turbo-windows_windows_amd64_v1/lib/libturbo.h && rustup set default-host x86_64-pc-windows-gnu"
runs-on: ${{ matrix.settings.host }}
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -82,7 +83,7 @@ jobs:
# https://github.com/actions/download-artifact#download-all-artifacts
name: ${{ matrix.settings.lib-cache-key }}
# Optional, a directory where to extract artifact(s), defaults to the current directory
path: shim/libturbo
path: cli/libturbo
# Optional, choose how to exit the action if no artifact is found
# can be one of:
# "fail", "warn", "ignore"
Expand All @@ -94,8 +95,9 @@ jobs:
# uses: actions/download-artifact@v3
# with:
# name: ${{ matrix.settings.lib-cache-key }}
# path: shim/libturbo
# path: cli/libturbo
- name: Build Setup
shell: bash
if: ${{ matrix.settings.setup }}
run: ${{ matrix.settings.setup }}

Expand Down
50 changes: 31 additions & 19 deletions shim/build.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
use std::{env, path::PathBuf, process::Command};

fn main() {
let is_release = matches!(env::var("PROFILE"), Ok(profile) if profile == "release");
let lib_search_path = if is_release && env::var("RELEASE_TURBO_CLI") == Ok("true".to_string()) {
let is_ci_release = matches!(env::var("PROFILE"), Ok(profile) if profile == "release")
&& env::var("RELEASE_TURBO_CLI")
.map(|val| val == "true")
.unwrap_or(false);
let lib_search_path = if is_ci_release {
expect_release_lib()
} else {
build_debug_libturbo()
};
println!("cargo:rerun-if-changed={}", lib_search_path);
println!("cargo:rustc-link-search={}", lib_search_path);
println!(
"cargo:rerun-if-changed={}",
lib_search_path.to_string_lossy()
);
println!(
"cargo:rustc-link-search={}",
lib_search_path.to_string_lossy()
);
println!("cargo:rustc-link-lib=turbo");

let target = build_target::target().unwrap();
let bindings = bindgen::Builder::default()
.header(header_path(&target.os))
.header(
lib_search_path
.join("libturbo.h")
.to_string_lossy(),
)
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
Expand All @@ -31,7 +44,9 @@ fn main() {
}
}

fn expect_release_lib() -> String {
fn expect_release_lib() -> PathBuf {
// We expect all artifacts to be in the cli path
let mut dir = cli_path();
let target = build_target::target().unwrap();
let platform = match target.os {
build_target::Os::MacOs => "darwin",
Expand All @@ -44,19 +59,16 @@ fn expect_release_lib() -> String {
build_target::Arch::X86_64 => "amd64_v1",
_ => panic!("unsupported target {}", target.triple),
};
let mut dir = PathBuf::from("libturbo");
dir.push("libturbo");
// format is ${BUILD_ID}_${OS}_${ARCH}. Build id is, for goreleaser reasons,
// turbo-${OS}
dir.push(format!("turbo-{platform}_{platform}_{arch}"));
dir.push("lib");
dir.to_string_lossy().to_string()
dir
}

fn build_debug_libturbo() -> String {
let cli_path = env::var_os("CARGO_WORKSPACE_DIR")
.map(PathBuf::from)
.unwrap()
.join("cli");
fn build_debug_libturbo() -> PathBuf {
let cli_path = cli_path();
let target = build_target::target().unwrap();
let mut cmd = Command::new("make");
cmd.current_dir(&cli_path);
Expand Down Expand Up @@ -89,12 +101,12 @@ fn build_debug_libturbo() -> String {
.success(),
"failed to build turbo static library"
);
cli_path.to_string_lossy().to_string()
cli_path
}

fn header_path(target: &build_target::Os) -> &'static str {
match target {
build_target::Os::Windows => "../cli/turbo.h",
_ => "../cli/libturbo.h",
}
fn cli_path() -> PathBuf {
env::var_os("CARGO_WORKSPACE_DIR")
.map(PathBuf::from)
.unwrap()
.join("cli")
}

0 comments on commit 0d1eaa4

Please sign in to comment.