mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 14:38:30 +00:00
fix(ci): fix tests
This commit is contained in:
47
.github/workflows/ci.yml
vendored
47
.github/workflows/ci.yml
vendored
@@ -11,6 +11,8 @@ on:
|
|||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
RUSTFLAGS: -Dwarnings
|
RUSTFLAGS: -Dwarnings
|
||||||
|
CARGO_INCREMENTAL: "0"
|
||||||
|
SCCACHE_GHA_ENABLED: "true"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
checks:
|
checks:
|
||||||
@@ -24,7 +26,13 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
components: rustfmt, clippy
|
components: rustfmt, clippy
|
||||||
|
|
||||||
|
- name: sccache
|
||||||
|
uses: mozilla-actions/sccache-action@v0.0.9
|
||||||
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
shared-key: dcr-ci
|
||||||
|
cache-all-crates: true
|
||||||
|
|
||||||
- name: Format
|
- name: Format
|
||||||
run: cargo fmt --all --check
|
run: cargo fmt --all --check
|
||||||
@@ -52,7 +60,22 @@ jobs:
|
|||||||
- name: Setup Rust
|
- name: Setup Rust
|
||||||
uses: dtolnay/rust-toolchain@stable
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
|
||||||
|
- name: sccache
|
||||||
|
uses: mozilla-actions/sccache-action@v0.0.9
|
||||||
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
shared-key: dcr-ci
|
||||||
|
cache-all-crates: true
|
||||||
|
cache-on-failure: true
|
||||||
|
|
||||||
|
- name: Cache apt packages
|
||||||
|
if: runner.os == 'Linux'
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: /var/cache/apt/archives
|
||||||
|
key: apt-${{ runner.os }}-${{ hashFiles('.github/workflows/ci.yml') }}
|
||||||
|
restore-keys: apt-${{ runner.os }}-
|
||||||
|
|
||||||
- name: Install Linux tools
|
- name: Install Linux tools
|
||||||
if: runner.os == 'Linux'
|
if: runner.os == 'Linux'
|
||||||
@@ -64,7 +87,8 @@ jobs:
|
|||||||
nasm \
|
nasm \
|
||||||
clang-format \
|
clang-format \
|
||||||
clang-tidy \
|
clang-tidy \
|
||||||
git
|
git \
|
||||||
|
llvm
|
||||||
|
|
||||||
- name: Install macOS tools
|
- name: Install macOS tools
|
||||||
if: runner.os == 'macOS'
|
if: runner.os == 'macOS'
|
||||||
@@ -76,8 +100,11 @@ jobs:
|
|||||||
if: runner.os == 'Windows'
|
if: runner.os == 'Windows'
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
choco install nasm -y
|
choco install nasm llvm -y
|
||||||
echo "C:\Program Files\NASM" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
echo "C:\Program Files\NASM" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
||||||
|
if (Test-Path "C:\Program Files\LLVM\bin") {
|
||||||
|
echo "C:\Program Files\LLVM\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
||||||
|
}
|
||||||
|
|
||||||
- name: Unit tests (binary crate)
|
- name: Unit tests (binary crate)
|
||||||
run: cargo test --bins -- --nocapture
|
run: cargo test --bins -- --nocapture
|
||||||
@@ -89,6 +116,10 @@ jobs:
|
|||||||
if: runner.os != 'Windows'
|
if: runner.os != 'Windows'
|
||||||
run: cargo test --tests --features archive -- --nocapture
|
run: cargo test --tests --features archive -- --nocapture
|
||||||
|
|
||||||
|
- name: sccache stats
|
||||||
|
if: always()
|
||||||
|
run: sccache --show-stats || true
|
||||||
|
|
||||||
test-archive-linux:
|
test-archive-linux:
|
||||||
name: archive feature smoke
|
name: archive feature smoke
|
||||||
needs: checks
|
needs: checks
|
||||||
@@ -99,15 +130,25 @@ jobs:
|
|||||||
- name: Setup Rust
|
- name: Setup Rust
|
||||||
uses: dtolnay/rust-toolchain@stable
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
|
||||||
|
- name: sccache
|
||||||
|
uses: mozilla-actions/sccache-action@v0.0.9
|
||||||
|
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
shared-key: dcr-ci
|
||||||
|
cache-all-crates: true
|
||||||
|
|
||||||
- name: Install tools
|
- name: Install tools
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y build-essential clang nasm
|
sudo apt-get install -y build-essential clang nasm llvm
|
||||||
|
|
||||||
- name: Build with archive
|
- name: Build with archive
|
||||||
run: cargo build --features archive
|
run: cargo build --features archive
|
||||||
|
|
||||||
- name: Flat-bin + unit suite with archive
|
- name: Flat-bin + unit suite with archive
|
||||||
run: cargo test --features archive --test cli_build --test cli_workspace --test cli_errors -- --nocapture
|
run: cargo test --features archive --test cli_build --test cli_workspace --test cli_errors -- --nocapture
|
||||||
|
|
||||||
|
- name: sccache stats
|
||||||
|
if: always()
|
||||||
|
run: sccache --show-stats || true
|
||||||
|
|||||||
@@ -160,14 +160,12 @@ pub(crate) fn archive_static(
|
|||||||
return Ok(common::elapsed_secs(start_time));
|
return Ok(common::elapsed_secs(start_time));
|
||||||
}
|
}
|
||||||
|
|
||||||
let archiver = ctx.archiver.unwrap_or(if cfg!(target_os = "windows") {
|
let archiver = ctx
|
||||||
"lib"
|
.archiver
|
||||||
} else {
|
.unwrap_or_else(|| default_archiver(ctx.compiler));
|
||||||
"ar"
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut cmd = Command::new(archiver);
|
let mut cmd = Command::new(archiver);
|
||||||
if cfg!(target_os = "windows") && archiver == "lib" {
|
if cfg!(target_os = "windows") && is_msvc_lib(archiver) {
|
||||||
cmd.arg("/nologo").arg(format!("/OUT:{lib_path}"));
|
cmd.arg("/nologo").arg(format!("/OUT:{lib_path}"));
|
||||||
} else {
|
} else {
|
||||||
cmd.arg("rcs").arg(&lib_path);
|
cmd.arg("rcs").arg(&lib_path);
|
||||||
@@ -243,6 +241,26 @@ pub(crate) fn link_binary(
|
|||||||
run(ctx, cmd, start_time)
|
run(ctx, cmd, start_time)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_archiver(compiler: &str) -> &'static str {
|
||||||
|
let c = compiler.to_lowercase();
|
||||||
|
if cfg!(target_os = "windows") {
|
||||||
|
if c.contains("cl") && !c.contains("clang") {
|
||||||
|
"lib"
|
||||||
|
} else if c.contains("clang") {
|
||||||
|
"llvm-ar"
|
||||||
|
} else {
|
||||||
|
"ar"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
"ar"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_msvc_lib(archiver: &str) -> bool {
|
||||||
|
let a = archiver.to_lowercase();
|
||||||
|
a == "lib" || a == "lib.exe" || a.ends_with("\\lib.exe") || a.ends_with("/lib.exe")
|
||||||
|
}
|
||||||
|
|
||||||
fn run(ctx: &BuildContext, mut cmd: Command, start_time: Instant) -> Result<f64, String> {
|
fn run(ctx: &BuildContext, mut cmd: Command, start_time: Instant) -> Result<f64, String> {
|
||||||
if ctx.verbose || std::env::var("DCR_DEBUG").is_ok() {
|
if ctx.verbose || std::env::var("DCR_DEBUG").is_ok() {
|
||||||
eprintln!("[dcr] {:?}", cmd);
|
eprintln!("[dcr] {:?}", cmd);
|
||||||
|
|||||||
@@ -60,8 +60,13 @@ pub fn build(ctx: &BuildContext) -> Result<f64, String> {
|
|||||||
let elapsed = common::elapsed_secs(start_time);
|
let elapsed = common::elapsed_secs(start_time);
|
||||||
return Ok(elapsed);
|
return Ok(elapsed);
|
||||||
}
|
}
|
||||||
let mut cmd = Command::new(ctx.archiver.unwrap_or("lib"));
|
let archiver = ctx.archiver.unwrap_or("lib");
|
||||||
cmd.arg("/nologo").arg(format!("/OUT:{lib_path}"));
|
let mut cmd = Command::new(archiver);
|
||||||
|
if archiver == "lib" || archiver.eq_ignore_ascii_case("lib.exe") {
|
||||||
|
cmd.arg("/nologo").arg(format!("/OUT:{lib_path}"));
|
||||||
|
} else {
|
||||||
|
cmd.arg("rcs").arg(&lib_path);
|
||||||
|
}
|
||||||
for obj in &objects {
|
for obj in &objects {
|
||||||
cmd.arg(obj);
|
cmd.arg(obj);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,11 +117,15 @@ fn registry_dependency_is_built_from_cache() {
|
|||||||
"[registry.local]\nurl = \"file://local\"\npriority = 1\n",
|
"[registry.local]\nurl = \"file://local\"\npriority = 1\n",
|
||||||
)
|
)
|
||||||
.expect("failed to write registry config");
|
.expect("failed to write registry config");
|
||||||
|
let dep_path = dep
|
||||||
|
.canonicalize()
|
||||||
|
.unwrap_or(dep.clone())
|
||||||
|
.to_string_lossy()
|
||||||
|
.replace('\\', "/");
|
||||||
std::fs::write(
|
std::fs::write(
|
||||||
dcr_home.join("index.json"),
|
dcr_home.join("index.json"),
|
||||||
format!(
|
format!(
|
||||||
"{{\"packages\":[{{\"name\":\"mylib\",\"latest_version\":\"0.1.0\",\"path\":\"{}\"}}]}}",
|
"{{\"packages\":[{{\"name\":\"mylib\",\"latest_version\":\"0.1.0\",\"path\":\"{dep_path}\"}}]}}"
|
||||||
dep.display()
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.expect("failed to write registry index");
|
.expect("failed to write registry index");
|
||||||
@@ -151,11 +155,16 @@ fn registry_dependency_is_built_from_cache() {
|
|||||||
.expect("failed to write app source");
|
.expect("failed to write app source");
|
||||||
|
|
||||||
let index_path = dcr_home.join("index.json");
|
let index_path = dcr_home.join("index.json");
|
||||||
let envs = [
|
let home_s = home.to_string_lossy().to_string();
|
||||||
|
let index_s = index_path.to_string_lossy().to_string();
|
||||||
|
let mut envs = vec![
|
||||||
("DCR_COMPILER", compiler),
|
("DCR_COMPILER", compiler),
|
||||||
("HOME", home.to_str().unwrap()),
|
("HOME", home_s.as_str()),
|
||||||
("DCR_INDEX_PATH", index_path.to_str().unwrap()),
|
("DCR_INDEX_PATH", index_s.as_str()),
|
||||||
];
|
];
|
||||||
|
if cfg!(windows) {
|
||||||
|
envs.push(("USERPROFILE", home_s.as_str()));
|
||||||
|
}
|
||||||
let out = run_dcr_env(&["build"], &app, &envs);
|
let out = run_dcr_env(&["build"], &app, &envs);
|
||||||
if !out.status.success() {
|
if !out.status.success() {
|
||||||
eprintln!("stdout: {}", String::from_utf8_lossy(&out.stdout));
|
eprintln!("stdout: {}", String::from_utf8_lossy(&out.stdout));
|
||||||
|
|||||||
Reference in New Issue
Block a user