mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 17:09:35 +00:00
Compare commits
4 Commits
v0.6.7
...
cf634d8a8b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf634d8a8b | ||
| b66c846956 | |||
| 2a9c918711 | |||
| 2af3baf4bb |
271
.github/workflows/release.yml
vendored
271
.github/workflows/release.yml
vendored
@@ -7,32 +7,65 @@ on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: "Tag to build and upload assets for (e.g. v0.6.5)"
|
||||
description: "Tag to build (e.g. v0.6.7)"
|
||||
required: true
|
||||
run_linux:
|
||||
description: "Build Linux"
|
||||
type: boolean
|
||||
default: true
|
||||
run_macos:
|
||||
description: "Build macOS"
|
||||
type: boolean
|
||||
default: true
|
||||
run_windows:
|
||||
description: "Build Windows"
|
||||
type: boolean
|
||||
default: true
|
||||
run_publish:
|
||||
description: "Publish to crates.io"
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
# ── Resolve Tag ────────────────────────────────────────────────────────────
|
||||
setup:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
tag: ${{ steps.tag.outputs.value }}
|
||||
version: ${{ steps.tag.outputs.version }}
|
||||
prerelease: ${{ steps.tag.outputs.prerelease }}
|
||||
steps:
|
||||
- name: Resolve tag
|
||||
id: tag
|
||||
run: |
|
||||
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
|
||||
TAG="${{ github.event.inputs.tag }}"
|
||||
else
|
||||
TAG="${GITHUB_REF_NAME}"
|
||||
fi
|
||||
VERSION="${TAG#v}"
|
||||
[[ "$TAG" == *"-"* ]] && PRERELEASE="true" || PRERELEASE="false"
|
||||
echo "value=${TAG}" >> "$GITHUB_OUTPUT"
|
||||
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
|
||||
echo "prerelease=${PRERELEASE}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
# ── Release Notes ──────────────────────────────────────────────────────────
|
||||
notes:
|
||||
needs: setup
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
# При ручном запуске чекаутим нужный тег
|
||||
ref: ${{ github.event.inputs.tag || github.ref }}
|
||||
ref: ${{ needs.setup.outputs.tag }}
|
||||
|
||||
- name: Prepare Release Notes
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# При ручном запуске берём версию из инпута, иначе из тега
|
||||
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
|
||||
tag="${{ github.event.inputs.tag }}"
|
||||
tag="${tag#v}"
|
||||
else
|
||||
tag="${GITHUB_REF_NAME#v}"
|
||||
fi
|
||||
tag="${{ needs.setup.outputs.version }}"
|
||||
notes_file=".github/release-notes.md"
|
||||
if grep -q "^## \\[${tag}\\]" CHANGELOG.md; then
|
||||
awk -v ver="$tag" '
|
||||
@@ -51,60 +84,23 @@ jobs:
|
||||
name: release-notes
|
||||
path: .github/release-notes.md
|
||||
|
||||
build:
|
||||
# ── Linux ──────────────────────────────────────────────────────────────────
|
||||
build-linux:
|
||||
if: ${{ github.event_name == 'push' || github.event.inputs.run_linux == 'true' }}
|
||||
needs: [setup, notes]
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
# ── Linux GNU ──────────────────────────────────────────────────────
|
||||
- os: ubuntu-latest
|
||||
target: x86_64-unknown-linux-gnu
|
||||
|
||||
- os: ubuntu-latest
|
||||
target: aarch64-unknown-linux-gnu
|
||||
apt: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
|
||||
env_cc: CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc
|
||||
env_linker: CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
|
||||
|
||||
# ── Linux Musl ─────────────────────────────────────────────────────
|
||||
- os: ubuntu-latest
|
||||
target: x86_64-unknown-linux-musl
|
||||
apt: musl-tools
|
||||
env_cc: CC_x86_64_unknown_linux_musl=musl-gcc
|
||||
env_linker: CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc
|
||||
|
||||
- os: ubuntu-latest
|
||||
target: aarch64-unknown-linux-musl
|
||||
musl_cross: aarch64-linux-musl-cross
|
||||
env_cc: CC_aarch64_unknown_linux_musl=aarch64-linux-musl-gcc
|
||||
env_linker: CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-musl-gcc
|
||||
|
||||
# ── macOS ──────────────────────────────────────────────────────────
|
||||
- os: macos-15-intel
|
||||
target: x86_64-apple-darwin
|
||||
|
||||
- os: macos-latest
|
||||
target: aarch64-apple-darwin
|
||||
|
||||
# ── Windows MSVC ───────────────────────────────────────────────────
|
||||
- os: windows-latest
|
||||
target: x86_64-pc-windows-msvc
|
||||
|
||||
- os: windows-latest
|
||||
target: aarch64-pc-windows-msvc
|
||||
|
||||
# ── Windows GNU ────────────────────────────────────────────────────
|
||||
- os: windows-latest
|
||||
target: x86_64-pc-windows-gnu
|
||||
|
||||
# gnullvm исключён: LLVM MinGW не предустановлен на GitHub Actions
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
needs: notes
|
||||
- target: x86_64-unknown-linux-gnu
|
||||
- target: aarch64-unknown-linux-gnu
|
||||
- target: x86_64-unknown-linux-musl
|
||||
- target: aarch64-unknown-linux-musl
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.inputs.tag || github.ref }}
|
||||
ref: ${{ needs.setup.outputs.tag }}
|
||||
|
||||
- name: Download Release Notes
|
||||
uses: actions/download-artifact@v4
|
||||
@@ -112,70 +108,143 @@ jobs:
|
||||
name: release-notes
|
||||
path: .github
|
||||
|
||||
- name: Install cargo-zigbuild (Linux cross-compilation)
|
||||
if: runner.os == 'Linux'
|
||||
- name: Install cargo-zigbuild
|
||||
run: |
|
||||
pip install cargo-zigbuild
|
||||
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
||||
|
||||
- name: Setup LLVM + MinGW (gnullvm)
|
||||
if: contains(matrix.target, 'gnullvm')
|
||||
shell: pwsh
|
||||
run: |
|
||||
choco install llvm mingw -y --no-progress
|
||||
echo "C:\Program Files\LLVM\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
||||
|
||||
- name: Setup Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
targets: ${{ matrix.target }}
|
||||
|
||||
- name: Build
|
||||
shell: bash
|
||||
run: |
|
||||
if [ "${{ runner.os }}" = "Linux" ] && [ "${{ matrix.target }}" != "x86_64-unknown-linux-gnu" ]; then
|
||||
if [ "${{ matrix.target }}" != "x86_64-unknown-linux-gnu" ]; then
|
||||
cargo zigbuild --release --target ${{ matrix.target }}
|
||||
else
|
||||
cargo build --release --target ${{ matrix.target }}
|
||||
fi
|
||||
|
||||
- name: Derive version string
|
||||
shell: bash
|
||||
- name: Prepare Artifact
|
||||
run: |
|
||||
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
|
||||
RAW_TAG="${{ github.event.inputs.tag }}"
|
||||
else
|
||||
RAW_TAG="${GITHUB_REF_NAME}"
|
||||
fi
|
||||
echo "RELEASE_TAG=${RAW_TAG}" >> "$GITHUB_ENV"
|
||||
echo "RELEASE_VERSION=${RAW_TAG#v}" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Derive asset name (Unix)
|
||||
if: runner.os != 'Windows'
|
||||
shell: bash
|
||||
run: |
|
||||
echo "ASSET_NAME=dcr-${{ matrix.target }}-${RELEASE_VERSION}" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Derive asset name (Windows)
|
||||
if: runner.os == 'Windows'
|
||||
shell: pwsh
|
||||
run: |
|
||||
"ASSET_NAME=dcr-${{ matrix.target }}-$($env:RELEASE_VERSION).exe" >> $env:GITHUB_ENV
|
||||
|
||||
- name: Prepare Artifact (Unix)
|
||||
if: runner.os != 'Windows'
|
||||
shell: bash
|
||||
run: cp target/${{ matrix.target }}/release/dcr "$ASSET_NAME"
|
||||
|
||||
- name: Prepare Artifact (Windows)
|
||||
if: runner.os == 'Windows'
|
||||
shell: pwsh
|
||||
run: Copy-Item "target/${{ matrix.target }}/release/dcr.exe" "$env:ASSET_NAME"
|
||||
ASSET="dcr-${{ matrix.target }}-${{ needs.setup.outputs.version }}"
|
||||
cp target/${{ matrix.target }}/release/dcr "$ASSET"
|
||||
echo "ASSET_NAME=${ASSET}" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Upload Release Asset
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: ${{ env.RELEASE_TAG }}
|
||||
tag_name: ${{ needs.setup.outputs.tag }}
|
||||
files: ${{ env.ASSET_NAME }}
|
||||
body_path: .github/release-notes.md
|
||||
prerelease: ${{ contains(env.RELEASE_TAG, '-') }}
|
||||
prerelease: ${{ needs.setup.outputs.prerelease == 'true' }}
|
||||
|
||||
# ── macOS ──────────────────────────────────────────────────────────────────
|
||||
build-macos:
|
||||
if: ${{ github.event_name == 'push' || github.event.inputs.run_macos == 'true' }}
|
||||
needs: [setup, notes]
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: macos-15-intel
|
||||
target: x86_64-apple-darwin
|
||||
- os: macos-latest
|
||||
target: aarch64-apple-darwin
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ needs.setup.outputs.tag }}
|
||||
|
||||
- name: Download Release Notes
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: release-notes
|
||||
path: .github
|
||||
|
||||
- name: Setup Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
targets: ${{ matrix.target }}
|
||||
|
||||
- name: Build
|
||||
run: cargo build --release --target ${{ matrix.target }}
|
||||
|
||||
- name: Prepare Artifact
|
||||
run: |
|
||||
ASSET="dcr-${{ matrix.target }}-${{ needs.setup.outputs.version }}"
|
||||
cp target/${{ matrix.target }}/release/dcr "$ASSET"
|
||||
echo "ASSET_NAME=${ASSET}" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Upload Release Asset
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: ${{ needs.setup.outputs.tag }}
|
||||
files: ${{ env.ASSET_NAME }}
|
||||
body_path: .github/release-notes.md
|
||||
prerelease: ${{ needs.setup.outputs.prerelease == 'true' }}
|
||||
|
||||
# ── Windows ────────────────────────────────────────────────────────────────
|
||||
build-windows:
|
||||
if: ${{ github.event_name == 'push' || github.event.inputs.run_windows == 'true' }}
|
||||
needs: [setup, notes]
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- target: x86_64-pc-windows-msvc
|
||||
- target: aarch64-pc-windows-msvc
|
||||
- target: x86_64-pc-windows-gnu
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ needs.setup.outputs.tag }}
|
||||
|
||||
- name: Download Release Notes
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: release-notes
|
||||
path: .github
|
||||
|
||||
- name: Setup Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
targets: ${{ matrix.target }}
|
||||
|
||||
- name: Build
|
||||
run: cargo build --release --target ${{ matrix.target }}
|
||||
|
||||
- name: Prepare Artifact
|
||||
shell: pwsh
|
||||
run: |
|
||||
$asset = "dcr-${{ matrix.target }}-${{ needs.setup.outputs.version }}.exe"
|
||||
Copy-Item "target/${{ matrix.target }}/release/dcr.exe" "$asset"
|
||||
"ASSET_NAME=$asset" >> $env:GITHUB_ENV
|
||||
|
||||
- name: Upload Release Asset
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: ${{ needs.setup.outputs.tag }}
|
||||
files: ${{ env.ASSET_NAME }}
|
||||
body_path: .github/release-notes.md
|
||||
prerelease: ${{ needs.setup.outputs.prerelease == 'true' }}
|
||||
|
||||
# ── crates.io ──────────────────────────────────────────────────────────────
|
||||
publish-crates:
|
||||
if: |
|
||||
(github.event_name == 'push' && needs.setup.outputs.prerelease == 'false') ||
|
||||
(github.event_name == 'workflow_dispatch' && github.event.inputs.run_publish == 'true')
|
||||
needs: [setup, build-linux, build-macos, build-windows]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ needs.setup.outputs.tag }}
|
||||
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Publish to crates.io
|
||||
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -777,15 +777,6 @@ version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e"
|
||||
|
||||
[[package]]
|
||||
name = "openssl-src"
|
||||
version = "300.6.0+3.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8e8cbfd3a4a8c8f089147fd7aaa33cf8c7450c4d09f8f80698a0cf093abeff4"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-sys"
|
||||
version = "0.9.115"
|
||||
@@ -794,7 +785,6 @@ checksum = "158fe5b292746440aa6e7a7e690e55aeb72d41505e2804c23c6973ad0e9c9781"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"openssl-src",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
@@ -3,6 +3,9 @@ name = "dcr"
|
||||
version = "0.6.7"
|
||||
edition = "2024"
|
||||
build = "build.rs"
|
||||
description = "DCR is a utility for managing C/C++ projects in a Cargo-like style."
|
||||
license = "MIT"
|
||||
repository = "https://github.com/dexoron/dcr"
|
||||
|
||||
[dependencies]
|
||||
glob = "0.3"
|
||||
@@ -16,4 +19,4 @@ serde_json = "1"
|
||||
ctrlc = "3"
|
||||
|
||||
[target.'cfg(not(windows))'.dependencies]
|
||||
openssl = { version = "0.10", features = ["vendored"] }
|
||||
openssl = { version = "0.10" }
|
||||
|
||||
2
rust-toolchain.toml
Normal file
2
rust-toolchain.toml
Normal file
@@ -0,0 +1,2 @@
|
||||
[toolchain]
|
||||
channel = "nightly"
|
||||
56
src/cli/fmt.rs
Normal file
56
src/cli/fmt.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use crate::utils::log::error;
|
||||
use crate::utils::text::{colored, BOLD_GREEN};
|
||||
use glob::glob;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn fmt(_args: &[String]) -> i32 {
|
||||
let patterns = [
|
||||
"src/**/*.c",
|
||||
"src/**/*.cpp",
|
||||
"src/**/*.h",
|
||||
"src/**/*.hpp",
|
||||
"tests/**/*.c",
|
||||
"tests/**/*.cpp",
|
||||
"tests/**/*.h",
|
||||
"tests/**/*.hpp",
|
||||
];
|
||||
|
||||
let mut files = Vec::new();
|
||||
for pattern in patterns {
|
||||
if let Ok(paths) = glob(pattern) {
|
||||
for path in paths.flatten() {
|
||||
if let Some(s) = path.to_str() {
|
||||
files.push(s.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if files.is_empty() {
|
||||
println!(" {} No files to format", colored("Format", BOLD_GREEN));
|
||||
return 0;
|
||||
}
|
||||
|
||||
println!(
|
||||
" {} {} files",
|
||||
colored("Formatting", BOLD_GREEN),
|
||||
files.len()
|
||||
);
|
||||
|
||||
let status = Command::new("clang-format").arg("-i").args(&files).status();
|
||||
|
||||
match status {
|
||||
Ok(s) if s.success() => {
|
||||
println!(" {} successful", colored("Format", BOLD_GREEN));
|
||||
0
|
||||
}
|
||||
Ok(s) => {
|
||||
error(&format!("clang-format failed with status: {}", s));
|
||||
1
|
||||
}
|
||||
Err(e) => {
|
||||
error(&format!("Failed to execute clang-format: {}", e));
|
||||
1
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ pub fn help() -> i32 {
|
||||
println!(" run [--profile] Build and run the project (default: --debug)");
|
||||
println!(" tree Display the dependency tree");
|
||||
println!(" test Run project tests (alias: tests)");
|
||||
println!(" fmt Format all C/C++ source files using clang-format");
|
||||
println!(" clean Remove the target directory");
|
||||
println!(" gen <subcommand> Generate IDE integration files");
|
||||
printc("FLAGS:", BOLD_GREEN);
|
||||
|
||||
@@ -3,6 +3,7 @@ pub mod build;
|
||||
pub mod clean;
|
||||
pub mod flag_update;
|
||||
pub mod flags;
|
||||
pub mod fmt;
|
||||
pub mod r#gen;
|
||||
pub mod help;
|
||||
pub mod init;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#![feature(let_chains)]
|
||||
use crate::utils::log::error;
|
||||
mod cli;
|
||||
mod config;
|
||||
@@ -24,6 +25,7 @@ fn main() {
|
||||
"run" => cli::run::run(rest),
|
||||
"tree" => cli::tree::tree(rest),
|
||||
"test" | "tests" => cli::test::test(rest),
|
||||
"fmt" => cli::fmt::fmt(rest),
|
||||
"clean" => cli::clean::clean(rest),
|
||||
"gen" => cli::r#gen::r#gen(rest),
|
||||
"--version" => {
|
||||
|
||||
Reference in New Issue
Block a user