mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 09:08:30 +00:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c22d2dbddc | |||
| 83061cc460 | |||
| 467e64aa4f | |||
| 7817834790 | |||
| 9fe2604154 | |||
| cb8a3b2001 | |||
| e0fd729635 | |||
| e70edf8ae4 | |||
| 210e82f026 | |||
| ff12ca2758 | |||
| 468491b5b1 | |||
| 0f48151b68 | |||
| e87e0cbc47 | |||
| fff8baa3c9 | |||
| ad0d4cdcb7 | |||
| 45806f193e | |||
| 9ae4bb5ab1 | |||
| 5a2025fb80 | |||
| 06e7af6ab6 | |||
| 8495441b1a | |||
| b56f502a30 | |||
| 115692253e | |||
| 7a0ebb43a5 | |||
| 4c628ff336 | |||
| 95324ce199 | |||
| d1e23a3179 |
136
.github/workflows/aur.yml
vendored
Normal file
136
.github/workflows/aur.yml
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
name: AUR Publish
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: "Tag version without v prefix (e.g. 0.2.2)"
|
||||
required: true
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
publish-aur:
|
||||
runs-on: ubuntu-latest
|
||||
environment: aur
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Derive version and checksum
|
||||
id: meta
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
|
||||
PKGVER="${{ inputs.version }}"
|
||||
else
|
||||
PKGVER="${GITHUB_REF_NAME#v}"
|
||||
fi
|
||||
SRC_URL="https://github.com/dexoron/dcr/archive/refs/tags/v${PKGVER}.tar.gz"
|
||||
SHA256="$(curl -fsSL "$SRC_URL" | sha256sum | awk '{print $1}')"
|
||||
|
||||
echo "pkgver=$PKGVER" >> "$GITHUB_OUTPUT"
|
||||
echo "source_url=$SRC_URL" >> "$GITHUB_OUTPUT"
|
||||
echo "sha256=$SHA256" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Render AUR metadata
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
PKGVER='${{ steps.meta.outputs.pkgver }}'
|
||||
SRC_URL='${{ steps.meta.outputs.source_url }}'
|
||||
SHA256='${{ steps.meta.outputs.sha256 }}'
|
||||
|
||||
cat > packaging/aur/dcr/PKGBUILD <<PKG
|
||||
pkgname=dcr
|
||||
pkgver=${PKGVER}
|
||||
pkgrel=1
|
||||
pkgdesc="Cargo-like utility to manage C/C++ projects"
|
||||
arch=('x86_64' 'aarch64')
|
||||
url="https://github.com/dexoron/dcr"
|
||||
license=('MIT')
|
||||
depends=('gcc-libs')
|
||||
makedepends=('cargo')
|
||||
options=('!lto')
|
||||
optdepends=(
|
||||
'gcc: build C/C++ projects with GCC'
|
||||
'clang: build C/C++ projects with Clang'
|
||||
)
|
||||
source=("\$pkgname-\$pkgver.tar.gz::\$url/archive/refs/tags/v\$pkgver.tar.gz")
|
||||
sha256sums=('${SHA256}')
|
||||
|
||||
build() {
|
||||
cd "\$srcdir/\$pkgname-\$pkgver"
|
||||
export CARGO_PROFILE_RELEASE_LTO=false
|
||||
export RUSTFLAGS="\${RUSTFLAGS:-}"
|
||||
export RUSTFLAGS="\${RUSTFLAGS/-C link-arg=-fuse-ld=lld/}"
|
||||
cargo build --release --locked
|
||||
}
|
||||
|
||||
package() {
|
||||
cd "\$srcdir/\$pkgname-\$pkgver"
|
||||
install -Dm755 "target/release/dcr" "\$pkgdir/usr/bin/dcr"
|
||||
install -Dm644 LICENSE "\$pkgdir/usr/share/licenses/\$pkgname/LICENSE"
|
||||
}
|
||||
PKG
|
||||
|
||||
cat > packaging/aur/dcr/.SRCINFO <<SRC
|
||||
pkgbase = dcr
|
||||
pkgdesc = Cargo-like utility to manage C/C++ projects
|
||||
pkgver = ${PKGVER}
|
||||
pkgrel = 1
|
||||
url = https://github.com/dexoron/dcr
|
||||
arch = x86_64
|
||||
arch = aarch64
|
||||
license = MIT
|
||||
makedepends = cargo
|
||||
depends = gcc-libs
|
||||
optdepends = gcc: build C/C++ projects with GCC
|
||||
optdepends = clang: build C/C++ projects with Clang
|
||||
options = !lto
|
||||
source = dcr-${PKGVER}.tar.gz::${SRC_URL}
|
||||
sha256sums = ${SHA256}
|
||||
|
||||
pkgname = dcr
|
||||
SRC
|
||||
|
||||
- name: Push to AUR
|
||||
env:
|
||||
AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
|
||||
AUR_PACKAGE: dcr
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
if [[ -z "${AUR_SSH_PRIVATE_KEY:-}" ]]; then
|
||||
echo "AUR_SSH_PRIVATE_KEY secret is missing"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
install -d -m 700 ~/.ssh
|
||||
printf '%s\n' "$AUR_SSH_PRIVATE_KEY" > ~/.ssh/aur
|
||||
chmod 600 ~/.ssh/aur
|
||||
ssh-keyscan aur.archlinux.org >> ~/.ssh/known_hosts
|
||||
|
||||
export GIT_SSH_COMMAND='ssh -i ~/.ssh/aur -o IdentitiesOnly=yes'
|
||||
git clone "ssh://aur@aur.archlinux.org/${AUR_PACKAGE}.git" aur-repo
|
||||
cp packaging/aur/dcr/PKGBUILD aur-repo/PKGBUILD
|
||||
cp packaging/aur/dcr/.SRCINFO aur-repo/.SRCINFO
|
||||
|
||||
cd aur-repo
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
|
||||
if git diff --quiet; then
|
||||
echo "No AUR changes"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
git add PKGBUILD .SRCINFO
|
||||
git commit -m "dcr ${{ steps.meta.outputs.pkgver }}"
|
||||
git push
|
||||
40
.github/workflows/release.yml
vendored
40
.github/workflows/release.yml
vendored
@@ -9,6 +9,34 @@ permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
notes:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Prepare Release Notes
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
tag="${GITHUB_REF_NAME#v}"
|
||||
notes_file=".github/release-notes.md"
|
||||
if grep -q "^## \\[${tag}\\]" CHANGELOG.md; then
|
||||
awk -v ver="$tag" '
|
||||
$0 ~ "^## \\[" ver "\\]" {found=1; next}
|
||||
found && $0 ~ "^## \\[" {exit}
|
||||
found {print}
|
||||
' CHANGELOG.md | sed -e '${/^$/d;}' > "$notes_file"
|
||||
else
|
||||
echo "No CHANGELOG section for $tag." > "$notes_file"
|
||||
git log -1 --pretty=format:"%s%n%n%b" >> "$notes_file"
|
||||
fi
|
||||
|
||||
- name: Upload Notes Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-notes
|
||||
path: .github/release-notes.md
|
||||
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
@@ -17,10 +45,10 @@ jobs:
|
||||
- os: ubuntu-latest
|
||||
target: x86_64-unknown-linux-gnu
|
||||
asset_name: dcr-x86_64-unknown-linux-gnu
|
||||
- os: macos-13
|
||||
- os: macos-15-intel
|
||||
target: x86_64-apple-darwin
|
||||
asset_name: dcr-x86_64-apple-darwin
|
||||
- os: macos-14
|
||||
- os: macos-15
|
||||
target: aarch64-apple-darwin
|
||||
asset_name: dcr-aarch64-apple-darwin
|
||||
- os: windows-latest
|
||||
@@ -28,9 +56,14 @@ jobs:
|
||||
asset_name: dcr-x86_64-pc-windows-msvc.exe
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
needs: notes
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Download Release Notes
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: release-notes
|
||||
path: .github
|
||||
|
||||
- name: Setup Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
@@ -56,3 +89,4 @@ jobs:
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: ${{ matrix.asset_name }}
|
||||
body_path: .github/release-notes.md
|
||||
|
||||
92
CHANGELOG.md
92
CHANGELOG.md
@@ -1,40 +1,78 @@
|
||||
# Changelog
|
||||
|
||||
## [0.2.5] - 2026-02-26
|
||||
Added:
|
||||
- Incremental builds (object caching by mtime)
|
||||
- `build.kind` with `staticlib` support
|
||||
- Custom output directory via `build.target`
|
||||
|
||||
## [0.2.4] - 2026-02-22
|
||||
Added:
|
||||
- Custom build flags: `build.cflags` and `build.ldflags`
|
||||
- Recursive source discovery inside `src/`
|
||||
- Path dependencies with auto include/lib resolution and `dcr.lock` generation (experimental)
|
||||
- Add docs/index.md and docs/dcr-toml.md
|
||||
|
||||
## [0.2.3] - 2026-02-21
|
||||
Added:
|
||||
- Modular builders for `gcc`, `clang`, `msvc`
|
||||
- Platform-specific binary path generation (Linux/macOS/Windows)
|
||||
|
||||
Changed:
|
||||
- Build configuration moved to `[build]` (`language`, `standard`, `compiler`)
|
||||
- `dcr.toml` formatting now includes the `[build]` section
|
||||
- Build uses built-in `debug/release` flags per compiler
|
||||
- Build compiles all `*.c/*.cpp` files in `src/` into a single binary (no incremental build)
|
||||
- Updated `dcr.toml` examples in documentation
|
||||
|
||||
## [0.2.2] - 2026-02-20
|
||||
Changed:
|
||||
- Reworked `dcr.toml` handling: added read, validation, and edit through `core::config`
|
||||
- `new` and `init` use the new config creation logic
|
||||
- `build` and `run` now require `dcr.toml` and read `compiler` and `name` from it
|
||||
|
||||
## [0.2.1] - 2026-02-18
|
||||
Changed:
|
||||
- Translated user-facing CLI messages to English
|
||||
- Unified error and warning output via `utils::log::{error, warn}`
|
||||
- Updated `--help` output: translated headers and examples to English, used `printc`, and applied `BOLD_*` styles
|
||||
- Translated installer script messages in `install.sh` and `install.ps1` to English
|
||||
|
||||
## [0.2.0] - 2026-02-17
|
||||
Изменено:
|
||||
- Проект переведен с Python на Rust
|
||||
- CLI и команды (`new`, `init`, `build`, `run`, `clean`, `--help`, `--version`, `--update`) перенесены на Rust
|
||||
- Обновлен флаг `--update` - добавлена поддержка GNU\Linux, Windows, MacOS
|
||||
- Обновлены `README.md`, `CONTRIBUTING.md`, `install.sh` под Rust-реализацию
|
||||
- Добавлен `install.ps1` для Windows
|
||||
- Обновлен `install.sh` для GNU/Linux и MacOS
|
||||
Changed:
|
||||
- Project migrated from Python to Rust
|
||||
- CLI and commands (`new`, `init`, `build`, `run`, `clean`, `--help`, `--version`, `--update`) ported to Rust
|
||||
- Updated `--update` flag: added support for GNU/Linux, Windows, macOS
|
||||
- Updated `README.md`, `CONTRIBUTING.md`, and `install.sh` for the Rust implementation
|
||||
- Added `install.ps1` for Windows
|
||||
- Updated `install.sh` for GNU/Linux and macOS
|
||||
|
||||
Добавлено:
|
||||
- Добавлен `install.ps1` для Windows
|
||||
- Поддержка GNU\Linux, Windows, MacOS(x86_64/arm)
|
||||
Added:
|
||||
- Added `install.ps1` for Windows
|
||||
- Support for GNU/Linux, Windows, macOS (x86_64/arm)
|
||||
|
||||
ВАЖНО:
|
||||
- Код перенесен с помощью нейронных сетей, в будущих версиях будет баг-фикс и изменение логики
|
||||
Important:
|
||||
- Code was ported with neural networks; future versions will include bug fixes and logic changes
|
||||
|
||||
## [0.1.2] - 2026-02-12
|
||||
Добавлено:
|
||||
- Команда обновления
|
||||
- Скрипт установки `install.sh` и инструкции по установке в README
|
||||
- Флаг `--version` для вывода версии
|
||||
Added:
|
||||
- Update command
|
||||
- `install.sh` install script and README instructions
|
||||
- `--version` flag
|
||||
|
||||
Изменено:
|
||||
- Улучшен консольный вывод команд, добавлены цвета и обновлена справка `--help`
|
||||
- Обновлен запуск проекта и обработка сборки в `run.py`/`build.py`
|
||||
Changed:
|
||||
- Improved CLI output, added colors, and updated `--help`
|
||||
- Updated project run/build handling in `run.py`/`build.py`
|
||||
|
||||
## [0.1.1] - 2026-02-11
|
||||
Изменено:
|
||||
- Обновлена справка `--help`
|
||||
- `main.py` теперь корректно запускается при прямом выполнении
|
||||
Changed:
|
||||
- Updated `--help`
|
||||
- `main.py` now runs correctly when executed directly
|
||||
|
||||
## [0.1.0] - 2026-02-11
|
||||
Первый публичный релиз.
|
||||
First public release.
|
||||
|
||||
Добавлено:
|
||||
- Базовые команды `new`, `init`, `build`, `run`, `clean`
|
||||
- Профили сборки `debug` и `release`
|
||||
- Шаблоны `dcr.toml` и `src/main.c`
|
||||
Added:
|
||||
- Base commands `new`, `init`, `build`, `run`, `clean`
|
||||
- Build profiles `debug` and `release`
|
||||
- `dcr.toml` and `src/main.c` templates
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# Вклад в проект
|
||||
# Contributing
|
||||
|
||||
Спасибо за интерес к проекту.
|
||||
Thanks for your interest in the project.
|
||||
|
||||
## Требования
|
||||
## Requirements
|
||||
|
||||
- Использовать Rust stable.
|
||||
- Перед PR код должен проходить форматирование, линт и сборку.
|
||||
- Use Rust stable.
|
||||
- Before opening a PR, the code must pass formatting, linting, and build.
|
||||
|
||||
## Быстрый старт
|
||||
## Quick Start
|
||||
|
||||
```bash
|
||||
git clone https://github.com/dexoron/dcr.git
|
||||
@@ -15,16 +15,16 @@ cd dcr
|
||||
cargo check
|
||||
```
|
||||
|
||||
## Стиль кода
|
||||
## Code Style
|
||||
|
||||
- Форматируйте код через `cargo fmt`.
|
||||
- Проверяйте предупреждения через `cargo clippy`.
|
||||
- Держите функции небольшими и сфокусированными.
|
||||
- Предпочитайте понятные имена вместо "хитрых".
|
||||
- Format code with `cargo fmt`.
|
||||
- Check warnings with `cargo clippy`.
|
||||
- Keep functions small and focused.
|
||||
- Prefer clear names over clever ones.
|
||||
|
||||
## Проверки
|
||||
## Checks
|
||||
|
||||
Перед PR запускайте:
|
||||
Before PR, run:
|
||||
|
||||
```bash
|
||||
cargo fmt --all
|
||||
@@ -32,26 +32,26 @@ cargo clippy --all-targets --all-features -- -D warnings
|
||||
cargo check
|
||||
```
|
||||
|
||||
## CI/CD и релизы
|
||||
## CI/CD and Releases
|
||||
|
||||
- CI: `.github/workflows/ci.yml`
|
||||
- Release: `.github/workflows/release.yml`
|
||||
- Релиз запускается по тегу `v*` и публикует бинарники для:
|
||||
- Releases are triggered by tags `v*` and publish binaries for:
|
||||
- `x86_64-unknown-linux-gnu`
|
||||
- `x86_64-apple-darwin`
|
||||
- `aarch64-apple-darwin`
|
||||
- `x86_64-pc-windows-msvc`
|
||||
|
||||
## Коммиты и PR
|
||||
## Commits and PRs
|
||||
|
||||
- Делайте коммиты понятными.
|
||||
- В PR указывайте краткое описание и мотивацию изменений.
|
||||
- Обновляйте документацию при изменении поведения.
|
||||
- Write clear commit messages.
|
||||
- In PRs, include a short description and rationale.
|
||||
- Update documentation when behavior changes.
|
||||
|
||||
## Вопросы
|
||||
## Questions
|
||||
|
||||
Если что-то непонятно, открой issue или задайте вопрос в PR.
|
||||
If anything is unclear, open an issue or ask in the PR.
|
||||
|
||||
Также можно задать вопрос напрямую:
|
||||
You can also reach out directly:
|
||||
- TG: @dexoron
|
||||
- DS: dexoron
|
||||
|
||||
129
Cargo.lock
generated
129
Cargo.lock
generated
@@ -26,6 +26,15 @@ version = "2.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.19.1"
|
||||
@@ -60,13 +69,44 @@ version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dcr"
|
||||
version = "0.2.0"
|
||||
version = "0.2.4"
|
||||
dependencies = [
|
||||
"reqwest",
|
||||
"self-replace",
|
||||
"serde",
|
||||
"sha2",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -172,6 +212,16 @@ dependencies = [
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.17"
|
||||
@@ -878,6 +928,15 @@ dependencies = [
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.7.1"
|
||||
@@ -890,6 +949,17 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
@@ -1043,6 +1113,45 @@ dependencies = [
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "1.0.3+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7614eaf19ad818347db24addfa201729cf2a9b6fdfd9eb0ab870fcacc606c0c"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde_core",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"toml_parser",
|
||||
"toml_writer",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "1.0.0+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32c2555c699578a4f59f0cc68e5116c8d7cabbd45e1409b989d4be085b53f13e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_parser"
|
||||
version = "1.0.9+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "702d4415e08923e7e1ef96cd5727c0dfed80b4d2fa25db9647fe5eb6f7c5a4c4"
|
||||
dependencies = [
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_writer"
|
||||
version = "1.0.6+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607"
|
||||
|
||||
[[package]]
|
||||
name = "tower"
|
||||
version = "0.5.3"
|
||||
@@ -1113,6 +1222,12 @@ version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
@@ -1149,6 +1264,12 @@ version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "want"
|
||||
version = "0.3.1"
|
||||
@@ -1466,6 +1587,12 @@ version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.7.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829"
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.51.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "dcr"
|
||||
version = "0.2.0"
|
||||
version = "0.2.4"
|
||||
edition = "2024"
|
||||
build = "build.rs"
|
||||
|
||||
@@ -8,3 +8,5 @@ build = "build.rs"
|
||||
reqwest = { version = "0.12", default-features = false, features = ["blocking", "json", "rustls-tls"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
self-replace = "1"
|
||||
sha2 = "0.10"
|
||||
toml = "1.0.3"
|
||||
|
||||
102
FAQ.md
Normal file
102
FAQ.md
Normal file
@@ -0,0 +1,102 @@
|
||||
# FAQ
|
||||
|
||||
## What is this project about?
|
||||
`dcr` is a tool for managing C/C++ projects and their dependencies.
|
||||
It is inspired by Cargo, but it is not a direct equivalent of Makefile, CMake, or other classic build systems.
|
||||
|
||||
The goal is to provide a simpler and easier-to-configure development workflow.
|
||||
|
||||
## How is the project developed?
|
||||
The project is written in Rust and is primarily developed by one maintainer, Dexoron.
|
||||
|
||||
AI tools are used during development, but they do not write the project end-to-end. Their role is limited to supporting specific tasks (for example, suggestions, wording checks, and translations).
|
||||
|
||||
## Which tools are used for development?
|
||||
Main development stack:
|
||||
- `RustRover` 2025 - development IDE.
|
||||
- `Codex` (`GPT-5.3-Codex (medium)`) - primary AI tool, integrated via JetBrains AI Chat.
|
||||
- `Rust` - main project language.
|
||||
- `Cargo` - tool for building, testing, and dependency management in Rust projects.
|
||||
|
||||
## Is the project open source?
|
||||
Yes, the project is open source.
|
||||
You can propose ideas, report issues, and contribute code changes.
|
||||
|
||||
The project is distributed under the MIT license (see `LICENSE`).
|
||||
|
||||
## How can I contribute?
|
||||
Thank you for contributing.
|
||||
You can:
|
||||
- help with code;
|
||||
- help with translations;
|
||||
- help with documentation;
|
||||
- suggest an idea or report a bug.
|
||||
|
||||
### If you want to submit changes (code, translation, documentation)
|
||||
1. Fork the required repository: `dexoron/dcr` (main project) or `dexoron/dcr-site` (project website).
|
||||
2. Make your changes following the rules in `CONTRIBUTING.md`.
|
||||
3. Push changes to your fork.
|
||||
4. Open a Pull Request.
|
||||
5. Wait for review.
|
||||
|
||||
### If you want to report a problem or suggest an idea
|
||||
1. Open the relevant repository: `dexoron/dcr` or `dexoron/dcr-site`.
|
||||
2. Go to the `Issues` tab.
|
||||
3. Create an Issue and specify its type (bug, suggestion, question/help).
|
||||
4. Describe the problem or idea clearly and concisely.
|
||||
5. Wait for feedback.
|
||||
|
||||
## How do I install `dcr`?
|
||||
Available installation methods may vary by project version.
|
||||
Recommended path:
|
||||
- check instructions in `README.md`;
|
||||
- if there is no prebuilt package for your platform, build from source using `cargo build --release`.
|
||||
|
||||
## How can I get started quickly?
|
||||
Minimal workflow:
|
||||
1. Install `dcr`.
|
||||
2. Create a project (or open an existing C/C++ project).
|
||||
3. Initialize `dcr` configuration.
|
||||
4. Add project dependencies.
|
||||
5. Build using `dcr`.
|
||||
|
||||
For detailed commands and examples, see `README.md` and the project documentation.
|
||||
|
||||
## What is the project status?
|
||||
`dcr` is under active development.
|
||||
This means some interfaces and behaviors may change between versions.
|
||||
|
||||
Before upgrading, check the changelog and release notes.
|
||||
|
||||
## Which systems does `dcr` support?
|
||||
`dcr` targets modern C/C++ development environments.
|
||||
Actual compatibility depends on the `dcr` version, operating system, and toolchain.
|
||||
|
||||
Before starting, check documentation for:
|
||||
- supported operating systems;
|
||||
- supported compilers and linkers;
|
||||
- version-specific limitations.
|
||||
|
||||
## How is `dcr` different from Make/CMake?
|
||||
`dcr` does not aim to be a direct replacement for Make/CMake.
|
||||
Its main focus is simplifying project and dependency management with a Cargo-like experience.
|
||||
|
||||
If you need low-level, full control over build steps, classic tools may be a better fit.
|
||||
If you want a simpler and more uniform configuration model, `dcr` may be more convenient.
|
||||
|
||||
## Where can I find documentation and examples?
|
||||
Primary sources:
|
||||
- `README.md` in the repository;
|
||||
- project documentation (see the project website);
|
||||
- `Issues` for known problems and discussions.
|
||||
|
||||
## How do I report a bug properly?
|
||||
To make a bug report easy to reproduce, include:
|
||||
1. `dcr` version.
|
||||
2. OS and compiler/toolchain version.
|
||||
3. Steps to reproduce.
|
||||
4. Expected behavior.
|
||||
5. Actual behavior and error output.
|
||||
6. Minimal project example (if possible).
|
||||
|
||||
Submit bugs and issues through `Issues` in the relevant repository.
|
||||
134
README.md
134
README.md
@@ -1,31 +1,38 @@
|
||||
# DCR (Dexoron Cargo Realization)
|
||||
|
||||
DCR — это утилита для управления проектами на C/C++ в стиле Cargo.
|
||||
DCR is a utility for managing C/C++ projects in a Cargo-like style.
|
||||
|
||||
Текущая реализация написана на Rust.
|
||||
The current implementation is written in Rust.
|
||||
|
||||
## Зачем DCR
|
||||
- Единая структура проекта без ручной настройки
|
||||
- Простые команды для типовых задач
|
||||
- Прозрачная компиляция и предсказуемые профили сборки
|
||||
## Why DCR
|
||||
- Unified project structure without manual setup
|
||||
- Simple commands for common tasks
|
||||
- Transparent compilation and predictable build profiles
|
||||
|
||||
## Возможности
|
||||
- Создание нового проекта или инициализация текущей директории
|
||||
- Сборка проекта в профилях `debug` и `release`
|
||||
- Запуск собранного бинарника
|
||||
- Очистка результатов сборки
|
||||
- Генерация минимального шаблона C-проекта
|
||||
- Обновление бинарника через `dcr --update` (GitHub Releases)
|
||||
## Features
|
||||
- Create a new project or initialize the current directory
|
||||
- Build a project with `debug` and `release` profiles
|
||||
- Run the compiled binary
|
||||
- Clean build artifacts
|
||||
- Generate a minimal C project template
|
||||
- Update the binary via `dcr --update` (GitHub Releases, not for pacman/AUR installs)
|
||||
|
||||
## Поддерживаемые платформы
|
||||
## Supported Platforms
|
||||
- Linux: `x86_64-unknown-linux-gnu`
|
||||
- macOS Intel: `x86_64-apple-darwin`
|
||||
- macOS Apple Silicon: `aarch64-apple-darwin`
|
||||
- Windows: `x86_64-pc-windows-msvc`
|
||||
|
||||
## Установка
|
||||
## Installation
|
||||
|
||||
### Из исходников
|
||||
### Package Manager
|
||||
|
||||
**Arch Linux**
|
||||
```sh
|
||||
yay -S dcr # or paru and other AUR package managers
|
||||
```
|
||||
|
||||
### From Source
|
||||
|
||||
```sh
|
||||
git clone https://github.com/dexoron/dcr.git
|
||||
@@ -35,37 +42,45 @@ mkdir -p ~/.local/bin
|
||||
ln -sf "$PWD/target/release/dcr" ~/.local/bin/dcr
|
||||
```
|
||||
|
||||
### Через install.sh (Linux/macOS)
|
||||
### Via `install.sh` (Linux/macOS)
|
||||
|
||||
```sh
|
||||
curl -fsSL https://raw.githubusercontent.com/dexoron/dcr/master/install.sh | bash
|
||||
curl -fsSL https://dcr.dexoron.su/install.sh | bash
|
||||
```
|
||||
|
||||
### Через install.ps1 (Windows)
|
||||
### Via `install.ps1` (Windows)
|
||||
|
||||
```powershell
|
||||
irm https://raw.githubusercontent.com/dexoron/dcr/master/install.ps1 | iex
|
||||
irm https://dcr.dexoron.su/install.ps1 | iex
|
||||
```
|
||||
|
||||
Оба скрипта при запуске спрашивают:
|
||||
- скачать готовый бинарник из GitHub Release
|
||||
- или собрать проект из `git`
|
||||
When executed, both scripts ask whether to:
|
||||
- download a prebuilt binary from GitHub Releases
|
||||
- or build the project from `git`
|
||||
|
||||
Релизные ассеты:
|
||||
Release assets:
|
||||
- `dcr-x86_64-unknown-linux-gnu`
|
||||
- `dcr-x86_64-apple-darwin`
|
||||
- `dcr-aarch64-apple-darwin`
|
||||
- `dcr-x86_64-pc-windows-msvc.exe`
|
||||
|
||||
## Быстрый старт
|
||||
## Update
|
||||
|
||||
Создать новый проект:
|
||||
- If DCR was installed from GitHub release assets, `install.sh`, `install.ps1`, or built manually:
|
||||
- use `dcr --update`
|
||||
- If DCR is installed via `pacman/AUR`:
|
||||
- update with your package manager: `paru/yay -Syu dcr` or `sudo pacman -Syu dcr`
|
||||
- `dcr --update` detects package-managed installs and asks you to update via package manager
|
||||
|
||||
## Quick Start
|
||||
|
||||
Create a new project:
|
||||
`dcr new hello`
|
||||
|
||||
Или инициализировать текущую директорию (директория должна быть пустой):
|
||||
Or initialize the current directory (the directory must be empty):
|
||||
`dcr init`
|
||||
|
||||
Структура проекта:
|
||||
Project structure:
|
||||
|
||||
```txt
|
||||
hello/
|
||||
@@ -74,55 +89,70 @@ hello/
|
||||
- dcr.toml
|
||||
```
|
||||
|
||||
Сборка и запуск проекта:
|
||||
`dcr run` или `dcr run --release`
|
||||
Build and run the project:
|
||||
`dcr run` or `dcr run --release`
|
||||
|
||||
## Команды
|
||||
## Commands
|
||||
|
||||
### `dcr new <name>`
|
||||
Создает проект в текущей директории с указанным именем.
|
||||
Creates a project with the specified name in the current directory.
|
||||
|
||||
### `dcr init`
|
||||
Создает проект в текущей директории. Имя проекта будет равно имени директории. Директория должна быть пустой.
|
||||
Creates a project in the current directory. The project name is taken from the directory name. The directory must be empty.
|
||||
|
||||
### `dcr build [profile]`
|
||||
Собирает проект. Если профиль не указан, используется `--debug`.
|
||||
Builds the project. If no profile is specified, `--debug` is used.
|
||||
|
||||
### `dcr run [profile]`
|
||||
Собирает проект и запускает бинарник. Если профиль не указан, используется `--debug`.
|
||||
Builds the project and runs the binary. If no profile is specified, `--debug` is used.
|
||||
|
||||
Запуск вручную:
|
||||
`./target/<profile>/main`
|
||||
Run manually:
|
||||
`./target/<profile>/<name>`
|
||||
|
||||
### `dcr clean`
|
||||
Удаляет папку `target` в корне проекта.
|
||||
Removes the `target` directory in the project root.
|
||||
|
||||
## Профили сборки
|
||||
Поддерживаются два профиля:
|
||||
- `--debug` (по умолчанию) — флаги: `-O0 -g -Wall -Wextra -fno-omit-frame-pointer -DDEBUG`
|
||||
- `--release` — флаги: `-O3 -DNDEBUG -march=native`
|
||||
## Build Profiles
|
||||
Two profiles are supported:
|
||||
- `--debug` (default) - built-in flags per compiler
|
||||
- `--release` - built-in flags per compiler
|
||||
|
||||
## Конфигурация
|
||||
Основной файл проекта — `dcr.toml`.
|
||||
Custom flags can be added in `dcr.toml` via `build.cflags` and `build.ldflags`.
|
||||
You can also set `build.target` to override the output directory (profile-independent).
|
||||
Use `build.kind = "staticlib"` to build a static library instead of a binary.
|
||||
`dcr run` is only for `build.kind = "bin"` and will fail for `staticlib`.
|
||||
|
||||
Пример `dcr.toml`:
|
||||
## Configuration
|
||||
The main project file is `dcr.toml`.
|
||||
|
||||
Example `dcr.toml`:
|
||||
|
||||
```toml
|
||||
[package]
|
||||
name = "hello"
|
||||
version = "0.1.0"
|
||||
|
||||
[build]
|
||||
language = "c"
|
||||
standard = "c11"
|
||||
compiler = "clang"
|
||||
# Optional custom flags
|
||||
cflags = ["-Wall", "-Wextra"]
|
||||
ldflags = ["-lm"]
|
||||
|
||||
[dependencies]
|
||||
```
|
||||
|
||||
## Требования
|
||||
- Rust toolchain (`rustc`, `cargo`) - Для ручной сборки DCR
|
||||
- C-компилятор (`clang`, `gcc` или другие)
|
||||
Path dependencies are supported. DCR will resolve them on build and generate `dcr.lock`.
|
||||
|
||||
## Релизы
|
||||
Релизы собираются автоматически через GitHub Actions (`.github/workflows/release.yml`) при пуше тега формата `v*`.
|
||||
Incremental build note: object files are rebuilt when source `.c/.cpp` files change. Header dependency tracking is not implemented yet.
|
||||
|
||||
## Лицензия
|
||||
См. файл `LICENSE`.
|
||||
## Requirements
|
||||
- Rust toolchain (`rustc`, `cargo`) - for building DCR from source
|
||||
- C compiler (`clang`, `gcc`, or 'cl'(msvc))
|
||||
|
||||
## Releases
|
||||
Releases are built automatically via GitHub Actions (`.github/workflows/release.yml`) when a tag matching `v*` is pushed.
|
||||
|
||||
## License
|
||||
See `LICENSE`.
|
||||
|
||||
6
TODO.md
Normal file
6
TODO.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# TODO
|
||||
|
||||
- Add incremental builds
|
||||
- Add header dependency tracking for incremental builds (GCC/Clang: -MMD, MSVC: /showIncludes)
|
||||
- Add external package managers (Conan, vcpkg)
|
||||
- Support building static libraries (ar .a)
|
||||
35
docs/README.md
Normal file
35
docs/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Introduction
|
||||
|
||||
DCR (Dexoron Cargo Realization) is a Cargo-style CLI for C/C++ projects.
|
||||
|
||||
Current DCR focuses on a simple, predictable workflow:
|
||||
|
||||
- create or initialize a project (`dcr new`, `dcr init`)
|
||||
- build with `debug` or `release` profiles (`dcr build`)
|
||||
- run binaries (`dcr run`)
|
||||
- clean artifacts (`dcr clean`)
|
||||
- update the installed binary (`dcr --update`)
|
||||
|
||||
## What is implemented in this version
|
||||
|
||||
- Project configuration in `dcr.toml` with `[package]`, `[build]`, `[dependencies]`.
|
||||
- Recursive source discovery in `src/`:
|
||||
- C: `*.c`
|
||||
- C++: `*.cpp`, `*.cxx`, `*.cc`
|
||||
- Compiler selection from `dcr.toml` (`clang`, `gcc`, `cl`, `clang-cl`, etc.).
|
||||
- Two build kinds:
|
||||
- `bin` (default)
|
||||
- `staticlib`
|
||||
- Optional custom output directory via `build.target`.
|
||||
- Path dependencies with include/lib resolution and `dcr.lock` generation.
|
||||
|
||||
## Important behavior notes
|
||||
|
||||
- `dcr.toml` is required for `build`, `run`, and `clean`.
|
||||
- `run` works only with `build.kind = "bin"`.
|
||||
- Incremental rebuild currently tracks source file timestamps (not header dependency graphs).
|
||||
- Object files are always created under `target/<profile>/obj/`.
|
||||
|
||||
## Repository
|
||||
|
||||
- <https://github.com/dexoron/dcr>
|
||||
41
docs/SUMMARY.md
Normal file
41
docs/SUMMARY.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# Table of contents
|
||||
|
||||
* [Introduction](README.md)
|
||||
|
||||
## Getting started
|
||||
|
||||
* [Installation](getting-started/installation.md)
|
||||
* [Create your first project](getting-started/create-your-first-project.md)
|
||||
* [Project structure](getting-started/project-structure.md)
|
||||
* [Build and run](getting-started/build-and-run.md)
|
||||
|
||||
## Configuration
|
||||
|
||||
* [dcr.toml overview](configuration/dcr.toml-overview.md)
|
||||
* [Package section](configuration/package-section.md)
|
||||
* [Build section](configuration/build-section.md)
|
||||
* [Dependencies section](configuration/dependencies-section.md)
|
||||
* [Build profiles](configuration/build-profiles.md)
|
||||
|
||||
## Commands
|
||||
|
||||
* [Global options](commands/global-options.md)
|
||||
* [dcr init/new](commands/dcr-init-or-new.md)
|
||||
* [dcr build](commands/dcr-build.md)
|
||||
* [dcr run](commands/dcr-run.md)
|
||||
* [dcr clean](commands/dcr-clean.md)
|
||||
|
||||
## Dependencies & Build
|
||||
|
||||
* [Dependency format](dependencies-and-build/dependency-format.md)
|
||||
* [Local dependencies](dependencies-and-build/local-dependencies.md)
|
||||
* [Versioning & lock file](dependencies-and-build/versioning-and-lock-file.md)
|
||||
* [Target directory](dependencies-and-build/target-directory.md)
|
||||
* [Compilers & linking](dependencies-and-build/compilers-and-linking.md)
|
||||
|
||||
## Reference & Help
|
||||
|
||||
* [CLI reference](reference-and-help/cli-reference.md)
|
||||
* [Config reference](reference-and-help/config-reference.md)
|
||||
* [FAQ](reference-and-help/faq.md)
|
||||
* [Contributing & Bug reports](reference-and-help/contributing-and-bug-reports.md)
|
||||
42
docs/commands/dcr-build.md
Normal file
42
docs/commands/dcr-build.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# dcr build
|
||||
|
||||
Builds the project in `debug` or `release` profile.
|
||||
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
dcr build
|
||||
dcr build --debug
|
||||
dcr build --release
|
||||
```
|
||||
|
||||
## What `build` does
|
||||
|
||||
1. Checks that `dcr.toml` exists and is valid.
|
||||
2. Reads build settings from `[build]`.
|
||||
3. Resolves path dependencies from `[dependencies]`.
|
||||
4. Creates required output directories.
|
||||
5. Recursively compiles sources from `src/`.
|
||||
6. Links final artifact (binary or static library).
|
||||
|
||||
## Config values used
|
||||
|
||||
- `package.name`
|
||||
- `build.compiler`
|
||||
- `build.language`
|
||||
- `build.standard`
|
||||
- `build.kind`
|
||||
- `build.target`
|
||||
- `build.cflags`
|
||||
- `build.ldflags`
|
||||
|
||||
## Source selection
|
||||
|
||||
- `language = "c"` -> `*.c`
|
||||
- `language = "c++" | "cpp" | "cxx"` -> `*.cpp`, `*.cxx`, `*.cc`
|
||||
|
||||
## Notes
|
||||
|
||||
- The profile is selected from the first argument only.
|
||||
- Unknown profile flags return an error.
|
||||
- Incremental rebuild is based on source/object mtime comparison.
|
||||
23
docs/commands/dcr-clean.md
Normal file
23
docs/commands/dcr-clean.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# dcr clean
|
||||
|
||||
Removes build artifacts in `target/`.
|
||||
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
dcr clean
|
||||
dcr clean --debug
|
||||
dcr clean --release
|
||||
```
|
||||
|
||||
## Behavior
|
||||
|
||||
- Without arguments: removes entire `target/`.
|
||||
- With profile: removes only `target/<profile>/`.
|
||||
|
||||
## Validation
|
||||
|
||||
- `dcr.toml` must exist.
|
||||
- More than one argument is treated as error.
|
||||
- Unknown profile is treated as error.
|
||||
- If `target` or selected profile directory does not exist, command prints a warning.
|
||||
43
docs/commands/dcr-init-or-new.md
Normal file
43
docs/commands/dcr-init-or-new.md
Normal file
@@ -0,0 +1,43 @@
|
||||
# dcr init/new
|
||||
|
||||
## `dcr new <name>`
|
||||
|
||||
Creates a new project directory and initializes it.
|
||||
|
||||
```sh
|
||||
dcr new hello
|
||||
```
|
||||
|
||||
Behavior:
|
||||
|
||||
1. Validates arguments (`<name>` is required, only one name is allowed).
|
||||
2. Creates `<name>/`.
|
||||
3. Creates `<name>/dcr.toml`.
|
||||
4. Sets `package.name = "<name>"`.
|
||||
5. Creates `<name>/src/main.c` with a Hello World template.
|
||||
|
||||
Errors:
|
||||
|
||||
- Missing project name.
|
||||
- Extra arguments.
|
||||
- Target directory already exists.
|
||||
|
||||
## `dcr init`
|
||||
|
||||
Initializes DCR in the current directory.
|
||||
|
||||
```sh
|
||||
dcr init
|
||||
```
|
||||
|
||||
Behavior:
|
||||
|
||||
1. Requires current directory to be empty.
|
||||
2. Creates `dcr.toml`.
|
||||
3. Sets `package.name` from the current directory name.
|
||||
4. Creates `src/main.c`.
|
||||
|
||||
Errors:
|
||||
|
||||
- Any arguments are treated as invalid.
|
||||
- Non-empty directory is rejected.
|
||||
27
docs/commands/dcr-run.md
Normal file
27
docs/commands/dcr-run.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# dcr run
|
||||
|
||||
Builds the project and runs the resulting binary.
|
||||
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
dcr run
|
||||
dcr run --debug
|
||||
dcr run --release
|
||||
```
|
||||
|
||||
## Behavior
|
||||
|
||||
1. Validates `dcr.toml`.
|
||||
2. Reads `package.name`, `build.kind`, and optional `build.target`.
|
||||
3. Runs the same build flow as `dcr build`.
|
||||
4. Executes the built artifact path for the selected profile.
|
||||
|
||||
## Restrictions
|
||||
|
||||
- If `build.kind = "staticlib"`, `run` exits with error.
|
||||
- The profile is selected from the first argument.
|
||||
|
||||
## On build failure
|
||||
|
||||
`dcr run` attempts to launch an existing binary from the same profile if present; otherwise it reports that code errors must be fixed.
|
||||
44
docs/commands/global-options.md
Normal file
44
docs/commands/global-options.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Global options
|
||||
|
||||
## `dcr --help`
|
||||
|
||||
```sh
|
||||
dcr --help
|
||||
```
|
||||
|
||||
Prints top-level CLI usage, commands, flags, and examples.
|
||||
|
||||
## `dcr --version`
|
||||
|
||||
```sh
|
||||
dcr --version
|
||||
```
|
||||
|
||||
Prints:
|
||||
|
||||
```text
|
||||
dcr <version> (<target>)
|
||||
```
|
||||
|
||||
## `dcr --update`
|
||||
|
||||
```sh
|
||||
dcr --update
|
||||
```
|
||||
|
||||
Update flow:
|
||||
|
||||
1. Requests latest release from GitHub API.
|
||||
2. Finds asset matching current `DCR_TARGET`.
|
||||
3. Downloads replacement binary.
|
||||
4. Replaces current executable via `self-replace`.
|
||||
|
||||
Limitations and behavior:
|
||||
|
||||
- No extra arguments are accepted.
|
||||
- Requires network access to GitHub API/assets.
|
||||
- On Linux, if binary is owned by pacman, DCR prints package-manager update instructions instead of self-updating.
|
||||
|
||||
## Running without command
|
||||
|
||||
Running plain `dcr` (without arguments) shows help output.
|
||||
39
docs/configuration/build-profiles.md
Normal file
39
docs/configuration/build-profiles.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Build profiles
|
||||
|
||||
DCR supports two profiles:
|
||||
|
||||
- `debug` (default)
|
||||
- `release`
|
||||
|
||||
## How to select
|
||||
|
||||
```sh
|
||||
dcr build --debug
|
||||
dcr build --release
|
||||
dcr run --release
|
||||
dcr clean --debug
|
||||
```
|
||||
|
||||
## Default profile flags
|
||||
|
||||
### GCC/Clang-like toolchains
|
||||
|
||||
- `debug`: `-O0 -g -Wall -Wextra -fno-omit-frame-pointer -DDEBUG`
|
||||
- `release`: `-O3 -DNDEBUG -march=native`
|
||||
|
||||
### MSVC toolchain
|
||||
|
||||
- `debug`: `/Od /Zi /W4 /DDEBUG /Oy-`
|
||||
- `release`: `/O2 /DNDEBUG`
|
||||
|
||||
## Artifacts
|
||||
|
||||
By default:
|
||||
|
||||
- `target/debug/<name>` (or `.exe` on Windows)
|
||||
- `target/release/<name>` (or `.exe` on Windows)
|
||||
|
||||
Static library mode (`kind = "staticlib"`):
|
||||
|
||||
- Linux/macOS: `lib<name>.a`
|
||||
- Windows: `<name>.lib`
|
||||
31
docs/configuration/build-section.md
Normal file
31
docs/configuration/build-section.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# Build section
|
||||
|
||||
## Schema
|
||||
|
||||
```toml
|
||||
[build]
|
||||
language = "c"
|
||||
standard = "c11"
|
||||
compiler = "clang"
|
||||
kind = "bin"
|
||||
# optional:
|
||||
# target = "./dist"
|
||||
# cflags = ["-Wall"]
|
||||
# ldflags = ["-lm"]
|
||||
```
|
||||
|
||||
## Fields
|
||||
|
||||
- `language` (string, required): `c`, `c++`, `cpp`, or `cxx`.
|
||||
- `standard` (string, required): language standard passed to compiler.
|
||||
- `compiler` (string, required): compiler command (for example `clang`, `gcc`, `cl`).
|
||||
- `kind` (string, required): `bin` or `staticlib`.
|
||||
- `target` (string, optional): custom output directory for final artifact.
|
||||
- `cflags` (string array, optional): extra compile flags.
|
||||
- `ldflags` (string array, optional): extra link flags.
|
||||
|
||||
## Behavior notes
|
||||
|
||||
- Compiler backend is selected by compiler string (`gcc`, `clang`, `cl`, `clang-cl`).
|
||||
- Empty or unknown compiler value falls back to clang-like build path.
|
||||
- `run` is not allowed for `kind = "staticlib"`.
|
||||
45
docs/configuration/dcr.toml-overview.md
Normal file
45
docs/configuration/dcr.toml-overview.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# dcr.toml overview
|
||||
|
||||
`dcr.toml` is the main project file used by DCR.
|
||||
|
||||
## Minimal generated template
|
||||
|
||||
```toml
|
||||
[package]
|
||||
name = "hello"
|
||||
version = "0.1.0"
|
||||
|
||||
[build]
|
||||
language = "c"
|
||||
standard = "c11"
|
||||
compiler = "clang"
|
||||
kind = "bin"
|
||||
|
||||
[dependencies]
|
||||
```
|
||||
|
||||
`dcr new` and `dcr init` generate this structure automatically.
|
||||
|
||||
## Required sections
|
||||
|
||||
- `[package]`
|
||||
- `[build]`
|
||||
- `[dependencies]`
|
||||
|
||||
## Required keys
|
||||
|
||||
- `package.name`
|
||||
- `package.version`
|
||||
- `build.language`
|
||||
- `build.standard`
|
||||
- `build.compiler`
|
||||
- `build.kind`
|
||||
|
||||
`build.kind` must be either `bin` or `staticlib`.
|
||||
|
||||
## Optional keys
|
||||
|
||||
- `build.target`
|
||||
- `build.cflags`
|
||||
- `build.ldflags`
|
||||
- dependency fields (`include`, `lib`, `libs`, `system`)
|
||||
30
docs/configuration/dependencies-section.md
Normal file
30
docs/configuration/dependencies-section.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Dependencies section
|
||||
|
||||
DCR currently supports path dependencies.
|
||||
|
||||
## Example
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
frecli = { path = "./lib/frecli", include = ["."], lib = ["."], libs = ["frecli"] }
|
||||
```
|
||||
|
||||
## Supported fields per dependency
|
||||
|
||||
- `path` (string, required): absolute path or path relative to project root.
|
||||
- `include` (string array, optional): include directories inside dependency.
|
||||
- `lib` (string array, optional): library directories inside dependency.
|
||||
- `libs` (string array, optional): library names for linker.
|
||||
- `system` (bool, optional): currently `system = true` is rejected.
|
||||
|
||||
## Defaults
|
||||
|
||||
- If `include` is omitted, DCR tries `<dep>/include`.
|
||||
- If `lib` is omitted, DCR tries `<dep>/lib`, then `<dep>/lib64`.
|
||||
- If `libs` is omitted, dependency key name is used.
|
||||
|
||||
## Validation
|
||||
|
||||
- Dependency value must be a TOML table.
|
||||
- `path` is mandatory.
|
||||
- `include`/`lib`/`libs` must be arrays of strings if provided.
|
||||
20
docs/configuration/package-section.md
Normal file
20
docs/configuration/package-section.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Package section
|
||||
|
||||
## Schema
|
||||
|
||||
```toml
|
||||
[package]
|
||||
name = "my-app"
|
||||
version = "0.1.0"
|
||||
```
|
||||
|
||||
## Fields
|
||||
|
||||
- `name` (string, required): used as output artifact base name.
|
||||
- `version` (string, required): used in `dcr.lock` project entry.
|
||||
|
||||
## Notes
|
||||
|
||||
- Empty `name` or `version` makes config invalid.
|
||||
- `dcr new` sets `name` from the passed project name.
|
||||
- `dcr init` sets `name` from current directory name.
|
||||
30
docs/dependencies-and-build/compilers-and-linking.md
Normal file
30
docs/dependencies-and-build/compilers-and-linking.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Compilers & linking
|
||||
|
||||
## Compiler backend selection
|
||||
|
||||
DCR picks a backend from `build.compiler`:
|
||||
|
||||
- contains `clang-cl` -> MSVC backend
|
||||
- contains `gcc` or `g++` -> GCC backend
|
||||
- contains `clang` or `clang++` -> Clang backend
|
||||
- equals `cl` or contains `msvc` -> MSVC backend
|
||||
- otherwise -> Clang backend fallback
|
||||
|
||||
## Compilation model
|
||||
|
||||
- Source files are found recursively in `src/` based on `build.language`.
|
||||
- Each source is compiled to `target/<profile>/obj/<relative-path>.o` (`.obj` on MSVC).
|
||||
- Recompile happens when source mtime is newer than object mtime.
|
||||
|
||||
## Linking
|
||||
|
||||
For `kind = "bin"`:
|
||||
|
||||
- Object files are linked into executable artifact.
|
||||
- Dependency lib dirs and library names are passed to linker.
|
||||
- `build.ldflags` are appended to link command.
|
||||
|
||||
For `kind = "staticlib"`:
|
||||
|
||||
- Linux/macOS (GCC/Clang): `ar rcs` creates `.a` archive.
|
||||
- Windows (MSVC): `lib` creates `.lib` archive.
|
||||
26
docs/dependencies-and-build/dependency-format.md
Normal file
26
docs/dependencies-and-build/dependency-format.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Dependency format
|
||||
|
||||
Dependencies are defined in `dcr.toml` under `[dependencies]`.
|
||||
|
||||
## Full example
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
fmt = { path = "./third_party/fmt", include = ["include"], lib = ["lib"], libs = ["fmt"] }
|
||||
```
|
||||
|
||||
## Field reference
|
||||
|
||||
- `path`: required dependency root path.
|
||||
- `include`: optional include subpaths (absolute or relative to dep root).
|
||||
- `lib`: optional library subpaths (absolute or relative to dep root).
|
||||
- `libs`: optional linker library names.
|
||||
|
||||
## Common valid compact form
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
mylib = { path = "./libs/mylib" }
|
||||
```
|
||||
|
||||
In this form DCR will try defaults for include/lib dirs and use `mylib` as the linker library name.
|
||||
19
docs/dependencies-and-build/local-dependencies.md
Normal file
19
docs/dependencies-and-build/local-dependencies.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# Local dependencies
|
||||
|
||||
## Resolution flow during build
|
||||
|
||||
For each dependency in `[dependencies]`, DCR:
|
||||
|
||||
1. Resolves `path` (absolute or project-relative).
|
||||
2. Resolves include dirs (`include` or default `include`).
|
||||
3. Resolves lib dirs (`lib` or defaults `lib`, `lib64`).
|
||||
4. Resolves link libs (`libs` or dependency name).
|
||||
5. Synchronizes dependency files to `target/<profile>/deps/<dep-name>/`.
|
||||
6. Adds include/lib/link options to compile/link commands.
|
||||
|
||||
## Failure cases
|
||||
|
||||
- Dependency path is missing or not a directory.
|
||||
- No valid include/lib directories were found.
|
||||
- Any configured include/lib path does not exist.
|
||||
- Invalid field types in dependency config.
|
||||
23
docs/dependencies-and-build/target-directory.md
Normal file
23
docs/dependencies-and-build/target-directory.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# Target directory
|
||||
|
||||
By default, DCR writes final artifacts to `target/<profile>/`.
|
||||
|
||||
You can override this with `build.target`:
|
||||
|
||||
```toml
|
||||
[build]
|
||||
target = "./dist"
|
||||
```
|
||||
|
||||
## Behavior
|
||||
|
||||
- Binary mode:
|
||||
- Linux/macOS: `<target>/<name>`
|
||||
- Windows: `<target>/<name>.exe`
|
||||
- Static library mode:
|
||||
- Linux/macOS: `<target>/lib<name>.a`
|
||||
- Windows: `<target>/<name>.lib`
|
||||
|
||||
## Important detail
|
||||
|
||||
`build.target` changes only the final artifact location. Object cache and dependency sync directories still use `target/<profile>/...`.
|
||||
32
docs/dependencies-and-build/versioning-and-lock-file.md
Normal file
32
docs/dependencies-and-build/versioning-and-lock-file.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Versioning & lock file
|
||||
|
||||
DCR generates `dcr.lock` when dependency resolution succeeds and at least one dependency exists.
|
||||
|
||||
## What is stored
|
||||
|
||||
- Project entry (`name`, `version`, dependency names).
|
||||
- One entry per resolved dependency:
|
||||
- `name`
|
||||
- `version` (from dependency `dcr.toml`, fallback `0.0.0`)
|
||||
- `source` (`path+...`)
|
||||
- `checksum` (SHA-256 over dependency files, excluding nested `target/`).
|
||||
|
||||
## Example shape
|
||||
|
||||
```toml
|
||||
[[package]]
|
||||
name = "my-app"
|
||||
version = "0.1.0"
|
||||
dependencies = ["fmt"]
|
||||
|
||||
[[package]]
|
||||
name = "fmt"
|
||||
version = "1.2.3"
|
||||
source = "path+./third_party/fmt"
|
||||
checksum = "..."
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- `dcr.lock` is rewritten on successful dependency resolution.
|
||||
- If `[dependencies]` is empty, lock generation is skipped.
|
||||
46
docs/getting-started/build-and-run.md
Normal file
46
docs/getting-started/build-and-run.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Build and run
|
||||
|
||||
## Build
|
||||
|
||||
Debug (default):
|
||||
|
||||
```sh
|
||||
dcr build
|
||||
# or
|
||||
dcr build --debug
|
||||
```
|
||||
|
||||
Release:
|
||||
|
||||
```sh
|
||||
dcr build --release
|
||||
```
|
||||
|
||||
## Run
|
||||
|
||||
```sh
|
||||
dcr run
|
||||
# or
|
||||
dcr run --release
|
||||
```
|
||||
|
||||
`dcr run` first builds, then launches the produced binary.
|
||||
|
||||
## Clean artifacts
|
||||
|
||||
```sh
|
||||
dcr clean
|
||||
```
|
||||
|
||||
Profile-only cleanup:
|
||||
|
||||
```sh
|
||||
dcr clean --debug
|
||||
dcr clean --release
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- `run` is unavailable for `build.kind = "staticlib"`.
|
||||
- Build profile flag is parsed from the first command argument.
|
||||
- Unknown profile flags produce an error.
|
||||
41
docs/getting-started/create-your-first-project.md
Normal file
41
docs/getting-started/create-your-first-project.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# Create your first project
|
||||
|
||||
## Create in a new folder
|
||||
|
||||
```sh
|
||||
dcr new hello
|
||||
cd hello
|
||||
```
|
||||
|
||||
This creates:
|
||||
|
||||
```text
|
||||
hello/
|
||||
- dcr.toml
|
||||
- src/
|
||||
- - main.c
|
||||
```
|
||||
|
||||
## Or initialize current folder
|
||||
|
||||
```sh
|
||||
mkdir hello
|
||||
cd hello
|
||||
dcr init
|
||||
```
|
||||
|
||||
`dcr init` requires the current directory to be empty.
|
||||
|
||||
## Next steps
|
||||
|
||||
Build and run:
|
||||
|
||||
```sh
|
||||
dcr run
|
||||
```
|
||||
|
||||
Release build/run:
|
||||
|
||||
```sh
|
||||
dcr run --release
|
||||
```
|
||||
56
docs/getting-started/installation.md
Normal file
56
docs/getting-started/installation.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# Installation
|
||||
|
||||
## Option 1: Install via script
|
||||
|
||||
### Linux/macOS
|
||||
|
||||
```sh
|
||||
curl -fsSL https://dcr.dexoron.su/install.sh | bash
|
||||
```
|
||||
|
||||
Alternative with `wget`:
|
||||
|
||||
```sh
|
||||
wget -qO- https://dcr.dexoron.su/install.sh | bash
|
||||
```
|
||||
|
||||
### Windows (PowerShell)
|
||||
|
||||
```powershell
|
||||
powershell -ExecutionPolicy ByPass -c "irm https://dcr.dexoron.su/install.ps1 | iex"
|
||||
```
|
||||
|
||||
## Option 2: Build from source
|
||||
|
||||
```sh
|
||||
git clone https://github.com/dexoron/dcr.git
|
||||
cd dcr
|
||||
cargo build --release
|
||||
mkdir -p ~/.local/bin
|
||||
ln -sf "$PWD/target/release/dcr" ~/.local/bin/dcr
|
||||
```
|
||||
|
||||
## Option 3: Arch Linux (AUR)
|
||||
|
||||
```sh
|
||||
yay -S dcr
|
||||
```
|
||||
|
||||
(You can also use `paru` or other AUR helpers.)
|
||||
|
||||
## Verify installation
|
||||
|
||||
```sh
|
||||
dcr --version
|
||||
```
|
||||
|
||||
Expected format:
|
||||
|
||||
```text
|
||||
dcr <version> (<target>)
|
||||
```
|
||||
|
||||
## Update policy
|
||||
|
||||
- If DCR was installed from GitHub releases, scripts, or manual build: use `dcr --update`.
|
||||
- If DCR is managed by `pacman/AUR`: update via package manager. On Linux, `dcr --update` detects pacman-owned binaries and prints a package-manager hint.
|
||||
39
docs/getting-started/project-structure.md
Normal file
39
docs/getting-started/project-structure.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Project structure
|
||||
|
||||
## Minimal project
|
||||
|
||||
```text
|
||||
project/
|
||||
- dcr.toml
|
||||
- src/
|
||||
- - main.c
|
||||
```
|
||||
|
||||
## Typical generated/optional files
|
||||
|
||||
```text
|
||||
project/
|
||||
- dcr.toml
|
||||
- dcr.lock
|
||||
- src/
|
||||
- - ... source files ...
|
||||
- target/
|
||||
- - debug/
|
||||
- - - obj/
|
||||
- - - deps/
|
||||
- - release/
|
||||
- - - obj/
|
||||
- - - deps/
|
||||
```
|
||||
|
||||
## Meaning
|
||||
|
||||
- `dcr.toml`: main project configuration.
|
||||
- `dcr.lock`: generated lock file for resolved path dependencies.
|
||||
- `src/`: recursively scanned source directory.
|
||||
- `target/<profile>/obj/`: cached object files for incremental rebuild.
|
||||
- `target/<profile>/deps/`: synchronized copies of path dependencies.
|
||||
- `target/<profile>/<name>` (or `.exe` on Windows): output for `kind = "bin"`.
|
||||
- `target/<profile>/lib<name>.a` (or `<name>.lib` on Windows): output for `kind = "staticlib"`.
|
||||
|
||||
If `build.target` is set, the final artifact is written to that custom directory, while object cache still stays in `target/<profile>/obj`.
|
||||
26
docs/reference-and-help/cli-reference.md
Normal file
26
docs/reference-and-help/cli-reference.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# CLI reference
|
||||
|
||||
## Command list
|
||||
|
||||
```text
|
||||
dcr new <name>
|
||||
dcr init
|
||||
dcr build [--debug|--release]
|
||||
dcr run [--debug|--release]
|
||||
dcr clean [--debug|--release]
|
||||
dcr --help
|
||||
dcr --version
|
||||
dcr --update
|
||||
```
|
||||
|
||||
## Notes on argument parsing
|
||||
|
||||
- Most commands parse profile from the first argument.
|
||||
- `new` requires exactly one argument.
|
||||
- `init` and `--update` do not accept extra arguments.
|
||||
- `clean` accepts at most one argument.
|
||||
|
||||
## Exit behavior overview
|
||||
|
||||
- Successful command execution returns `0`.
|
||||
- Validation/build/runtime errors return non-zero status.
|
||||
41
docs/reference-and-help/config-reference.md
Normal file
41
docs/reference-and-help/config-reference.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# Config reference
|
||||
|
||||
## Full schema
|
||||
|
||||
```toml
|
||||
[package]
|
||||
name = "string" # required
|
||||
version = "string" # required
|
||||
|
||||
[build]
|
||||
language = "c|c++|cpp|cxx" # required
|
||||
standard = "string" # required
|
||||
compiler = "string" # required
|
||||
kind = "bin|staticlib" # required
|
||||
target = "string" # optional
|
||||
cflags = ["string", "..."] # optional
|
||||
ldflags = ["string", "..."] # optional
|
||||
|
||||
[dependencies]
|
||||
name = {
|
||||
path = "string", # required for each dependency
|
||||
include = ["string", "..."], # optional
|
||||
lib = ["string", "..."], # optional
|
||||
libs = ["string", "..."], # optional
|
||||
}
|
||||
```
|
||||
|
||||
## Validation rules
|
||||
|
||||
- `[package]`, `[build]`, `[dependencies]` must exist.
|
||||
- Required string fields must be non-empty.
|
||||
- `build.kind` must be `bin` or `staticlib`.
|
||||
- Dependency fields `include/lib/libs` must be string arrays when provided.
|
||||
|
||||
## Generated defaults (`dcr new` / `dcr init`)
|
||||
|
||||
- `package.version = "0.1.0"`
|
||||
- `build.language = "c"`
|
||||
- `build.standard = "c11"`
|
||||
- `build.compiler = "clang"`
|
||||
- `build.kind = "bin"`
|
||||
34
docs/reference-and-help/contributing-and-bug-reports.md
Normal file
34
docs/reference-and-help/contributing-and-bug-reports.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# Contributing & Bug reports
|
||||
|
||||
## Contribution workflow
|
||||
|
||||
1. Fork `dexoron/dcr` (and `dexoron/dcr-site` if docs website changes are needed).
|
||||
2. Make focused changes.
|
||||
3. Run checks locally:
|
||||
|
||||
```bash
|
||||
cargo fmt --all
|
||||
cargo clippy --all-targets --all-features -- -D warnings
|
||||
cargo check
|
||||
```
|
||||
|
||||
4. Open a PR with short rationale and behavior impact.
|
||||
5. Update docs when CLI behavior changes.
|
||||
|
||||
## Bug report checklist
|
||||
|
||||
Include:
|
||||
|
||||
1. DCR version (`dcr --version`).
|
||||
2. OS and compiler/toolchain version.
|
||||
3. Reproduction steps.
|
||||
4. Expected result.
|
||||
5. Actual result and full error output.
|
||||
6. Minimal reproducible project.
|
||||
|
||||
## Where to report
|
||||
|
||||
Use GitHub Issues in the relevant repository:
|
||||
|
||||
- <https://github.com/dexoron/dcr>
|
||||
- <https://github.com/dexoron/dcr-site>
|
||||
34
docs/reference-and-help/faq.md
Normal file
34
docs/reference-and-help/faq.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# FAQ
|
||||
|
||||
## What commands are available?
|
||||
|
||||
`new`, `init`, `build`, `run`, `clean`, `--help`, `--version`, `--update`.
|
||||
|
||||
## Is `dcr.toml` mandatory?
|
||||
|
||||
Yes, for `build`, `run`, and `clean`.
|
||||
|
||||
## What source files are compiled?
|
||||
|
||||
DCR scans `src/` recursively:
|
||||
|
||||
- for C: `*.c`
|
||||
- for C++: `*.cpp`, `*.cxx`, `*.cc`
|
||||
|
||||
## Can I switch compiler?
|
||||
|
||||
Yes. Set `build.compiler` in `dcr.toml` (for example `gcc`, `clang`, `cl`, `clang-cl`).
|
||||
|
||||
## How does incremental rebuild work?
|
||||
|
||||
It compares source file mtime with object file mtime. Header dependency tracking is not implemented yet.
|
||||
|
||||
## What does `dcr run` do if build fails?
|
||||
|
||||
It tries to run an existing binary from the selected profile; if none exists, it reports an error.
|
||||
|
||||
## How do I update DCR?
|
||||
|
||||
Use `dcr --update` for non-package-managed installs.
|
||||
|
||||
If installed through pacman/AUR, update via package manager.
|
||||
36
install.ps1
36
install.ps1
@@ -13,27 +13,27 @@ function Fail($msg) { Write-Host "[ERROR] $msg" -ForegroundColor Red; exit 1 }
|
||||
|
||||
function Require-Cmd($name) {
|
||||
if (-not (Get-Command $name -ErrorAction SilentlyContinue)) {
|
||||
Fail "Не найдено: $name"
|
||||
Fail "Not found: $name"
|
||||
}
|
||||
}
|
||||
|
||||
function Select-Mode {
|
||||
Write-Host "Выбери способ установки:"
|
||||
Write-Host " 1) Скачать готовый бинарник из GitHub Release (рекомендуется)"
|
||||
Write-Host " 2) Собрать из git"
|
||||
$choice = Read-Host "Введите 1 или 2 [1]"
|
||||
Write-Host "Choose installation mode:"
|
||||
Write-Host " 1) Download prebuilt binary from GitHub Release (recommended)"
|
||||
Write-Host " 2) Build from git"
|
||||
$choice = Read-Host "Enter 1 or 2 [1]"
|
||||
if ([string]::IsNullOrWhiteSpace($choice)) { $choice = '1' }
|
||||
|
||||
switch ($choice) {
|
||||
'1' { return 'release' }
|
||||
'2' { return 'build' }
|
||||
default { Fail 'Неизвестный вариант' }
|
||||
default { Fail 'Unknown option' }
|
||||
}
|
||||
}
|
||||
|
||||
function Get-Target {
|
||||
if ($env:PROCESSOR_ARCHITECTURE -ne 'AMD64') {
|
||||
Fail "Поддерживается только x86_64 Windows, текущая архитектура: $env:PROCESSOR_ARCHITECTURE"
|
||||
Fail "Only x86_64 Windows is supported, current architecture: $env:PROCESSOR_ARCHITECTURE"
|
||||
}
|
||||
return 'x86_64-pc-windows-msvc'
|
||||
}
|
||||
@@ -44,17 +44,17 @@ function Install-FromRelease {
|
||||
New-Item -ItemType Directory -Path $InstallPath -Force | Out-Null
|
||||
|
||||
$assetName = "dcr-$target.exe"
|
||||
Info "Получение последнего релиза..."
|
||||
Info "Fetching latest release..."
|
||||
$release = Invoke-RestMethod -Method Get -Uri $ApiUrl
|
||||
|
||||
$asset = $release.assets | Where-Object { $_.name -eq $assetName } | Select-Object -First 1
|
||||
if (-not $asset) {
|
||||
Fail "Не найден ассет $assetName в релизе $($release.tag_name)"
|
||||
Fail "Asset $assetName not found in release $($release.tag_name)"
|
||||
}
|
||||
|
||||
Info "Скачивание $assetName..."
|
||||
Info "Downloading $assetName..."
|
||||
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $BinaryPath
|
||||
Ok "Скачан бинарник $assetName"
|
||||
Ok "Binary downloaded: $assetName"
|
||||
}
|
||||
|
||||
function Install-FromSource {
|
||||
@@ -66,17 +66,17 @@ function Install-FromSource {
|
||||
$tmp = Join-Path $env:TEMP 'dcr-install'
|
||||
if (Test-Path $tmp) { Remove-Item -Recurse -Force $tmp }
|
||||
|
||||
Info 'Клонирование репозитория...'
|
||||
Info 'Cloning repository...'
|
||||
git clone --depth 1 $RepoUrl $tmp | Out-Null
|
||||
|
||||
Info 'Сборка release-бинарника...'
|
||||
Info 'Building release binary...'
|
||||
Push-Location $tmp
|
||||
cargo build --release --target $target
|
||||
Pop-Location
|
||||
|
||||
New-Item -ItemType Directory -Path $InstallPath -Force | Out-Null
|
||||
Copy-Item (Join-Path $tmp "target\$target\release\dcr.exe") $BinaryPath -Force
|
||||
Ok 'Установлен бинарник из исходников'
|
||||
Ok 'Binary installed from source'
|
||||
|
||||
Remove-Item -Recurse -Force $tmp
|
||||
}
|
||||
@@ -93,13 +93,13 @@ function Setup-Path {
|
||||
$newPath = if ($userPath) { "$userPath;$BinPath" } else { $BinPath }
|
||||
[Environment]::SetEnvironmentVariable('Path', $newPath, 'User')
|
||||
$env:Path = "$env:Path;$BinPath"
|
||||
Warn "Добавлен путь в PATH: $BinPath"
|
||||
Warn "Added path to PATH: $BinPath"
|
||||
}
|
||||
|
||||
Ok "Команда dcr доступна через $linkPath"
|
||||
Ok "dcr command is available via $linkPath"
|
||||
}
|
||||
|
||||
Info 'Запуск установки DCR'
|
||||
Info 'Starting DCR installation'
|
||||
$mode = Select-Mode
|
||||
$target = Get-Target
|
||||
|
||||
@@ -110,4 +110,4 @@ if ($mode -eq 'build') {
|
||||
}
|
||||
|
||||
Setup-Path
|
||||
Ok 'Установка завершена успешно'
|
||||
Ok 'Installation completed successfully'
|
||||
|
||||
54
install.sh
54
install.sh
@@ -22,12 +22,12 @@ success() { echo -e "${GREEN}✔ $1${NC}"; }
|
||||
warn() { echo -e "${YELLOW}⚠ $1${NC}"; }
|
||||
error() { echo -e "${RED}✖ $1${NC}"; }
|
||||
|
||||
trap 'error "Ошибка на строке $LINENO"; exit 1' ERR
|
||||
trap 'error "Error on line $LINENO"; exit 1' ERR
|
||||
|
||||
check_os() {
|
||||
case "$(uname -s)" in
|
||||
Linux|Darwin) ;;
|
||||
*) error "Поддерживаются только Linux и macOS"; exit 1 ;;
|
||||
*) error "Only Linux and macOS are supported"; exit 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -40,32 +40,32 @@ detect_target() {
|
||||
Linux:x86_64) TARGET_TRIPLE="x86_64-unknown-linux-gnu" ;;
|
||||
Darwin:x86_64) TARGET_TRIPLE="x86_64-apple-darwin" ;;
|
||||
Darwin:arm64|Darwin:aarch64) TARGET_TRIPLE="aarch64-apple-darwin" ;;
|
||||
*) error "Неподдерживаемая платформа: $os/$arch"; exit 1 ;;
|
||||
*) error "Unsupported platform: $os/$arch"; exit 1 ;;
|
||||
esac
|
||||
|
||||
ASSET_NAME="dcr-${TARGET_TRIPLE}"
|
||||
}
|
||||
|
||||
check_common_dependencies() {
|
||||
command -v curl >/dev/null 2>&1 || { error "curl не установлен"; exit 1; }
|
||||
command -v curl >/dev/null 2>&1 || { error "curl is not installed"; exit 1; }
|
||||
}
|
||||
|
||||
check_build_dependencies() {
|
||||
command -v git >/dev/null 2>&1 || { error "git не установлен"; exit 1; }
|
||||
command -v cargo >/dev/null 2>&1 || { error "cargo не установлен"; exit 1; }
|
||||
command -v git >/dev/null 2>&1 || { error "git is not installed"; exit 1; }
|
||||
command -v cargo >/dev/null 2>&1 || { error "cargo is not installed"; exit 1; }
|
||||
}
|
||||
|
||||
prepare_sources() {
|
||||
log "Получение исходников..."
|
||||
log "Fetching sources..."
|
||||
rm -rf "$TMPDIR"
|
||||
git clone --depth 1 "$REPO_URL" "$TMPDIR"
|
||||
success "Исходники получены"
|
||||
success "Sources fetched"
|
||||
}
|
||||
|
||||
build_binary() {
|
||||
log "Сборка release-бинарника..."
|
||||
log "Building release binary..."
|
||||
(cd "$TMPDIR" && cargo build --release)
|
||||
success "Сборка завершена"
|
||||
success "Build completed"
|
||||
}
|
||||
|
||||
fetch_latest_release_json() {
|
||||
@@ -73,47 +73,47 @@ fetch_latest_release_json() {
|
||||
}
|
||||
|
||||
download_binary() {
|
||||
log "Получение последнего релиза..."
|
||||
log "Fetching latest release..."
|
||||
|
||||
local release_json download_url tag
|
||||
release_json="$(fetch_latest_release_json)"
|
||||
|
||||
tag="$(printf '%s\n' "$release_json" | sed -n 's/.*"tag_name": "\([^"]*\)".*/\1/p' | head -n1)"
|
||||
if [[ -z "$tag" ]]; then
|
||||
error "Не удалось определить версию релиза"
|
||||
error "Failed to determine release version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
download_url="$(printf '%s\n' "$release_json" | sed -n "s#.*\"browser_download_url\": \"\([^\"]*${ASSET_NAME}\)\".*#\1#p" | head -n1)"
|
||||
if [[ -z "$download_url" ]]; then
|
||||
error "Не найден ассет ${ASSET_NAME} в релизе ${tag}"
|
||||
error "Asset ${ASSET_NAME} not found in release ${tag}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$INSTALL_PATH"
|
||||
curl -fL "$download_url" -o "$INSTALL_PATH/dcr"
|
||||
chmod +x "$INSTALL_PATH/dcr"
|
||||
success "Скачан бинарник ${ASSET_NAME} (${tag})"
|
||||
success "Binary ${ASSET_NAME} downloaded (${tag})"
|
||||
}
|
||||
|
||||
install_built_binary() {
|
||||
mkdir -p "$INSTALL_PATH"
|
||||
cp "$TMPDIR/target/release/dcr" "$INSTALL_PATH/dcr"
|
||||
chmod +x "$INSTALL_PATH/dcr"
|
||||
success "Установлен бинарник из исходников"
|
||||
success "Binary installed from source"
|
||||
}
|
||||
|
||||
install_link() {
|
||||
log "Создание симлинка..."
|
||||
log "Creating symlink..."
|
||||
mkdir -p "$BINPATH"
|
||||
ln -sf "$INSTALL_PATH/dcr" "$BINPATH/dcr"
|
||||
success "Команда 'dcr' добавлена в $BINPATH"
|
||||
success "Command 'dcr' added to $BINPATH"
|
||||
}
|
||||
|
||||
check_path() {
|
||||
if ! echo "$PATH" | grep -q "$BINPATH"; then
|
||||
warn "Каталог $BINPATH не найден в PATH"
|
||||
echo "Добавь в ~/.bashrc или ~/.zshrc:"
|
||||
warn "Directory $BINPATH not found in PATH"
|
||||
echo "Add this to ~/.bashrc or ~/.zshrc:"
|
||||
echo "export PATH=\"$BINPATH:\$PATH\""
|
||||
fi
|
||||
}
|
||||
@@ -123,20 +123,20 @@ cleanup() {
|
||||
}
|
||||
|
||||
select_install_mode() {
|
||||
echo "Выбери способ установки:"
|
||||
echo " 1) Скачать готовый бинарник из GitHub Release (рекомендуется)"
|
||||
echo " 2) Собрать из git"
|
||||
read -r -p "Введите 1 или 2 [1]: " choice
|
||||
echo "Choose installation mode:"
|
||||
echo " 1) Download prebuilt binary from GitHub Release (recommended)"
|
||||
echo " 2) Build from git"
|
||||
read -r -p "Enter 1 or 2 [1]: " choice
|
||||
|
||||
case "${choice:-1}" in
|
||||
1) INSTALL_MODE="release" ;;
|
||||
2) INSTALL_MODE="build" ;;
|
||||
*) error "Неизвестный вариант"; exit 1 ;;
|
||||
*) error "Unknown option"; exit 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
main() {
|
||||
log "Запуск установки DCR"
|
||||
log "Starting DCR installation"
|
||||
|
||||
check_os
|
||||
detect_target
|
||||
@@ -157,8 +157,8 @@ main() {
|
||||
check_path
|
||||
cleanup
|
||||
|
||||
success "Установка завершена успешно"
|
||||
log "Лог сохранён в $LOGFILE"
|
||||
success "Installation completed successfully"
|
||||
log "Log saved to $LOGFILE"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
21
packaging/aur/README.md
Normal file
21
packaging/aur/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# AUR publishing
|
||||
|
||||
This repository includes an automated AUR publish workflow:
|
||||
- package files: `packaging/aur/dcr/PKGBUILD`, `packaging/aur/dcr/.SRCINFO`
|
||||
- workflow: `.github/workflows/aur.yml`
|
||||
|
||||
## One-time setup
|
||||
|
||||
1. Create the `dcr` package on AUR and initialize its git repository.
|
||||
2. Create an SSH key pair for CI.
|
||||
3. Add the public key to your AUR account.
|
||||
4. Add the private key to GitHub Actions secret `AUR_SSH_PRIVATE_KEY`.
|
||||
|
||||
## Release flow
|
||||
|
||||
1. Bump project version in `Cargo.toml`.
|
||||
2. Push tag `v<version>` (example: `v0.2.2`).
|
||||
3. GitHub Actions will:
|
||||
- compute source tarball SHA256
|
||||
- render `PKGBUILD` and `.SRCINFO`
|
||||
- push updates to `ssh://aur@aur.archlinux.org/dcr.git`
|
||||
17
packaging/aur/dcr/.SRCINFO
Normal file
17
packaging/aur/dcr/.SRCINFO
Normal file
@@ -0,0 +1,17 @@
|
||||
pkgbase = dcr
|
||||
pkgdesc = Cargo-like utility to manage C/C++ projects
|
||||
pkgver = 0.2.1
|
||||
pkgrel = 1
|
||||
url = https://github.com/dexoron/dcr
|
||||
arch = x86_64
|
||||
arch = aarch64
|
||||
license = MIT
|
||||
makedepends = cargo
|
||||
depends = gcc-libs
|
||||
optdepends = gcc: build C/C++ projects with GCC
|
||||
optdepends = clang: build C/C++ projects with Clang
|
||||
options = !lto
|
||||
source = dcr-0.2.1.tar.gz::https://github.com/dexoron/dcr/archive/refs/tags/v0.2.1.tar.gz
|
||||
sha256sums = 30e334fa98cd51073c0fa84c80a982584b00156b57084311ad53419441ce6235
|
||||
|
||||
pkgname = dcr
|
||||
30
packaging/aur/dcr/PKGBUILD
Normal file
30
packaging/aur/dcr/PKGBUILD
Normal file
@@ -0,0 +1,30 @@
|
||||
pkgname=dcr
|
||||
pkgver=0.2.1
|
||||
pkgrel=3
|
||||
pkgdesc="Cargo-like utility to manage C/C++ projects"
|
||||
arch=('x86_64' 'aarch64')
|
||||
url="https://github.com/dexoron/dcr"
|
||||
license=('MIT')
|
||||
depends=('gcc-libs')
|
||||
makedepends=('cargo')
|
||||
options=('!lto')
|
||||
optdepends=(
|
||||
'gcc: build C/C++ projects with GCC'
|
||||
'clang: build C/C++ projects with Clang'
|
||||
)
|
||||
source=("$pkgname-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz")
|
||||
sha256sums=('30e334fa98cd51073c0fa84c80a982584b00156b57084311ad53419441ce6235')
|
||||
|
||||
build() {
|
||||
cd "$srcdir/$pkgname-$pkgver"
|
||||
export CARGO_PROFILE_RELEASE_LTO=false
|
||||
export RUSTFLAGS="${RUSTFLAGS:-}"
|
||||
export RUSTFLAGS="${RUSTFLAGS/-C link-arg=-fuse-ld=lld/}"
|
||||
cargo build --release --locked
|
||||
}
|
||||
|
||||
package() {
|
||||
cd "$srcdir/$pkgname-$pkgver"
|
||||
install -Dm755 "target/release/dcr" "$pkgdir/usr/bin/dcr"
|
||||
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
|
||||
}
|
||||
218
src/cli/build.rs
218
src/cli/build.rs
@@ -1,82 +1,186 @@
|
||||
use crate::config::{PROFILE, PROJECT_COMPILER, flags};
|
||||
use crate::config::{PROFILE, flags};
|
||||
use crate::core::builder::{BuildContext, build as build_project};
|
||||
use crate::core::config::Config;
|
||||
use crate::core::deps::resolve_deps;
|
||||
use crate::utils::fs::check_dir;
|
||||
use crate::utils::text::{BOLD, BRIGHT_GREEN, BRIGHT_RED, colored};
|
||||
use crate::utils::log::{error, warn};
|
||||
use crate::utils::text::{BOLD_GREEN, colored};
|
||||
use std::fs;
|
||||
use std::process::Command;
|
||||
use std::time::Instant;
|
||||
|
||||
pub fn build(args: &[String]) -> i32 {
|
||||
let mut active_profile = PROFILE.to_string();
|
||||
let red_bold = BRIGHT_RED.to_owned() + BOLD;
|
||||
let green_bold = BRIGHT_GREEN.to_owned() + BOLD;
|
||||
let project_name = std::env::current_dir()
|
||||
.ok()
|
||||
.and_then(|p| p.file_name().map(|v| v.to_string_lossy().to_string()))
|
||||
.unwrap_or_else(|| "project".to_string());
|
||||
|
||||
let items = check_dir(None).unwrap_or_default();
|
||||
if !items.contains(&"dcr.toml".to_string()) {
|
||||
println!("{}: не найден файл dcr.toml", colored("error", &red_bold));
|
||||
error("dcr.toml file not found");
|
||||
return 1;
|
||||
}
|
||||
|
||||
let config = match Config::open("./dcr.toml") {
|
||||
Ok(cfg) => cfg,
|
||||
Err(_) => {
|
||||
error("dcr.toml file not found");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
let active_profile = match parse_profile(args) {
|
||||
Ok(profile) => profile,
|
||||
Err(code) => return code,
|
||||
};
|
||||
let project_name = get_config_str(&config, "package.name");
|
||||
let project_compiler = get_config_str(&config, "build.compiler");
|
||||
let build_language = get_config_str(&config, "build.language");
|
||||
let build_standard = get_config_str(&config, "build.standard");
|
||||
let build_target = get_config_str(&config, "build.target");
|
||||
let build_kind = get_config_str(&config, "build.kind");
|
||||
let build_cflags = match get_config_list(&config, "build.cflags") {
|
||||
Ok(v) => v,
|
||||
Err(msg) => {
|
||||
error(&msg);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
let build_ldflags = match get_config_list(&config, "build.ldflags") {
|
||||
Ok(v) => v,
|
||||
Err(msg) => {
|
||||
error(&msg);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
println!(
|
||||
" Building project `{}`\n Profile: {}\n Compiler: {}\n",
|
||||
colored(&project_name, BOLD_GREEN),
|
||||
colored(&active_profile, BOLD_GREEN),
|
||||
colored(&project_compiler, BOLD_GREEN)
|
||||
);
|
||||
|
||||
ensure_target_dirs(&items, &active_profile, normalize_target(&build_target));
|
||||
|
||||
let project_root = match std::env::current_dir() {
|
||||
Ok(p) => p,
|
||||
Err(_) => {
|
||||
error("Failed to determine project root");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
let resolved = match resolve_deps(&config, &active_profile, &project_root) {
|
||||
Ok(r) => r,
|
||||
Err(msg) => {
|
||||
error(&msg);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
let ctx = BuildContext {
|
||||
profile: &active_profile,
|
||||
project_name: &project_name,
|
||||
compiler: &project_compiler,
|
||||
language: &build_language,
|
||||
standard: &build_standard,
|
||||
target_dir: normalize_target(&build_target),
|
||||
kind: normalize_kind(&build_kind),
|
||||
include_dirs: &resolved.include_dirs,
|
||||
lib_dirs: &resolved.lib_dirs,
|
||||
libs: &resolved.libs,
|
||||
cflags: &build_cflags,
|
||||
ldflags: &build_ldflags,
|
||||
};
|
||||
match run_build(&ctx) {
|
||||
Ok(times) => {
|
||||
println!(
|
||||
" {} Build completed successfully in {} seconds",
|
||||
colored("✔", BOLD_GREEN),
|
||||
colored(×.to_string(), BOLD_GREEN)
|
||||
);
|
||||
0
|
||||
}
|
||||
Err(msg) => {
|
||||
error(&msg);
|
||||
1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_profile(args: &[String]) -> Result<String, i32> {
|
||||
if let Some(first_arg) = args.first() {
|
||||
if first_arg.starts_with("--") {
|
||||
let candidate = first_arg.trim_start_matches("--");
|
||||
if flags(candidate).is_some() {
|
||||
active_profile = candidate.to_string();
|
||||
} else {
|
||||
println!("{}: неизвестный флаг сборки", colored("error", &red_bold));
|
||||
return 1;
|
||||
return Ok(candidate.to_string());
|
||||
}
|
||||
} else {
|
||||
println!("{}: неизвестный аргумент", colored("error", &red_bold));
|
||||
return 1;
|
||||
warn("Unknown build flag");
|
||||
return Err(1);
|
||||
}
|
||||
warn("Unknown argument");
|
||||
return Err(1);
|
||||
}
|
||||
Ok(PROFILE.to_string())
|
||||
}
|
||||
|
||||
println!(
|
||||
" Сборка проекта `{}`\n Профиль: {}\n Компилятор: {}\n",
|
||||
colored(&project_name, &green_bold),
|
||||
colored(&active_profile, &green_bold),
|
||||
colored(PROJECT_COMPILER, &green_bold)
|
||||
);
|
||||
fn get_config_str(config: &Config, key: &str) -> String {
|
||||
config
|
||||
.get(key)
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("")
|
||||
.to_string()
|
||||
}
|
||||
|
||||
fn get_config_list(config: &Config, key: &str) -> Result<Vec<String>, String> {
|
||||
let value = match config.get(key) {
|
||||
Some(v) => v,
|
||||
None => return Ok(Vec::new()),
|
||||
};
|
||||
let arr = value
|
||||
.as_array()
|
||||
.ok_or_else(|| format!("{key} must be an array of strings"))?;
|
||||
let mut out = Vec::new();
|
||||
for item in arr {
|
||||
let s = item
|
||||
.as_str()
|
||||
.ok_or_else(|| format!("{key} must be an array of strings"))?;
|
||||
out.push(s.to_string());
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
fn ensure_target_dirs(items: &[String], profile: &str, target_dir: Option<&str>) {
|
||||
if let Some(dir) = target_dir {
|
||||
let _ = fs::create_dir_all(dir);
|
||||
return;
|
||||
}
|
||||
if !items.contains(&"target".to_string()) {
|
||||
let _ = fs::create_dir("./target");
|
||||
}
|
||||
let target_items = check_dir(Some("target")).unwrap_or_default();
|
||||
if !target_items.contains(&active_profile) {
|
||||
let _ = fs::create_dir(format!("./target/{active_profile}"));
|
||||
if !target_items.contains(&profile.to_string()) {
|
||||
let _ = fs::create_dir(format!("./target/{profile}"));
|
||||
}
|
||||
|
||||
let src_items = check_dir(Some("src")).unwrap_or_default();
|
||||
if src_items.contains(&"main.c".to_string()) {
|
||||
let compile_flags = flags(&active_profile).unwrap_or(&[]);
|
||||
let start_time = Instant::now();
|
||||
let mut cmd = Command::new(PROJECT_COMPILER);
|
||||
cmd.arg("./src/main.c");
|
||||
for flag in compile_flags {
|
||||
cmd.arg(flag);
|
||||
}
|
||||
cmd.arg("-o").arg(format!("./target/{active_profile}/main"));
|
||||
|
||||
match cmd.status() {
|
||||
Ok(status) if status.success() => {
|
||||
let times = ((start_time.elapsed().as_secs_f64() * 100.0).trunc()) / 100.0;
|
||||
println!(
|
||||
" {} Сборка завершена успешно, за {} секунд",
|
||||
colored("✔", &green_bold),
|
||||
colored(×.to_string(), &green_bold)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
_ => {
|
||||
println!("{}: сборка не удалась", colored("error", &red_bold));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
fn run_build(ctx: &BuildContext) -> Result<f64, String> {
|
||||
let start_time = Instant::now();
|
||||
match build_project(ctx) {
|
||||
Ok(times) => {
|
||||
let times = if times == 0.0 {
|
||||
((start_time.elapsed().as_secs_f64() * 100.0).trunc()) / 100.0
|
||||
} else {
|
||||
times
|
||||
};
|
||||
Ok(times)
|
||||
}
|
||||
Err(_) => Err("Build failed".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize_target(target: &str) -> Option<&str> {
|
||||
let trimmed = target.trim();
|
||||
if trimmed.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(trimmed)
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize_kind(kind: &str) -> &str {
|
||||
let trimmed = kind.trim();
|
||||
if trimmed.is_empty() { "bin" } else { trimmed }
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
use crate::config::flags;
|
||||
use crate::utils::fs::check_dir;
|
||||
use crate::utils::text::{BOLD, BRIGHT_GREEN, BRIGHT_RED, BRIGHT_YELLOW, colored};
|
||||
use crate::utils::log::{error, warn};
|
||||
use crate::utils::text::{BOLD_GREEN, colored};
|
||||
use std::fs;
|
||||
|
||||
pub fn clean(args: &[String]) -> i32 {
|
||||
let red_bold = BRIGHT_RED.to_owned() + BOLD;
|
||||
let green_bold = BRIGHT_GREEN.to_owned() + BOLD;
|
||||
let yellow_bold = BRIGHT_YELLOW.to_owned() + BOLD;
|
||||
|
||||
let project_name = std::env::current_dir()
|
||||
.ok()
|
||||
.and_then(|p| p.file_name().map(|v| v.to_string_lossy().to_string()))
|
||||
@@ -15,23 +12,20 @@ pub fn clean(args: &[String]) -> i32 {
|
||||
let items = check_dir(None).unwrap_or_default();
|
||||
|
||||
if args.len() > 1 {
|
||||
println!("{}: неизвестный аргумент", colored("error", &red_bold));
|
||||
error("Unknown argument");
|
||||
return 1;
|
||||
}
|
||||
if !items.contains(&"dcr.toml".to_string()) {
|
||||
println!("{}: не найден файл dcr.toml", colored("error", &red_bold));
|
||||
error("dcr.toml file not found");
|
||||
return 1;
|
||||
}
|
||||
|
||||
println!(
|
||||
" Очистка проекта `{}`",
|
||||
colored(&project_name, &green_bold)
|
||||
" Cleaning project `{}`",
|
||||
colored(&project_name, BOLD_GREEN)
|
||||
);
|
||||
if !items.contains(&"target".to_string()) {
|
||||
println!(
|
||||
"{}: директория target не найдена",
|
||||
colored("warn", &yellow_bold)
|
||||
);
|
||||
warn("Directory target not found");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -41,32 +35,29 @@ pub fn clean(args: &[String]) -> i32 {
|
||||
profile = profile.trim_start_matches("--").to_string();
|
||||
}
|
||||
if flags(&profile).is_none() {
|
||||
println!("{}: неизвестный профиль", colored("error", &red_bold));
|
||||
error("Unknown profile");
|
||||
return 1;
|
||||
}
|
||||
|
||||
let target_items = check_dir(Some("target")).unwrap_or_default();
|
||||
if !target_items.contains(&profile) {
|
||||
println!(
|
||||
"{}: директория target/{profile} не найдена",
|
||||
colored("warn", &yellow_bold)
|
||||
);
|
||||
warn(&format!("Directory target/{profile} not found"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
println!(" Профиль: {}", colored(&profile, &green_bold));
|
||||
println!(" Profile: {}", colored(&profile, BOLD_GREEN));
|
||||
let _ = fs::remove_dir_all(format!("target/{profile}"));
|
||||
println!(
|
||||
"{} Удалена директория target/{profile}",
|
||||
colored("\n ✔", &green_bold)
|
||||
"{} Removed directory target/{profile}",
|
||||
colored("\n ✔", BOLD_GREEN)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
let _ = fs::remove_dir_all("target");
|
||||
println!(
|
||||
"{} Удалена директория target",
|
||||
colored("\n ✔", &green_bold)
|
||||
"{} Removed directory target",
|
||||
colored("\n ✔", BOLD_GREEN)
|
||||
);
|
||||
0
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use crate::utils::log::{error, warn};
|
||||
use reqwest::blocking::Client;
|
||||
use serde::Deserialize;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
const LATEST_RELEASE_URL: &str = "https://api.github.com/repos/dexoron/dcr/releases/latest";
|
||||
@@ -20,16 +22,32 @@ struct ReleaseAsset {
|
||||
|
||||
pub fn flag_update(args: &[String]) -> i32 {
|
||||
if !args.is_empty() {
|
||||
println!("Ошибка: команда не поддежривает аргументы");
|
||||
warn("Command does not support additional arguments");
|
||||
return 1;
|
||||
}
|
||||
|
||||
let current_exe = match std::env::current_exe() {
|
||||
Ok(path) => path,
|
||||
Err(_) => {
|
||||
error("Failed to resolve current binary path");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(package_name) = pacman_owned_package(¤t_exe) {
|
||||
warn("This dcr binary is managed by pacman/AUR");
|
||||
println!(
|
||||
"Update via package manager: yay/paru -Syu {package_name} or sudo pacman -Syu {package_name}"
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
let current_version = env!("CARGO_PKG_VERSION");
|
||||
let target = env!("DCR_TARGET");
|
||||
let client = match Client::builder().user_agent("dcr-updater").build() {
|
||||
Ok(client) => client,
|
||||
Err(_) => {
|
||||
println!("Ошибка: не удалось инициализировать HTTP клиент");
|
||||
error("Failed to initialize HTTP client");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
@@ -37,14 +55,14 @@ pub fn flag_update(args: &[String]) -> i32 {
|
||||
let release = match fetch_latest_release(&client) {
|
||||
Ok(release) => release,
|
||||
Err(err) => {
|
||||
println!("Ошибка: не удалось проверить обновления: {err}");
|
||||
error(&format!("Failed to check for updates: {err}"));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
let latest_version = release.tag_name.trim_start_matches('v');
|
||||
if latest_version == current_version {
|
||||
println!("Установлена последняя версия: {current_version}");
|
||||
println!("Latest version is already installed: {current_version}");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -54,41 +72,34 @@ pub fn flag_update(args: &[String]) -> i32 {
|
||||
.iter()
|
||||
.find(|asset| candidate_names.iter().any(|name| name == &asset.name))
|
||||
else {
|
||||
println!("Ошибка: не найден бинарник для таргета {target}");
|
||||
error(&format!("Binary for target {target} not found"));
|
||||
return 1;
|
||||
};
|
||||
|
||||
let bytes = match download_asset(&client, &asset.browser_download_url) {
|
||||
Ok(bytes) => bytes,
|
||||
Err(err) => {
|
||||
println!("Ошибка: не удалось скачать обновление: {err}");
|
||||
error(&format!("Failed to download update: {err}"));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
let current_exe = match std::env::current_exe() {
|
||||
Ok(path) => path,
|
||||
Err(_) => {
|
||||
println!("Ошибка: не удалось определить путь текущего бинарника");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
let temp_path = temp_binary_path(¤t_exe);
|
||||
|
||||
if fs::write(&temp_path, &bytes).is_err() {
|
||||
println!("Ошибка: не удалось записать временный бинарник");
|
||||
error("Failed to write temporary binary");
|
||||
return 1;
|
||||
}
|
||||
set_executable_permissions(&temp_path);
|
||||
|
||||
if self_replace::self_replace(&temp_path).is_err() {
|
||||
let _ = fs::remove_file(&temp_path);
|
||||
println!("Ошибка: не удалось заменить текущий бинарник");
|
||||
error("Failed to replace current binary");
|
||||
return 1;
|
||||
}
|
||||
|
||||
let _ = fs::remove_file(&temp_path);
|
||||
println!("Обновление завершено: {current_version} -> {latest_version}");
|
||||
println!("Update completed: {current_version} -> {latest_version}");
|
||||
0
|
||||
}
|
||||
|
||||
@@ -96,31 +107,31 @@ fn fetch_latest_release(client: &Client) -> Result<Release, String> {
|
||||
let response = client
|
||||
.get(LATEST_RELEASE_URL)
|
||||
.send()
|
||||
.map_err(|_| "запрос к GitHub API завершился ошибкой".to_string())?;
|
||||
.map_err(|_| "GitHub API request failed".to_string())?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
return Err(format!("GitHub API вернул статус {}", response.status()));
|
||||
return Err(format!("GitHub API returned status {}", response.status()));
|
||||
}
|
||||
|
||||
response
|
||||
.json::<Release>()
|
||||
.map_err(|_| "ответ GitHub API имеет неожиданный формат".to_string())
|
||||
.map_err(|_| "GitHub API response has an unexpected format".to_string())
|
||||
}
|
||||
|
||||
fn download_asset(client: &Client, url: &str) -> Result<Vec<u8>, String> {
|
||||
let response = client
|
||||
.get(url)
|
||||
.send()
|
||||
.map_err(|_| "запрос на скачивание завершился ошибкой".to_string())?;
|
||||
.map_err(|_| "Download request failed".to_string())?;
|
||||
|
||||
if !response.status().is_success() {
|
||||
return Err(format!("скачивание вернуло статус {}", response.status()));
|
||||
return Err(format!("Download returned status {}", response.status()));
|
||||
}
|
||||
|
||||
response
|
||||
.bytes()
|
||||
.map(|bytes| bytes.to_vec())
|
||||
.map_err(|_| "не удалось прочитать скачанные данные".to_string())
|
||||
.map_err(|_| "Failed to read downloaded data".to_string())
|
||||
}
|
||||
|
||||
fn asset_candidates(target: &str) -> Vec<String> {
|
||||
@@ -156,3 +167,23 @@ fn set_executable_permissions(path: &Path) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn pacman_owned_package(path: &Path) -> Option<String> {
|
||||
let output = Command::new("pacman").arg("-Qoq").arg(path).output().ok()?;
|
||||
if !output.status.success() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let package_name = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
||||
if package_name.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(package_name)
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn pacman_owned_package(_path: &Path) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -1,36 +1,33 @@
|
||||
use crate::utils::text::{BOLD, BRIGHT_CYAN, BRIGHT_GREEN, colored};
|
||||
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, printc};
|
||||
|
||||
pub fn help() -> i32 {
|
||||
let green_bold = BRIGHT_GREEN.to_owned() + BOLD;
|
||||
let cyan_bold = BRIGHT_CYAN.to_owned() + BOLD;
|
||||
|
||||
println!("DCR (Dexoron Cargo Realization)");
|
||||
println!("Менеджер C-проектов, вдохновленный Cargo.");
|
||||
println!("C project manager inspired by Cargo.");
|
||||
println!();
|
||||
println!("{}", colored("ИСПОЛЬЗОВАНИЕ:", &green_bold));
|
||||
println!("{}", colored(" dcr <команда> [опции]", &cyan_bold));
|
||||
printc("USAGE:", BOLD_GREEN);
|
||||
printc(" dcr <command> [options]", BOLD_CYAN);
|
||||
println!();
|
||||
println!("{}", colored("КОМАНДЫ:", &green_bold));
|
||||
println!(" new <name> Создать новый проект");
|
||||
println!(" init Инициализировать текущую директорию как проект");
|
||||
println!(" build [--profile] Собрать проект (по умолчанию: --debug)");
|
||||
println!(" run [--profile] Собрать и запустить (по умолчанию: --debug)");
|
||||
println!(" clean Удалить директорию target");
|
||||
println!("{}", colored("ФЛАГИ:", &green_bold));
|
||||
println!(" --help Показать справку по команде");
|
||||
println!(" --update Обновить dcr до актуальной версии");
|
||||
println!(" --version Показать версию dcr");
|
||||
printc("COMMANDS:", BOLD_GREEN);
|
||||
println!(" new <name> Create a new project");
|
||||
println!(" init Initialize the current directory as a project");
|
||||
println!(" build [--profile] Build the project (default: --debug)");
|
||||
println!(" run [--profile] Build and run the project (default: --debug)");
|
||||
println!(" clean Remove the target directory");
|
||||
printc("FLAGS:", BOLD_GREEN);
|
||||
println!(" --help Show command help");
|
||||
println!(" --update Update dcr to the latest version");
|
||||
println!(" --version Show dcr version");
|
||||
println!();
|
||||
println!("{}", colored("ОПЦИИ:", &green_bold));
|
||||
println!(" --debug Сборка с профилем debug");
|
||||
println!(" --release Сборка с профилем release");
|
||||
printc("OPTIONS:", BOLD_GREEN);
|
||||
println!(" --debug Build with debug profile");
|
||||
println!(" --release Build with release profile");
|
||||
println!();
|
||||
println!("{}", colored("ПРИМЕРЫ:", &green_bold));
|
||||
println!("{}", colored(" dcr new hello", &cyan_bold));
|
||||
println!("{}", colored(" dcr build --release", &cyan_bold));
|
||||
println!("{}", colored(" dcr run --debug", &cyan_bold));
|
||||
printc("EXAMPLES:", BOLD_GREEN);
|
||||
printc(" dcr new hello", BOLD_CYAN);
|
||||
printc(" dcr build --release", BOLD_CYAN);
|
||||
printc(" dcr run --debug", BOLD_CYAN);
|
||||
println!();
|
||||
println!("{}", colored("ПОДСКАЗКА:", &green_bold));
|
||||
println!(" Запусти 'dcr <команда> --help' для справки по команде.");
|
||||
printc("TIP:", BOLD_GREEN);
|
||||
println!(" Run 'dcr <command> --help' for command-specific help.");
|
||||
0
|
||||
}
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
use crate::config::{FILE_MAIN_C, file_dcr_toml};
|
||||
use crate::config::FILE_MAIN_C;
|
||||
use crate::core::config::Config;
|
||||
use crate::utils::fs::check_dir;
|
||||
use crate::utils::text::{BOLD, BRIGHT_CYAN, BRIGHT_GREEN, BRIGHT_RED, colored, printc};
|
||||
use crate::utils::log::{error, warn};
|
||||
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc};
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
use toml::Value;
|
||||
|
||||
pub fn init(args: &[String]) -> i32 {
|
||||
let red_bold = BRIGHT_RED.to_owned() + BOLD;
|
||||
let green_bold = BRIGHT_GREEN.to_owned() + BOLD;
|
||||
let cyan_bold = BRIGHT_CYAN.to_owned() + BOLD;
|
||||
|
||||
if !args.is_empty() {
|
||||
println!(
|
||||
"{}: команда не поддерживает доп. аргументы",
|
||||
colored("error", &red_bold)
|
||||
);
|
||||
warn("Command does not support additional arguments");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -24,73 +20,61 @@ pub fn init(args: &[String]) -> i32 {
|
||||
.unwrap_or_else(|| "project".to_string());
|
||||
|
||||
if !items.is_empty() {
|
||||
println!("{}: директория не пуста", colored("error", &red_bold));
|
||||
error("Directory not empty");
|
||||
return 1;
|
||||
}
|
||||
|
||||
let cwd = std::env::current_dir()
|
||||
.map(|v| v.to_string_lossy().to_string())
|
||||
.unwrap_or_else(|_| ".".to_string());
|
||||
println!("Инициализация проекта в {cwd}");
|
||||
println!("Initializing the project in {cwd}");
|
||||
|
||||
let mut dcr_toml = match fs::File::create("./dcr.toml") {
|
||||
Ok(file) => file,
|
||||
let mut config = match Config::new("./dcr.toml") {
|
||||
Ok(cfg) => cfg,
|
||||
Err(_) => {
|
||||
println!(
|
||||
"{}: не удалось создать dcr.toml",
|
||||
colored("error", &red_bold)
|
||||
);
|
||||
error("Failed to create dcr.toml");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
if dcr_toml
|
||||
.write_all(file_dcr_toml(&project_name).as_bytes())
|
||||
if config
|
||||
.edit("package.name", Value::String(project_name.clone()))
|
||||
.is_err()
|
||||
{
|
||||
println!(
|
||||
"{}: не удалось записать dcr.toml",
|
||||
colored("error", &red_bold)
|
||||
);
|
||||
error("Failed to write dcr.toml");
|
||||
return 1;
|
||||
}
|
||||
println!(
|
||||
" {} Создан файл {}",
|
||||
colored("✔", &green_bold),
|
||||
colored("dcr.toml", &cyan_bold)
|
||||
" {} Created file {}",
|
||||
colored("✔", BOLD_GREEN),
|
||||
colored("dcr.toml", BOLD_CYAN)
|
||||
);
|
||||
|
||||
if fs::create_dir("src").is_err() {
|
||||
println!("{}: не удалось создать src", colored("error", &red_bold));
|
||||
error("Failed to create src/");
|
||||
return 1;
|
||||
}
|
||||
let mut main_c = match fs::File::create("./src/main.c") {
|
||||
Ok(file) => file,
|
||||
Err(_) => {
|
||||
println!(
|
||||
"{}: не удалось создать src/main.c",
|
||||
colored("error", &red_bold)
|
||||
);
|
||||
error("Failed to create src/main.c");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
if main_c.write_all(FILE_MAIN_C.as_bytes()).is_err() {
|
||||
println!(
|
||||
"{}: не удалось записать src/main.c",
|
||||
colored("error", &red_bold)
|
||||
);
|
||||
error("Failed to write src/main.c");
|
||||
return 1;
|
||||
}
|
||||
println!(
|
||||
" {} Создан файл {}\n",
|
||||
colored("✔", &green_bold),
|
||||
colored("src/main.c", &cyan_bold)
|
||||
" {} Created file {}\n",
|
||||
colored("✔", BOLD_GREEN),
|
||||
colored("src/main.c", BOLD_CYAN)
|
||||
);
|
||||
|
||||
println!(
|
||||
"Проект `{}` успешно создан\n",
|
||||
colored(&project_name, &green_bold)
|
||||
"Project `{}` successfully created\n",
|
||||
colored(project_name.as_str(), BOLD_GREEN)
|
||||
);
|
||||
printc("Следуюший шаг:", &green_bold);
|
||||
printc(" dcr run", &cyan_bold);
|
||||
printc("Next step:", BOLD_GREEN);
|
||||
printc(" dcr run", BOLD_CYAN);
|
||||
0
|
||||
}
|
||||
|
||||
@@ -1,123 +1,101 @@
|
||||
use crate::config::{FILE_MAIN_C, file_dcr_toml};
|
||||
use crate::config::FILE_MAIN_C;
|
||||
use crate::core::config::Config;
|
||||
use crate::utils::fs::check_dir;
|
||||
use crate::utils::text::{BOLD, BRIGHT_CYAN, BRIGHT_GREEN, BRIGHT_RED, colored, printc};
|
||||
use crate::utils::log::{error, warn};
|
||||
use crate::utils::text::{BOLD_CYAN, BOLD_GREEN, colored, printc};
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
use toml::Value;
|
||||
|
||||
pub fn new(args: &[String]) -> i32 {
|
||||
let items = check_dir(None).unwrap_or_default();
|
||||
let red_bold = BRIGHT_RED.to_owned() + BOLD;
|
||||
let green_bold = BRIGHT_GREEN.to_owned() + BOLD;
|
||||
let cyan_bold = BRIGHT_CYAN.to_owned() + BOLD;
|
||||
|
||||
if args.is_empty() {
|
||||
println!(
|
||||
"{}: не указанно название проекта",
|
||||
colored("error", &red_bold)
|
||||
);
|
||||
error("Project name not specified");
|
||||
return 1;
|
||||
}
|
||||
if args.len() > 1 {
|
||||
println!(
|
||||
"{}: команда не поддерживает доп. аргументы",
|
||||
colored("error", &red_bold)
|
||||
);
|
||||
warn("Command does not support additional arguments");
|
||||
return 1;
|
||||
}
|
||||
|
||||
let project_name = &args[0];
|
||||
println!(
|
||||
"Создание проекта `{}`...",
|
||||
colored(project_name, &green_bold)
|
||||
"Creating a Project `{}`...",
|
||||
colored(project_name, BOLD_CYAN)
|
||||
);
|
||||
|
||||
if items.contains(project_name) {
|
||||
error(&format!(
|
||||
"Directory `{}` already exists\n",
|
||||
colored(project_name, BOLD_CYAN)
|
||||
));
|
||||
printc("Подсказка:", BOLD_CYAN);
|
||||
println!(
|
||||
"{}: директория `{}` уже существует\n",
|
||||
colored("error", &red_bold),
|
||||
colored(project_name, &green_bold)
|
||||
);
|
||||
printc("Подсказка:", &green_bold);
|
||||
println!(
|
||||
" Используй `{}` для инициализации существующего проекта\n или задай другое имя проекта",
|
||||
colored("dcr init", &cyan_bold)
|
||||
" Use `{}` to initialize an existing project\n or specify a different project name",
|
||||
colored("dcr init", BOLD_CYAN)
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if fs::create_dir(project_name).is_err() {
|
||||
println!(
|
||||
"{}: не удалось создать директорию",
|
||||
colored("error", &red_bold)
|
||||
);
|
||||
error("Failed to create directory");
|
||||
return 1;
|
||||
}
|
||||
println!(
|
||||
" {} Создана директория {}",
|
||||
colored("✔", &green_bold),
|
||||
" {} Directory created {}",
|
||||
colored("✔", BOLD_GREEN),
|
||||
project_name
|
||||
);
|
||||
|
||||
let toml_path = format!("./{project_name}/dcr.toml");
|
||||
let mut dcr_toml = match fs::File::create(&toml_path) {
|
||||
Ok(file) => file,
|
||||
let mut config = match Config::new(&toml_path) {
|
||||
Ok(cfg) => cfg,
|
||||
Err(_) => {
|
||||
println!(
|
||||
"{}: не удалось создать dcr.toml",
|
||||
colored("error", &red_bold)
|
||||
);
|
||||
error("Failed to create dcr.toml");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
if dcr_toml
|
||||
.write_all(file_dcr_toml(project_name).as_bytes())
|
||||
if config
|
||||
.edit("package.name", Value::String(project_name.to_string()))
|
||||
.is_err()
|
||||
{
|
||||
println!(
|
||||
"{}: не удалось записать dcr.toml",
|
||||
colored("error", &red_bold)
|
||||
);
|
||||
error("Failed to write dcr.toml");
|
||||
return 1;
|
||||
}
|
||||
println!(
|
||||
" {} Создан файл {}",
|
||||
colored("✔", &green_bold),
|
||||
colored("dcr.toml", &cyan_bold)
|
||||
" {} Created file {}",
|
||||
colored("✔", BOLD_GREEN),
|
||||
colored("dcr.toml", BOLD_CYAN)
|
||||
);
|
||||
|
||||
if fs::create_dir_all(format!("./{project_name}/src")).is_err() {
|
||||
println!("{}: не удалось создать src", colored("error", &red_bold));
|
||||
error("Failed to create src/");
|
||||
return 1;
|
||||
}
|
||||
let main_c_path = format!("./{project_name}/src/main.c");
|
||||
let mut main_c = match fs::File::create(&main_c_path) {
|
||||
Ok(file) => file,
|
||||
Err(_) => {
|
||||
println!(
|
||||
"{}: не удалось создать src/main.c",
|
||||
colored("error", &red_bold)
|
||||
);
|
||||
error("Failed to create src/main.c");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
if main_c.write_all(FILE_MAIN_C.as_bytes()).is_err() {
|
||||
println!(
|
||||
"{}: не удалось записать src/main.c",
|
||||
colored("error", &red_bold)
|
||||
);
|
||||
error("Failed to write src/main.c");
|
||||
return 1;
|
||||
}
|
||||
println!(
|
||||
" {} Создан файл {}\n",
|
||||
colored("✔", &green_bold),
|
||||
colored("src/main.c", &cyan_bold)
|
||||
" {} Created file {}\n",
|
||||
colored("✔", BOLD_GREEN),
|
||||
colored("src/main.c", BOLD_CYAN)
|
||||
);
|
||||
|
||||
println!(
|
||||
"Проект `{}` успешно создан\n",
|
||||
colored(project_name, &green_bold)
|
||||
"Project `{}` successfully created\n",
|
||||
colored(project_name, BOLD_GREEN)
|
||||
);
|
||||
printc("Следуюший шаг:", &green_bold);
|
||||
printc(&format!(" cd {project_name}\n dcr run"), &cyan_bold);
|
||||
printc("Next step:", BOLD_GREEN);
|
||||
printc(&format!(" cd {}\n dcr run", project_name), BOLD_CYAN);
|
||||
0
|
||||
}
|
||||
|
||||
@@ -1,55 +1,73 @@
|
||||
use crate::cli::build::build;
|
||||
use crate::config::{PROFILE, flags};
|
||||
use crate::core::config::Config;
|
||||
use crate::core::runner::run_binary;
|
||||
use crate::utils::fs::check_dir;
|
||||
use crate::utils::text::{BOLD, BRIGHT_RED, colored};
|
||||
use std::process::Command;
|
||||
use crate::utils::log::{error, warn};
|
||||
use crate::utils::text::{BOLD_GREEN, colored};
|
||||
|
||||
pub fn run(args: &[String]) -> i32 {
|
||||
let red_bold = BRIGHT_RED.to_owned() + BOLD;
|
||||
let mut active_profile = PROFILE.to_string();
|
||||
|
||||
let items = check_dir(None).unwrap_or_default();
|
||||
if !items.contains(&"dcr.toml".to_string()) {
|
||||
println!("{}: не найден файл dcr.toml", colored("error", &red_bold));
|
||||
error("dcr.toml file not found");
|
||||
return 1;
|
||||
}
|
||||
|
||||
let config = match Config::open("./dcr.toml") {
|
||||
Ok(cfg) => cfg,
|
||||
Err(_) => {
|
||||
error("dcr.toml file not found");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
let project_name: &str = config
|
||||
.get("package.name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("");
|
||||
let build_kind = config
|
||||
.get("build.kind")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("");
|
||||
let target_dir = config
|
||||
.get("build.target")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.trim())
|
||||
.filter(|s| !s.is_empty());
|
||||
|
||||
if let Some(first_arg) = args.first() {
|
||||
if first_arg.starts_with("--") {
|
||||
let candidate = first_arg.trim_start_matches("--");
|
||||
if flags(candidate).is_some() {
|
||||
active_profile = candidate.to_string();
|
||||
} else {
|
||||
println!("{}: неизвестный флаг сборки", colored("error", &red_bold));
|
||||
warn("Unknown build flag");
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
println!("{}: неизвестный аргумент", colored("error", &red_bold));
|
||||
warn("Unknown argument");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if build_kind.trim() == "staticlib" {
|
||||
error("Cannot run static library");
|
||||
return 1;
|
||||
}
|
||||
let build_status = build(args);
|
||||
let bin_path = crate::platform::bin_path(&active_profile, project_name, target_dir);
|
||||
if build_status == 0 {
|
||||
println!("\n Запуск target/{active_profile}/main");
|
||||
println!("\n {} {}", colored("Running", BOLD_GREEN), bin_path);
|
||||
println!("--------------------------------");
|
||||
return Command::new(format!("./target/{active_profile}/main"))
|
||||
.status()
|
||||
.map(|status| status.code().unwrap_or(1))
|
||||
.unwrap_or(1);
|
||||
return run_binary(project_name, &active_profile, target_dir);
|
||||
}
|
||||
|
||||
if check_dir(Some(&format!("target/{active_profile}")))
|
||||
.unwrap_or_default()
|
||||
.contains(&active_profile)
|
||||
{
|
||||
println!("Запуск последнего релиза");
|
||||
return Command::new(format!("./target/{active_profile}/main"))
|
||||
.status()
|
||||
.map(|status| status.code().unwrap_or(1))
|
||||
.unwrap_or(1);
|
||||
let fallback_code = run_binary(project_name, &active_profile, target_dir);
|
||||
if fallback_code != 1 {
|
||||
return fallback_code;
|
||||
}
|
||||
|
||||
println!("Исправьте ошибки в коде для запуска проекта");
|
||||
0
|
||||
error("Fix errors in the code to run the project");
|
||||
1
|
||||
}
|
||||
|
||||
@@ -1,24 +1,4 @@
|
||||
pub const PROJECT_VERSION: &str = "0.1.0";
|
||||
pub const PROJECT_LANGUAGE: &str = "c";
|
||||
pub const PROJECT_COMPILER: &str = "clang";
|
||||
pub const PROFILE: &str = "debug";
|
||||
|
||||
pub fn file_dcr_toml(project_name: &str) -> String {
|
||||
format!(
|
||||
r#"[package]
|
||||
name = "{project_name}"
|
||||
version = "{project_version}"
|
||||
language = "{project_language}"
|
||||
compiler = "{project_compiler}"
|
||||
|
||||
[dependencies]
|
||||
"#,
|
||||
project_version = PROJECT_VERSION,
|
||||
project_language = PROJECT_LANGUAGE,
|
||||
project_compiler = PROJECT_COMPILER
|
||||
)
|
||||
}
|
||||
|
||||
pub const FILE_MAIN_C: &str = r#"#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
183
src/core/builder/clang.rs
Normal file
183
src/core/builder/clang.rs
Normal file
@@ -0,0 +1,183 @@
|
||||
use crate::core::builder::BuildContext;
|
||||
use crate::platform;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use std::time::Instant;
|
||||
|
||||
pub fn build(ctx: &BuildContext) -> Result<f64, String> {
|
||||
let compiler = if ctx.compiler.is_empty() {
|
||||
"cc"
|
||||
} else {
|
||||
ctx.compiler
|
||||
};
|
||||
let start_time = Instant::now();
|
||||
let sources = collect_sources(ctx.language)?;
|
||||
let obj_dir = Path::new("./target").join(ctx.profile).join("obj");
|
||||
let objects = build_objects(compiler, &sources, &obj_dir, ctx, "o")?;
|
||||
|
||||
if ctx.kind == "staticlib" {
|
||||
let lib_path = platform::lib_path(ctx.profile, ctx.project_name, ctx.target_dir);
|
||||
let mut cmd = Command::new("ar");
|
||||
cmd.arg("rcs").arg(&lib_path);
|
||||
for obj in &objects {
|
||||
cmd.arg(obj);
|
||||
}
|
||||
match cmd.status() {
|
||||
Ok(status) if status.success() => {
|
||||
let elapsed = ((start_time.elapsed().as_secs_f64() * 100.0).trunc()) / 100.0;
|
||||
return Ok(elapsed);
|
||||
}
|
||||
Ok(_) => return Err("Build failed".to_string()),
|
||||
Err(err) => return Err(format!("Build failed: {err}")),
|
||||
}
|
||||
}
|
||||
|
||||
let mut cmd = Command::new(compiler);
|
||||
for obj in &objects {
|
||||
cmd.arg(obj);
|
||||
}
|
||||
for flag in default_flags(ctx.profile) {
|
||||
cmd.arg(flag);
|
||||
}
|
||||
for flag in ctx.cflags {
|
||||
cmd.arg(flag);
|
||||
}
|
||||
for dir in ctx.lib_dirs {
|
||||
cmd.arg(format!("-L{dir}"));
|
||||
}
|
||||
for lib in ctx.libs {
|
||||
cmd.arg(format!("-l{lib}"));
|
||||
}
|
||||
for flag in ctx.ldflags {
|
||||
cmd.arg(flag);
|
||||
}
|
||||
cmd.arg("-o").arg(platform::bin_path(
|
||||
ctx.profile,
|
||||
ctx.project_name,
|
||||
ctx.target_dir,
|
||||
));
|
||||
|
||||
match cmd.status() {
|
||||
Ok(status) if status.success() => {
|
||||
let elapsed = ((start_time.elapsed().as_secs_f64() * 100.0).trunc()) / 100.0;
|
||||
Ok(elapsed)
|
||||
}
|
||||
Ok(_) => Err("Build failed".to_string()),
|
||||
Err(err) => Err(format!("Build failed: {err}")),
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_sources(language: &str) -> Result<Vec<String>, String> {
|
||||
let lang = language.to_lowercase();
|
||||
let mut sources = Vec::new();
|
||||
collect_sources_rec("./src", &lang, &mut sources)?;
|
||||
sources.sort();
|
||||
if sources.is_empty() {
|
||||
return Err("No source files found in ./src".to_string());
|
||||
}
|
||||
Ok(sources)
|
||||
}
|
||||
|
||||
fn collect_sources_rec(dir: &str, lang: &str, out: &mut Vec<String>) -> Result<(), String> {
|
||||
let entries = fs::read_dir(dir).map_err(|err| format!("src dir error: {err}"))?;
|
||||
for entry in entries {
|
||||
let entry = entry.map_err(|err| format!("src dir error: {err}"))?;
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
collect_sources_rec(&path.to_string_lossy(), lang, out)?;
|
||||
continue;
|
||||
}
|
||||
if !path.is_file() {
|
||||
continue;
|
||||
}
|
||||
let ext = path
|
||||
.extension()
|
||||
.and_then(|v| v.to_str())
|
||||
.unwrap_or("")
|
||||
.to_lowercase();
|
||||
let file = path.to_string_lossy().to_string();
|
||||
let allowed = (lang == "c" && ext == "c")
|
||||
|| ((lang == "c++" || lang == "cpp" || lang == "cxx")
|
||||
&& (ext == "cpp" || ext == "cxx" || ext == "cc"));
|
||||
if allowed {
|
||||
out.push(file);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn default_flags(profile: &str) -> &'static [&'static str] {
|
||||
match profile {
|
||||
"release" => &["-O3", "-DNDEBUG", "-march=native"],
|
||||
"debug" => &[
|
||||
"-O0",
|
||||
"-g",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-fno-omit-frame-pointer",
|
||||
"-DDEBUG",
|
||||
],
|
||||
_ => &[],
|
||||
}
|
||||
}
|
||||
|
||||
fn build_objects(
|
||||
compiler: &str,
|
||||
sources: &[String],
|
||||
obj_dir: &Path,
|
||||
ctx: &BuildContext,
|
||||
obj_ext: &str,
|
||||
) -> Result<Vec<String>, String> {
|
||||
let mut objects = Vec::new();
|
||||
for source in sources {
|
||||
let obj_path = object_path(obj_dir, source, obj_ext);
|
||||
if let Some(parent) = Path::new(&obj_path).parent() {
|
||||
fs::create_dir_all(parent).map_err(|err| format!("obj dir error: {err}"))?;
|
||||
}
|
||||
if needs_rebuild(source, &obj_path) {
|
||||
let mut cmd = Command::new(compiler);
|
||||
cmd.arg("-c").arg(source).arg("-o").arg(&obj_path);
|
||||
if !ctx.standard.is_empty() {
|
||||
cmd.arg(format!("-std={}", ctx.standard));
|
||||
}
|
||||
for flag in default_flags(ctx.profile) {
|
||||
cmd.arg(flag);
|
||||
}
|
||||
for flag in ctx.cflags {
|
||||
cmd.arg(flag);
|
||||
}
|
||||
for dir in ctx.include_dirs {
|
||||
cmd.arg(format!("-I{dir}"));
|
||||
}
|
||||
match cmd.status() {
|
||||
Ok(status) if status.success() => {}
|
||||
Ok(_) => return Err("Build failed".to_string()),
|
||||
Err(err) => return Err(format!("Build failed: {err}")),
|
||||
}
|
||||
}
|
||||
objects.push(obj_path);
|
||||
}
|
||||
Ok(objects)
|
||||
}
|
||||
|
||||
fn object_path(obj_dir: &Path, source: &str, obj_ext: &str) -> String {
|
||||
let src_path = Path::new(source);
|
||||
let rel = src_path
|
||||
.strip_prefix("./src")
|
||||
.or_else(|_| src_path.strip_prefix("src"))
|
||||
.unwrap_or(src_path);
|
||||
let mut out = obj_dir.join(rel);
|
||||
out.set_extension(obj_ext.trim_start_matches('.'));
|
||||
out.to_string_lossy().to_string()
|
||||
}
|
||||
|
||||
fn needs_rebuild(source: &str, object: &str) -> bool {
|
||||
let src_time = fs::metadata(source).and_then(|m| m.modified());
|
||||
let obj_time = fs::metadata(object).and_then(|m| m.modified());
|
||||
match (src_time, obj_time) {
|
||||
(Ok(s), Ok(o)) => s > o,
|
||||
(Ok(_), Err(_)) => true,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
183
src/core/builder/gcc.rs
Normal file
183
src/core/builder/gcc.rs
Normal file
@@ -0,0 +1,183 @@
|
||||
use crate::core::builder::BuildContext;
|
||||
use crate::platform;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use std::time::Instant;
|
||||
|
||||
pub fn build(ctx: &BuildContext) -> Result<f64, String> {
|
||||
let compiler = if ctx.compiler.is_empty() {
|
||||
"cc"
|
||||
} else {
|
||||
ctx.compiler
|
||||
};
|
||||
let start_time = Instant::now();
|
||||
let sources = collect_sources(ctx.language)?;
|
||||
let obj_dir = Path::new("./target").join(ctx.profile).join("obj");
|
||||
let objects = build_objects(compiler, &sources, &obj_dir, ctx, "o")?;
|
||||
|
||||
if ctx.kind == "staticlib" {
|
||||
let lib_path = platform::lib_path(ctx.profile, ctx.project_name, ctx.target_dir);
|
||||
let mut cmd = Command::new("ar");
|
||||
cmd.arg("rcs").arg(&lib_path);
|
||||
for obj in &objects {
|
||||
cmd.arg(obj);
|
||||
}
|
||||
match cmd.status() {
|
||||
Ok(status) if status.success() => {
|
||||
let elapsed = ((start_time.elapsed().as_secs_f64() * 100.0).trunc()) / 100.0;
|
||||
return Ok(elapsed);
|
||||
}
|
||||
Ok(_) => return Err("Build failed".to_string()),
|
||||
Err(err) => return Err(format!("Build failed: {err}")),
|
||||
}
|
||||
}
|
||||
|
||||
let mut cmd = Command::new(compiler);
|
||||
for obj in &objects {
|
||||
cmd.arg(obj);
|
||||
}
|
||||
for flag in default_flags(ctx.profile) {
|
||||
cmd.arg(flag);
|
||||
}
|
||||
for flag in ctx.cflags {
|
||||
cmd.arg(flag);
|
||||
}
|
||||
for dir in ctx.lib_dirs {
|
||||
cmd.arg(format!("-L{dir}"));
|
||||
}
|
||||
for lib in ctx.libs {
|
||||
cmd.arg(format!("-l{lib}"));
|
||||
}
|
||||
for flag in ctx.ldflags {
|
||||
cmd.arg(flag);
|
||||
}
|
||||
cmd.arg("-o").arg(platform::bin_path(
|
||||
ctx.profile,
|
||||
ctx.project_name,
|
||||
ctx.target_dir,
|
||||
));
|
||||
|
||||
match cmd.status() {
|
||||
Ok(status) if status.success() => {
|
||||
let elapsed = ((start_time.elapsed().as_secs_f64() * 100.0).trunc()) / 100.0;
|
||||
Ok(elapsed)
|
||||
}
|
||||
Ok(_) => Err("Build failed".to_string()),
|
||||
Err(err) => Err(format!("Build failed: {err}")),
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_sources(language: &str) -> Result<Vec<String>, String> {
|
||||
let lang = language.to_lowercase();
|
||||
let mut sources = Vec::new();
|
||||
collect_sources_rec("./src", &lang, &mut sources)?;
|
||||
sources.sort();
|
||||
if sources.is_empty() {
|
||||
return Err("No source files found in ./src".to_string());
|
||||
}
|
||||
Ok(sources)
|
||||
}
|
||||
|
||||
fn collect_sources_rec(dir: &str, lang: &str, out: &mut Vec<String>) -> Result<(), String> {
|
||||
let entries = fs::read_dir(dir).map_err(|err| format!("src dir error: {err}"))?;
|
||||
for entry in entries {
|
||||
let entry = entry.map_err(|err| format!("src dir error: {err}"))?;
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
collect_sources_rec(&path.to_string_lossy(), lang, out)?;
|
||||
continue;
|
||||
}
|
||||
if !path.is_file() {
|
||||
continue;
|
||||
}
|
||||
let ext = path
|
||||
.extension()
|
||||
.and_then(|v| v.to_str())
|
||||
.unwrap_or("")
|
||||
.to_lowercase();
|
||||
let file = path.to_string_lossy().to_string();
|
||||
let allowed = (lang == "c" && ext == "c")
|
||||
|| ((lang == "c++" || lang == "cpp" || lang == "cxx")
|
||||
&& (ext == "cpp" || ext == "cxx" || ext == "cc"));
|
||||
if allowed {
|
||||
out.push(file);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn default_flags(profile: &str) -> &'static [&'static str] {
|
||||
match profile {
|
||||
"release" => &["-O3", "-DNDEBUG", "-march=native"],
|
||||
"debug" => &[
|
||||
"-O0",
|
||||
"-g",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-fno-omit-frame-pointer",
|
||||
"-DDEBUG",
|
||||
],
|
||||
_ => &[],
|
||||
}
|
||||
}
|
||||
|
||||
fn build_objects(
|
||||
compiler: &str,
|
||||
sources: &[String],
|
||||
obj_dir: &Path,
|
||||
ctx: &BuildContext,
|
||||
obj_ext: &str,
|
||||
) -> Result<Vec<String>, String> {
|
||||
let mut objects = Vec::new();
|
||||
for source in sources {
|
||||
let obj_path = object_path(obj_dir, source, obj_ext);
|
||||
if let Some(parent) = Path::new(&obj_path).parent() {
|
||||
fs::create_dir_all(parent).map_err(|err| format!("obj dir error: {err}"))?;
|
||||
}
|
||||
if needs_rebuild(source, &obj_path) {
|
||||
let mut cmd = Command::new(compiler);
|
||||
cmd.arg("-c").arg(source).arg("-o").arg(&obj_path);
|
||||
if !ctx.standard.is_empty() {
|
||||
cmd.arg(format!("-std={}", ctx.standard));
|
||||
}
|
||||
for flag in default_flags(ctx.profile) {
|
||||
cmd.arg(flag);
|
||||
}
|
||||
for flag in ctx.cflags {
|
||||
cmd.arg(flag);
|
||||
}
|
||||
for dir in ctx.include_dirs {
|
||||
cmd.arg(format!("-I{dir}"));
|
||||
}
|
||||
match cmd.status() {
|
||||
Ok(status) if status.success() => {}
|
||||
Ok(_) => return Err("Build failed".to_string()),
|
||||
Err(err) => return Err(format!("Build failed: {err}")),
|
||||
}
|
||||
}
|
||||
objects.push(obj_path);
|
||||
}
|
||||
Ok(objects)
|
||||
}
|
||||
|
||||
fn object_path(obj_dir: &Path, source: &str, obj_ext: &str) -> String {
|
||||
let src_path = Path::new(source);
|
||||
let rel = src_path
|
||||
.strip_prefix("./src")
|
||||
.or_else(|_| src_path.strip_prefix("src"))
|
||||
.unwrap_or(src_path);
|
||||
let mut out = obj_dir.join(rel);
|
||||
out.set_extension(obj_ext.trim_start_matches('.'));
|
||||
out.to_string_lossy().to_string()
|
||||
}
|
||||
|
||||
fn needs_rebuild(source: &str, object: &str) -> bool {
|
||||
let src_time = fs::metadata(source).and_then(|m| m.modified());
|
||||
let obj_time = fs::metadata(object).and_then(|m| m.modified());
|
||||
match (src_time, obj_time) {
|
||||
(Ok(s), Ok(o)) => s > o,
|
||||
(Ok(_), Err(_)) => true,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
35
src/core/builder/mod.rs
Normal file
35
src/core/builder/mod.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
pub mod clang;
|
||||
pub mod gcc;
|
||||
pub mod msvc;
|
||||
|
||||
pub struct BuildContext<'a> {
|
||||
pub profile: &'a str,
|
||||
pub project_name: &'a str,
|
||||
pub compiler: &'a str,
|
||||
pub language: &'a str,
|
||||
pub standard: &'a str,
|
||||
pub target_dir: Option<&'a str>,
|
||||
pub kind: &'a str,
|
||||
pub include_dirs: &'a [String],
|
||||
pub lib_dirs: &'a [String],
|
||||
pub libs: &'a [String],
|
||||
pub cflags: &'a [String],
|
||||
pub ldflags: &'a [String],
|
||||
}
|
||||
|
||||
pub fn build(ctx: &BuildContext) -> Result<f64, String> {
|
||||
let compiler = ctx.compiler.to_lowercase();
|
||||
if compiler.contains("clang-cl") {
|
||||
return msvc::build(ctx);
|
||||
}
|
||||
if compiler.contains("gcc") || compiler.contains("g++") {
|
||||
return gcc::build(ctx);
|
||||
}
|
||||
if compiler.contains("clang") || compiler.contains("clang++") {
|
||||
return clang::build(ctx);
|
||||
}
|
||||
if compiler == "cl" || compiler.contains("msvc") {
|
||||
return msvc::build(ctx);
|
||||
}
|
||||
clang::build(ctx)
|
||||
}
|
||||
236
src/core/builder/msvc.rs
Normal file
236
src/core/builder/msvc.rs
Normal file
@@ -0,0 +1,236 @@
|
||||
use crate::core::builder::BuildContext;
|
||||
use crate::platform;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use std::time::Instant;
|
||||
|
||||
pub fn build(ctx: &BuildContext) -> Result<f64, String> {
|
||||
let compiler = if ctx.compiler.is_empty() {
|
||||
"cl"
|
||||
} else {
|
||||
ctx.compiler
|
||||
};
|
||||
let start_time = Instant::now();
|
||||
let sources = collect_sources(ctx.language)?;
|
||||
let obj_dir = Path::new("./target").join(ctx.profile).join("obj");
|
||||
let objects = build_objects(compiler, &sources, &obj_dir, ctx, "obj")?;
|
||||
|
||||
if ctx.kind == "staticlib" {
|
||||
let lib_path = platform::lib_path(ctx.profile, ctx.project_name, ctx.target_dir);
|
||||
let mut cmd = Command::new("lib");
|
||||
cmd.arg("/nologo").arg(format!("/OUT:{lib_path}"));
|
||||
for obj in &objects {
|
||||
cmd.arg(obj);
|
||||
}
|
||||
match cmd.status() {
|
||||
Ok(status) if status.success() => {
|
||||
let elapsed = ((start_time.elapsed().as_secs_f64() * 100.0).trunc()) / 100.0;
|
||||
return Ok(elapsed);
|
||||
}
|
||||
Ok(_) => return Err("Build failed".to_string()),
|
||||
Err(err) => return Err(format!("Build failed: {err}")),
|
||||
}
|
||||
}
|
||||
|
||||
let mut cmd = Command::new(compiler);
|
||||
cmd.arg("/nologo");
|
||||
match ctx.language.to_lowercase().as_str() {
|
||||
"c" => {
|
||||
cmd.arg("/TC");
|
||||
}
|
||||
"c++" | "cpp" | "cxx" => {
|
||||
cmd.arg("/TP");
|
||||
}
|
||||
_ => {
|
||||
return Err("Unsupported language".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
if !ctx.standard.is_empty() {
|
||||
let std_flag = msvc_standard_flag(ctx.language, ctx.standard)?;
|
||||
cmd.arg(std_flag);
|
||||
}
|
||||
|
||||
for obj in &objects {
|
||||
cmd.arg(obj);
|
||||
}
|
||||
for flag in default_flags(ctx.profile) {
|
||||
cmd.arg(flag);
|
||||
}
|
||||
for flag in ctx.cflags {
|
||||
cmd.arg(flag);
|
||||
}
|
||||
for dir in ctx.lib_dirs {
|
||||
cmd.arg(format!("/LIBPATH:{dir}"));
|
||||
}
|
||||
for lib in ctx.libs {
|
||||
if lib.to_lowercase().ends_with(".lib") {
|
||||
cmd.arg(lib);
|
||||
} else {
|
||||
cmd.arg(format!("{lib}.lib"));
|
||||
}
|
||||
}
|
||||
if !ctx.ldflags.is_empty() {
|
||||
cmd.arg("/link");
|
||||
for flag in ctx.ldflags {
|
||||
cmd.arg(flag);
|
||||
}
|
||||
}
|
||||
cmd.arg(format!(
|
||||
"/Fe:{}",
|
||||
platform::bin_path(ctx.profile, ctx.project_name, ctx.target_dir)
|
||||
));
|
||||
|
||||
match cmd.status() {
|
||||
Ok(status) if status.success() => {
|
||||
let elapsed = ((start_time.elapsed().as_secs_f64() * 100.0).trunc()) / 100.0;
|
||||
Ok(elapsed)
|
||||
}
|
||||
Ok(_) => Err("Build failed".to_string()),
|
||||
Err(err) => Err(format!("Build failed: {err}")),
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_sources(language: &str) -> Result<Vec<String>, String> {
|
||||
let lang = language.to_lowercase();
|
||||
let mut sources = Vec::new();
|
||||
collect_sources_rec("./src", &lang, &mut sources)?;
|
||||
sources.sort();
|
||||
if sources.is_empty() {
|
||||
return Err("No source files found in ./src".to_string());
|
||||
}
|
||||
Ok(sources)
|
||||
}
|
||||
|
||||
fn collect_sources_rec(dir: &str, lang: &str, out: &mut Vec<String>) -> Result<(), String> {
|
||||
let entries = fs::read_dir(dir).map_err(|err| format!("src dir error: {err}"))?;
|
||||
for entry in entries {
|
||||
let entry = entry.map_err(|err| format!("src dir error: {err}"))?;
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
collect_sources_rec(&path.to_string_lossy(), lang, out)?;
|
||||
continue;
|
||||
}
|
||||
if !path.is_file() {
|
||||
continue;
|
||||
}
|
||||
let ext = path
|
||||
.extension()
|
||||
.and_then(|v| v.to_str())
|
||||
.unwrap_or("")
|
||||
.to_lowercase();
|
||||
let file = path.to_string_lossy().to_string();
|
||||
let allowed = (lang == "c" && ext == "c")
|
||||
|| ((lang == "c++" || lang == "cpp" || lang == "cxx")
|
||||
&& (ext == "cpp" || ext == "cxx" || ext == "cc"));
|
||||
if allowed {
|
||||
out.push(file);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn msvc_standard_flag(language: &str, standard: &str) -> Result<String, String> {
|
||||
let lang = language.to_lowercase();
|
||||
let std = standard.to_lowercase();
|
||||
if lang == "c" {
|
||||
return match std.as_str() {
|
||||
"c11" => Ok("/std:c11".to_string()),
|
||||
"c17" => Ok("/std:c17".to_string()),
|
||||
_ => Err("Unsupported C standard for MSVC".to_string()),
|
||||
};
|
||||
}
|
||||
if lang == "c++" || lang == "cpp" || lang == "cxx" {
|
||||
return match std.as_str() {
|
||||
"c++11" => Ok("/std:c++11".to_string()),
|
||||
"c++14" => Ok("/std:c++14".to_string()),
|
||||
"c++17" => Ok("/std:c++17".to_string()),
|
||||
"c++20" => Ok("/std:c++20".to_string()),
|
||||
"c++23" => Ok("/std:c++latest".to_string()),
|
||||
_ => Err("Unsupported C++ standard for MSVC".to_string()),
|
||||
};
|
||||
}
|
||||
Err("Unsupported language".to_string())
|
||||
}
|
||||
|
||||
fn default_flags(profile: &str) -> &'static [&'static str] {
|
||||
match profile {
|
||||
"release" => &["/O2", "/DNDEBUG"],
|
||||
"debug" => &["/Od", "/Zi", "/W4", "/DDEBUG", "/Oy-"],
|
||||
_ => &[],
|
||||
}
|
||||
}
|
||||
|
||||
fn build_objects(
|
||||
compiler: &str,
|
||||
sources: &[String],
|
||||
obj_dir: &Path,
|
||||
ctx: &BuildContext,
|
||||
obj_ext: &str,
|
||||
) -> Result<Vec<String>, String> {
|
||||
let mut objects = Vec::new();
|
||||
for source in sources {
|
||||
let obj_path = object_path(obj_dir, source, obj_ext);
|
||||
if let Some(parent) = Path::new(&obj_path).parent() {
|
||||
fs::create_dir_all(parent).map_err(|err| format!("obj dir error: {err}"))?;
|
||||
}
|
||||
if needs_rebuild(source, &obj_path) {
|
||||
let mut cmd = Command::new(compiler);
|
||||
cmd.arg("/nologo");
|
||||
match ctx.language.to_lowercase().as_str() {
|
||||
"c" => {
|
||||
cmd.arg("/TC");
|
||||
}
|
||||
"c++" | "cpp" | "cxx" => {
|
||||
cmd.arg("/TP");
|
||||
}
|
||||
_ => {
|
||||
return Err("Unsupported language".to_string());
|
||||
}
|
||||
}
|
||||
if !ctx.standard.is_empty() {
|
||||
let std_flag = msvc_standard_flag(ctx.language, ctx.standard)?;
|
||||
cmd.arg(std_flag);
|
||||
}
|
||||
for flag in default_flags(ctx.profile) {
|
||||
cmd.arg(flag);
|
||||
}
|
||||
for flag in ctx.cflags {
|
||||
cmd.arg(flag);
|
||||
}
|
||||
for dir in ctx.include_dirs {
|
||||
cmd.arg(format!("/I{dir}"));
|
||||
}
|
||||
cmd.arg("/c").arg(source).arg(format!("/Fo:{}", obj_path));
|
||||
match cmd.status() {
|
||||
Ok(status) if status.success() => {}
|
||||
Ok(_) => return Err("Build failed".to_string()),
|
||||
Err(err) => return Err(format!("Build failed: {err}")),
|
||||
}
|
||||
}
|
||||
objects.push(obj_path);
|
||||
}
|
||||
Ok(objects)
|
||||
}
|
||||
|
||||
fn object_path(obj_dir: &Path, source: &str, obj_ext: &str) -> String {
|
||||
let src_path = Path::new(source);
|
||||
let rel = src_path
|
||||
.strip_prefix("./src")
|
||||
.or_else(|_| src_path.strip_prefix("src"))
|
||||
.unwrap_or(src_path);
|
||||
let mut out = obj_dir.join(rel);
|
||||
out.set_extension(obj_ext.trim_start_matches('.'));
|
||||
out.to_string_lossy().to_string()
|
||||
}
|
||||
|
||||
fn needs_rebuild(source: &str, object: &str) -> bool {
|
||||
let src_time = fs::metadata(source).and_then(|m| m.modified());
|
||||
let obj_time = fs::metadata(object).and_then(|m| m.modified());
|
||||
match (src_time, obj_time) {
|
||||
(Ok(s), Ok(o)) => s > o,
|
||||
(Ok(_), Err(_)) => true,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
325
src/core/config.rs
Normal file
325
src/core/config.rs
Normal file
@@ -0,0 +1,325 @@
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use toml::Value;
|
||||
use toml::map::Map;
|
||||
|
||||
const DEFAULT_VERSION: &str = "0.1.0";
|
||||
const DEFAULT_LANGUAGE: &str = "c";
|
||||
const DEFAULT_STANDARD: &str = "c11";
|
||||
const DEFAULT_COMPILER: &str = "clang";
|
||||
const DEFAULT_KIND: &str = "bin";
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ConfigError {
|
||||
Io(std::io::Error),
|
||||
TomlDe(toml::de::Error),
|
||||
TomlSer(toml::ser::Error),
|
||||
Invalid(String),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for ConfigError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
ConfigError::Io(err) => write!(f, "I/O error: {err}"),
|
||||
ConfigError::TomlDe(err) => write!(f, "TOML parse error: {err}"),
|
||||
ConfigError::TomlSer(err) => write!(f, "TOML serialize error: {err}"),
|
||||
ConfigError::Invalid(msg) => write!(f, "Invalid config: {msg}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for ConfigError {}
|
||||
|
||||
impl From<std::io::Error> for ConfigError {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
ConfigError::Io(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<toml::de::Error> for ConfigError {
|
||||
fn from(err: toml::de::Error) -> Self {
|
||||
ConfigError::TomlDe(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<toml::ser::Error> for ConfigError {
|
||||
fn from(err: toml::ser::Error) -> Self {
|
||||
ConfigError::TomlSer(err)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Config {
|
||||
path: PathBuf,
|
||||
data: Value,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new(path: &str) -> Result<Self, ConfigError> {
|
||||
let path = PathBuf::from(path);
|
||||
let data = if path.exists() {
|
||||
read_toml(&path)?
|
||||
} else {
|
||||
let default_value = default_toml()?;
|
||||
write_toml(&path, &default_value)?;
|
||||
default_value
|
||||
};
|
||||
let cfg = Self { path, data };
|
||||
cfg.validate()?;
|
||||
Ok(cfg)
|
||||
}
|
||||
|
||||
pub fn open(path: &str) -> Result<Self, ConfigError> {
|
||||
let path = PathBuf::from(path);
|
||||
if !path.exists() {
|
||||
return Err(ConfigError::Invalid("dcr.toml not found".into()));
|
||||
}
|
||||
let data = read_toml(&path)?;
|
||||
let cfg = Self { path, data };
|
||||
cfg.validate()?;
|
||||
Ok(cfg)
|
||||
}
|
||||
|
||||
pub fn get(&self, key: &str) -> Option<&Value> {
|
||||
let parts: Vec<&str> = key.split('.').collect();
|
||||
get_path(&self.data, &parts)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn add(&mut self, key: &str, value: Value) -> Result<(), ConfigError> {
|
||||
self.set(key, value)
|
||||
}
|
||||
|
||||
pub fn edit(&mut self, key: &str, value: Value) -> Result<(), ConfigError> {
|
||||
self.set(key, value)
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub fn check(&self) -> bool {
|
||||
self.validate().is_ok()
|
||||
}
|
||||
|
||||
pub fn validate(&self) -> Result<(), ConfigError> {
|
||||
let package = self
|
||||
.get("package")
|
||||
.and_then(|v| v.as_table())
|
||||
.ok_or_else(|| ConfigError::Invalid("missing [package]".into()))?;
|
||||
|
||||
for key in ["name", "version"] {
|
||||
let value = package.get(key).and_then(|v| v.as_str()).unwrap_or("");
|
||||
if value.trim().is_empty() {
|
||||
return Err(ConfigError::Invalid(format!("package.{key} is empty")));
|
||||
}
|
||||
}
|
||||
|
||||
let build = self
|
||||
.get("build")
|
||||
.and_then(|v| v.as_table())
|
||||
.ok_or_else(|| ConfigError::Invalid("missing [build]".into()))?;
|
||||
|
||||
for key in ["language", "standard", "compiler", "kind"] {
|
||||
let value = build.get(key).and_then(|v| v.as_str()).unwrap_or("");
|
||||
if value.trim().is_empty() {
|
||||
return Err(ConfigError::Invalid(format!("build.{key} is empty")));
|
||||
}
|
||||
}
|
||||
if let Some(kind) = build.get("kind").and_then(|v| v.as_str()) {
|
||||
let kind = kind.trim();
|
||||
if kind != "bin" && kind != "staticlib" {
|
||||
return Err(ConfigError::Invalid("build.kind is invalid".into()));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn save(&self) -> Result<(), ConfigError> {
|
||||
write_toml(&self.path, &self.data)
|
||||
}
|
||||
|
||||
fn set(&mut self, key: &str, value: Value) -> Result<(), ConfigError> {
|
||||
let parts: Vec<&str> = key.split('.').collect();
|
||||
set_path(&mut self.data, &parts, value)?;
|
||||
self.save()?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn read_toml(path: &Path) -> Result<Value, ConfigError> {
|
||||
let content = fs::read_to_string(path)?;
|
||||
Ok(toml::from_str(&content)?)
|
||||
}
|
||||
|
||||
fn write_toml(path: &Path, value: &Value) -> Result<(), ConfigError> {
|
||||
let content = format_toml(value)?;
|
||||
fs::write(path, content)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn default_toml() -> Result<Value, ConfigError> {
|
||||
let name = std::env::current_dir()
|
||||
.ok()
|
||||
.and_then(|p| p.file_name().map(|v| v.to_string_lossy().to_string()))
|
||||
.unwrap_or_else(|| "project".to_string());
|
||||
|
||||
let mut package = Map::new();
|
||||
package.insert("name".to_string(), Value::String(name));
|
||||
package.insert(
|
||||
"version".to_string(),
|
||||
Value::String(DEFAULT_VERSION.to_string()),
|
||||
);
|
||||
let mut build = Map::new();
|
||||
build.insert(
|
||||
"language".to_string(),
|
||||
Value::String(DEFAULT_LANGUAGE.to_string()),
|
||||
);
|
||||
build.insert(
|
||||
"standard".to_string(),
|
||||
Value::String(DEFAULT_STANDARD.to_string()),
|
||||
);
|
||||
build.insert(
|
||||
"compiler".to_string(),
|
||||
Value::String(DEFAULT_COMPILER.to_string()),
|
||||
);
|
||||
build.insert("kind".to_string(), Value::String(DEFAULT_KIND.to_string()));
|
||||
|
||||
let mut root = Map::new();
|
||||
root.insert("package".to_string(), Value::Table(package));
|
||||
root.insert("build".to_string(), Value::Table(build));
|
||||
root.insert("dependencies".to_string(), Value::Table(Map::new()));
|
||||
|
||||
Ok(Value::Table(root))
|
||||
}
|
||||
|
||||
fn format_toml(value: &Value) -> Result<String, ConfigError> {
|
||||
let root = value
|
||||
.as_table()
|
||||
.ok_or_else(|| ConfigError::Invalid("root is not a table".into()))?;
|
||||
|
||||
let package = root
|
||||
.get("package")
|
||||
.and_then(|v| v.as_table())
|
||||
.ok_or_else(|| ConfigError::Invalid("missing [package]".into()))?;
|
||||
let build = root
|
||||
.get("build")
|
||||
.and_then(|v| v.as_table())
|
||||
.ok_or_else(|| ConfigError::Invalid("missing [build]".into()))?;
|
||||
let deps = root
|
||||
.get("dependencies")
|
||||
.and_then(|v| v.as_table())
|
||||
.ok_or_else(|| ConfigError::Invalid("missing [dependencies]".into()))?;
|
||||
|
||||
let name = package.get("name").and_then(|v| v.as_str()).unwrap_or("");
|
||||
let version = package
|
||||
.get("version")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("");
|
||||
|
||||
let language = build.get("language").and_then(|v| v.as_str()).unwrap_or("");
|
||||
let standard = build.get("standard").and_then(|v| v.as_str()).unwrap_or("");
|
||||
let compiler = build.get("compiler").and_then(|v| v.as_str()).unwrap_or("");
|
||||
|
||||
let mut out = String::new();
|
||||
out.push_str("[package]\n");
|
||||
out.push_str(&format!("name = \"{name}\"\n"));
|
||||
out.push_str(&format!("version = \"{version}\"\n\n"));
|
||||
|
||||
out.push_str("[build]\n");
|
||||
out.push_str(&format!("language = \"{language}\"\n"));
|
||||
out.push_str(&format!("standard = \"{standard}\"\n"));
|
||||
out.push_str(&format!("compiler = \"{compiler}\"\n"));
|
||||
let kind = build
|
||||
.get("kind")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or(DEFAULT_KIND);
|
||||
out.push_str(&format!("kind = \"{kind}\"\n"));
|
||||
if let Some(target) = build.get("target").and_then(|v| v.as_str())
|
||||
&& !target.trim().is_empty()
|
||||
{
|
||||
out.push_str(&format!("target = \"{target}\"\n"));
|
||||
}
|
||||
if let Some(cflags) = build.get("cflags") {
|
||||
out.push_str(&format!("cflags = {}\n", format_string_array(cflags)));
|
||||
}
|
||||
if let Some(ldflags) = build.get("ldflags") {
|
||||
out.push_str(&format!("ldflags = {}\n", format_string_array(ldflags)));
|
||||
}
|
||||
out.push('\n');
|
||||
|
||||
out.push_str("[dependencies]\n");
|
||||
if !deps.is_empty() {
|
||||
let mut keys: Vec<&String> = deps.keys().collect();
|
||||
keys.sort();
|
||||
for key in keys {
|
||||
if let Some(val) = deps.get(key) {
|
||||
out.push_str(&format!("{key} = {}\n", format_dep_value(val)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
fn format_dep_value(value: &Value) -> String {
|
||||
match value {
|
||||
Value::String(s) => format!("\"{s}\""),
|
||||
Value::Table(tbl) => {
|
||||
let mut parts = Vec::new();
|
||||
if let Some(v) = tbl.get("path").and_then(|v| v.as_str()) {
|
||||
parts.push(format!("path = \"{v}\""));
|
||||
}
|
||||
if let Some(v) = tbl.get("system").and_then(|v| v.as_bool()) {
|
||||
parts.push(format!("system = {}", if v { "true" } else { "false" }));
|
||||
}
|
||||
if let Some(v) = tbl.get("include") {
|
||||
parts.push(format!("include = {}", format_string_array(v)));
|
||||
}
|
||||
if let Some(v) = tbl.get("lib") {
|
||||
parts.push(format!("lib = {}", format_string_array(v)));
|
||||
}
|
||||
if let Some(v) = tbl.get("libs") {
|
||||
parts.push(format!("libs = {}", format_string_array(v)));
|
||||
}
|
||||
format!("{{ {} }}", parts.join(", "))
|
||||
}
|
||||
_ => "\"\"".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn format_string_array(value: &Value) -> String {
|
||||
if let Some(arr) = value.as_array() {
|
||||
let items: Vec<String> = arr
|
||||
.iter()
|
||||
.filter_map(|v| v.as_str().map(|s| format!("\"{s}\"")))
|
||||
.collect();
|
||||
return format!("[{}]", items.join(", "));
|
||||
}
|
||||
"[]".to_string()
|
||||
}
|
||||
|
||||
fn get_path<'a>(value: &'a Value, path: &[&str]) -> Option<&'a Value> {
|
||||
let mut current = value;
|
||||
for key in path {
|
||||
current = current.as_table()?.get(*key)?;
|
||||
}
|
||||
Some(current)
|
||||
}
|
||||
|
||||
fn set_path(value: &mut Value, path: &[&str], new_value: Value) -> Result<(), ConfigError> {
|
||||
let mut current = value
|
||||
.as_table_mut()
|
||||
.ok_or_else(|| ConfigError::Invalid("root is not a table".into()))?;
|
||||
|
||||
for key in &path[..path.len().saturating_sub(1)] {
|
||||
if !current.contains_key(*key) {
|
||||
current.insert((*key).to_string(), Value::Table(Map::new()));
|
||||
}
|
||||
current = current
|
||||
.get_mut(*key)
|
||||
.and_then(|v| v.as_table_mut())
|
||||
.ok_or_else(|| ConfigError::Invalid(format!("'{key}' is not a table")))?;
|
||||
}
|
||||
|
||||
if let Some(last) = path.last() {
|
||||
current.insert((*last).to_string(), new_value);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ConfigError::Invalid("empty key".into()))
|
||||
}
|
||||
}
|
||||
353
src/core/deps.rs
Normal file
353
src/core/deps.rs
Normal file
@@ -0,0 +1,353 @@
|
||||
use crate::core::config::Config;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use toml::Value;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DepSpec {
|
||||
pub name: String,
|
||||
pub path_raw: String,
|
||||
pub include_raw: Option<Vec<String>>,
|
||||
pub lib_raw: Option<Vec<String>>,
|
||||
pub libs_raw: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ResolvedDeps {
|
||||
pub include_dirs: Vec<String>,
|
||||
pub lib_dirs: Vec<String>,
|
||||
pub libs: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn resolve_deps(
|
||||
config: &Config,
|
||||
profile: &str,
|
||||
project_root: &Path,
|
||||
) -> Result<ResolvedDeps, String> {
|
||||
let project_name = config
|
||||
.get("package.name")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
let project_version = config
|
||||
.get("package.version")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
let deps = parse_dependencies(config)?;
|
||||
if deps.is_empty() {
|
||||
return Ok(ResolvedDeps {
|
||||
include_dirs: Vec::new(),
|
||||
lib_dirs: Vec::new(),
|
||||
libs: Vec::new(),
|
||||
});
|
||||
}
|
||||
|
||||
let mut include_dirs = Vec::new();
|
||||
let mut lib_dirs = Vec::new();
|
||||
let mut libs = Vec::new();
|
||||
let mut lock_packages = Vec::new();
|
||||
|
||||
for dep in deps {
|
||||
let dep_path = resolve_path(project_root, &dep.path_raw)?;
|
||||
if !dep_path.is_dir() {
|
||||
return Err(format!(
|
||||
"Dependency '{}' path is not a directory: {}",
|
||||
dep.name,
|
||||
dep_path.display()
|
||||
));
|
||||
}
|
||||
|
||||
let include = resolve_paths(&dep_path, dep.include_raw.as_deref(), &["include"])?;
|
||||
let lib = resolve_paths(&dep_path, dep.lib_raw.as_deref(), &["lib", "lib64"])?;
|
||||
let libs_list = dep
|
||||
.libs_raw
|
||||
.clone()
|
||||
.unwrap_or_else(|| vec![dep.name.clone()]);
|
||||
|
||||
if include.is_empty() || lib.is_empty() {
|
||||
return Err(format!(
|
||||
"Dependency '{}' missing include/lib dirs. Add include/lib in dcr.toml.",
|
||||
dep.name
|
||||
));
|
||||
}
|
||||
|
||||
include_dirs.extend(include.iter().map(|p| p.to_string_lossy().to_string()));
|
||||
lib_dirs.extend(lib.iter().map(|p| p.to_string_lossy().to_string()));
|
||||
libs.extend(libs_list.iter().cloned());
|
||||
|
||||
let dep_cache = project_root
|
||||
.join("target")
|
||||
.join(profile)
|
||||
.join("deps")
|
||||
.join(&dep.name);
|
||||
sync_dep_dir(&dep_path, &dep_cache)
|
||||
.map_err(|err| format!("Failed to sync dep {}: {err}", dep.name))?;
|
||||
|
||||
let dep_version = read_dep_version(&dep_path).unwrap_or_else(|| "0.0.0".to_string());
|
||||
let dep_checksum = compute_checksum(&dep_path)
|
||||
.map_err(|err| format!("Failed to hash dep {}: {err}", dep.name))?;
|
||||
lock_packages.push(DepLock {
|
||||
name: dep.name.clone(),
|
||||
version: dep_version,
|
||||
checksum: dep_checksum,
|
||||
source: format!("path+{}", dep.path_raw),
|
||||
});
|
||||
}
|
||||
|
||||
write_lock(
|
||||
project_root,
|
||||
&project_name,
|
||||
&project_version,
|
||||
&lock_packages,
|
||||
)?;
|
||||
|
||||
Ok(ResolvedDeps {
|
||||
include_dirs,
|
||||
lib_dirs,
|
||||
libs,
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct DepLock {
|
||||
name: String,
|
||||
version: String,
|
||||
checksum: String,
|
||||
source: String,
|
||||
}
|
||||
|
||||
fn parse_dependencies(config: &Config) -> Result<Vec<DepSpec>, String> {
|
||||
let deps_val = match config.get("dependencies") {
|
||||
Some(v) => v,
|
||||
None => return Ok(Vec::new()),
|
||||
};
|
||||
let deps_table = deps_val
|
||||
.as_table()
|
||||
.ok_or_else(|| "dependencies is not a table".to_string())?;
|
||||
let mut deps = Vec::new();
|
||||
for (name, value) in deps_table {
|
||||
match value {
|
||||
Value::Table(tbl) => {
|
||||
if tbl.get("system").and_then(|v| v.as_bool()).unwrap_or(false) {
|
||||
return Err(format!(
|
||||
"Dependency '{}' uses system=true, which is not supported yet",
|
||||
name
|
||||
));
|
||||
}
|
||||
let path = tbl
|
||||
.get("path")
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or_else(|| format!("Dependency '{}' missing path", name))?
|
||||
.to_string();
|
||||
let include = parse_string_list(tbl.get("include"), name, "include")?;
|
||||
let lib = parse_string_list(tbl.get("lib"), name, "lib")?;
|
||||
let libs = parse_string_list(tbl.get("libs"), name, "libs")?;
|
||||
deps.push(DepSpec {
|
||||
name: name.to_string(),
|
||||
path_raw: path,
|
||||
include_raw: include,
|
||||
lib_raw: lib,
|
||||
libs_raw: libs,
|
||||
});
|
||||
}
|
||||
_ => {
|
||||
return Err(format!(
|
||||
"Dependency '{}' must be a table with path/include/lib",
|
||||
name
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
deps.sort_by(|a, b| a.name.cmp(&b.name));
|
||||
Ok(deps)
|
||||
}
|
||||
|
||||
fn parse_string_list(
|
||||
value: Option<&Value>,
|
||||
dep_name: &str,
|
||||
key: &str,
|
||||
) -> Result<Option<Vec<String>>, String> {
|
||||
let Some(value) = value else { return Ok(None) };
|
||||
let list = value.as_array().ok_or_else(|| {
|
||||
format!(
|
||||
"Dependency '{}' field '{}' must be an array of strings",
|
||||
dep_name, key
|
||||
)
|
||||
})?;
|
||||
let mut out = Vec::new();
|
||||
for item in list {
|
||||
let s = item
|
||||
.as_str()
|
||||
.ok_or_else(|| format!("Dependency '{}' field '{}' must be strings", dep_name, key))?;
|
||||
out.push(s.to_string());
|
||||
}
|
||||
Ok(Some(out))
|
||||
}
|
||||
|
||||
fn resolve_path(project_root: &Path, raw: &str) -> Result<PathBuf, String> {
|
||||
let p = Path::new(raw);
|
||||
let full = if p.is_absolute() {
|
||||
p.to_path_buf()
|
||||
} else {
|
||||
project_root.join(p)
|
||||
};
|
||||
Ok(full)
|
||||
}
|
||||
|
||||
fn resolve_paths(
|
||||
base: &Path,
|
||||
raw: Option<&[String]>,
|
||||
defaults: &[&str],
|
||||
) -> Result<Vec<PathBuf>, String> {
|
||||
let mut out = Vec::new();
|
||||
if let Some(raw) = raw {
|
||||
for r in raw {
|
||||
let p = Path::new(r);
|
||||
let full = if p.is_absolute() {
|
||||
p.to_path_buf()
|
||||
} else {
|
||||
base.join(p)
|
||||
};
|
||||
if !full.exists() {
|
||||
return Err(format!("Path does not exist: {}", full.display()));
|
||||
}
|
||||
out.push(full);
|
||||
}
|
||||
return Ok(out);
|
||||
}
|
||||
|
||||
for d in defaults {
|
||||
let candidate = base.join(d);
|
||||
if candidate.exists() {
|
||||
out.push(candidate);
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
fn sync_dep_dir(src: &Path, dst: &Path) -> std::io::Result<()> {
|
||||
if dst.exists() {
|
||||
fs::remove_dir_all(dst)?;
|
||||
}
|
||||
copy_dir_all(src, dst)
|
||||
}
|
||||
|
||||
fn copy_dir_all(src: &Path, dst: &Path) -> std::io::Result<()> {
|
||||
fs::create_dir_all(dst)?;
|
||||
for entry in fs::read_dir(src)? {
|
||||
let entry = entry?;
|
||||
let ty = entry.file_type()?;
|
||||
let from = entry.path();
|
||||
let to = dst.join(entry.file_name());
|
||||
if ty.is_dir() {
|
||||
copy_dir_all(&from, &to)?;
|
||||
} else {
|
||||
fs::copy(&from, &to)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_lock(
|
||||
project_root: &Path,
|
||||
project_name: &str,
|
||||
project_version: &str,
|
||||
packages: &[DepLock],
|
||||
) -> Result<(), String> {
|
||||
let mut out = String::new();
|
||||
if !packages.is_empty() {
|
||||
out.push_str("[[package]]\n");
|
||||
out.push_str(&format!("name = \"{}\"\n", escape_value(project_name)));
|
||||
out.push_str(&format!(
|
||||
"version = \"{}\"\n",
|
||||
escape_value(project_version)
|
||||
));
|
||||
out.push_str(&format!(
|
||||
"dependencies = [{}]\n\n",
|
||||
quote_list(&packages.iter().map(|p| p.name.clone()).collect::<Vec<_>>())
|
||||
));
|
||||
}
|
||||
for pkg in packages {
|
||||
out.push_str("[[package]]\n");
|
||||
out.push_str(&format!("name = \"{}\"\n", escape_value(&pkg.name)));
|
||||
out.push_str(&format!("version = \"{}\"\n", escape_value(&pkg.version)));
|
||||
out.push_str(&format!("source = \"{}\"\n", escape_value(&pkg.source)));
|
||||
out.push_str(&format!("checksum = \"{}\"\n", escape_value(&pkg.checksum)));
|
||||
out.push('\n');
|
||||
}
|
||||
fs::write(project_root.join("dcr.lock"), out)
|
||||
.map_err(|err| format!("Failed to write dcr.lock: {err}"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn quote_list(items: &[String]) -> String {
|
||||
items
|
||||
.iter()
|
||||
.map(|s| format!("\"{}\"", escape_value(s)))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
}
|
||||
|
||||
fn escape_value(input: &str) -> String {
|
||||
input.replace('\\', "\\\\").replace('"', "\\\"")
|
||||
}
|
||||
|
||||
fn read_dep_version(dep_path: &Path) -> Option<String> {
|
||||
let path = dep_path.join("dcr.toml");
|
||||
let content = fs::read_to_string(path).ok()?;
|
||||
let value: Value = content.parse().ok()?;
|
||||
value
|
||||
.get("package")
|
||||
.and_then(|v| v.as_table())
|
||||
.and_then(|t| t.get("version"))
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.to_string())
|
||||
}
|
||||
|
||||
fn compute_checksum(root: &Path) -> Result<String, String> {
|
||||
let mut files = Vec::new();
|
||||
collect_files(root, root, &mut files)?;
|
||||
files.sort();
|
||||
let mut hasher = Sha256::new();
|
||||
for rel in files {
|
||||
hasher.update(rel.as_bytes());
|
||||
let data =
|
||||
fs::read(root.join(&rel)).map_err(|err| format!("failed to read {}: {err}", rel))?;
|
||||
hasher.update(&data);
|
||||
}
|
||||
let hash = hasher.finalize();
|
||||
Ok(to_hex(&hash))
|
||||
}
|
||||
|
||||
fn collect_files(root: &Path, dir: &Path, out: &mut Vec<String>) -> Result<(), String> {
|
||||
for entry in fs::read_dir(dir).map_err(|err| format!("read_dir failed: {err}"))? {
|
||||
let entry = entry.map_err(|err| format!("read_dir failed: {err}"))?;
|
||||
let path = entry.path();
|
||||
let name = entry.file_name();
|
||||
let name_str = name.to_string_lossy();
|
||||
if name_str == "target" {
|
||||
continue;
|
||||
}
|
||||
if path.is_dir() {
|
||||
collect_files(root, &path, out)?;
|
||||
} else if path.is_file() {
|
||||
let rel = path
|
||||
.strip_prefix(root)
|
||||
.unwrap_or(&path)
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
out.push(rel);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn to_hex(bytes: &[u8]) -> String {
|
||||
let mut out = String::with_capacity(bytes.len() * 2);
|
||||
for b in bytes {
|
||||
out.push_str(&format!("{:02x}", b));
|
||||
}
|
||||
out
|
||||
}
|
||||
4
src/core/mod.rs
Normal file
4
src/core/mod.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
pub mod builder;
|
||||
pub mod config;
|
||||
pub mod deps;
|
||||
pub mod runner;
|
||||
37
src/core/runner.rs
Normal file
37
src/core/runner.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use crate::platform;
|
||||
use crate::utils::fs::check_dir;
|
||||
use crate::utils::log::warn;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn run_binary(project_name: &str, profile: &str, target_dir: Option<&str>) -> i32 {
|
||||
let bin_path = platform::bin_path(profile, project_name, target_dir);
|
||||
if Path::new(&bin_path).exists() {
|
||||
return Command::new(bin_path)
|
||||
.status()
|
||||
.map(|status| status.code().unwrap_or(1))
|
||||
.unwrap_or(1);
|
||||
}
|
||||
|
||||
if target_dir.is_none()
|
||||
&& check_dir(Some(&format!("target/{profile}")))
|
||||
.unwrap_or_default()
|
||||
.contains(&profile.to_string())
|
||||
{
|
||||
warn("Launch of the latest release");
|
||||
return Command::new(platform::bin_path(profile, project_name, target_dir))
|
||||
.status()
|
||||
.map(|status| status.code().unwrap_or(1))
|
||||
.unwrap_or(1);
|
||||
}
|
||||
|
||||
if target_dir.is_some() && Path::new(&bin_path).exists() {
|
||||
warn("Launch of the latest release");
|
||||
return Command::new(bin_path)
|
||||
.status()
|
||||
.map(|status| status.code().unwrap_or(1))
|
||||
.unwrap_or(1);
|
||||
}
|
||||
|
||||
1
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
use crate::utils::log::error;
|
||||
mod cli;
|
||||
mod config;
|
||||
mod core;
|
||||
mod platform;
|
||||
mod utils;
|
||||
|
||||
fn main() {
|
||||
@@ -25,7 +28,7 @@ fn main() {
|
||||
"--help" => cli::help::help(),
|
||||
"--update" => cli::flag_update::flag_update(rest),
|
||||
_ => {
|
||||
println!("Неизвестная команда или аргумент");
|
||||
error("Unknown command or argument");
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
13
src/platform/linux.rs
Normal file
13
src/platform/linux.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
pub fn bin_path(profile: &str, name: &str, target_dir: Option<&str>) -> String {
|
||||
match target_dir {
|
||||
Some(dir) => format!("{}/{}", dir.trim_end_matches('/'), name),
|
||||
None => format!("./target/{profile}/{name}"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lib_path(profile: &str, name: &str, target_dir: Option<&str>) -> String {
|
||||
match target_dir {
|
||||
Some(dir) => format!("{}/lib{}.a", dir.trim_end_matches('/'), name),
|
||||
None => format!("./target/{profile}/lib{name}.a"),
|
||||
}
|
||||
}
|
||||
13
src/platform/macos.rs
Normal file
13
src/platform/macos.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
pub fn bin_path(profile: &str, name: &str, target_dir: Option<&str>) -> String {
|
||||
match target_dir {
|
||||
Some(dir) => format!("{}/{}", dir.trim_end_matches('/'), name),
|
||||
None => format!("./target/{profile}/{name}"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lib_path(profile: &str, name: &str, target_dir: Option<&str>) -> String {
|
||||
match target_dir {
|
||||
Some(dir) => format!("{}/lib{}.a", dir.trim_end_matches('/'), name),
|
||||
None => format!("./target/{profile}/lib{name}.a"),
|
||||
}
|
||||
}
|
||||
50
src/platform/mod.rs
Normal file
50
src/platform/mod.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
#[cfg(target_os = "linux")]
|
||||
pub mod linux;
|
||||
#[cfg(target_os = "macos")]
|
||||
pub mod macos;
|
||||
#[cfg(target_os = "windows")]
|
||||
pub mod windows;
|
||||
|
||||
pub fn bin_path(profile: &str, name: &str, target_dir: Option<&str>) -> String {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
linux::bin_path(profile, name, target_dir)
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
return macos::bin_path(profile, name, target_dir);
|
||||
}
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
return windows::bin_path(profile, name, target_dir);
|
||||
}
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
|
||||
{
|
||||
match target_dir {
|
||||
Some(dir) => format!("{}/{}", dir.trim_end_matches('/'), name),
|
||||
None => format!("./target/{profile}/{name}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lib_path(profile: &str, name: &str, target_dir: Option<&str>) -> String {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
linux::lib_path(profile, name, target_dir)
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
return macos::lib_path(profile, name, target_dir);
|
||||
}
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
return windows::lib_path(profile, name, target_dir);
|
||||
}
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
|
||||
{
|
||||
match target_dir {
|
||||
Some(dir) => format!("{}/lib{}.a", dir.trim_end_matches('/'), name),
|
||||
None => format!("./target/{profile}/lib{name}.a"),
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/platform/windows.rs
Normal file
13
src/platform/windows.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
pub fn bin_path(profile: &str, name: &str, target_dir: Option<&str>) -> String {
|
||||
match target_dir {
|
||||
Some(dir) => format!("{}/{}.exe", dir.trim_end_matches('/'), name),
|
||||
None => format!("./target/{profile}/{name}.exe"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lib_path(profile: &str, name: &str, target_dir: Option<&str>) -> String {
|
||||
match target_dir {
|
||||
Some(dir) => format!("{}/{}.lib", dir.trim_end_matches('/'), name),
|
||||
None => format!("./target/{profile}/{name}.lib"),
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn check_dir(dir: Option<&str>) -> io::Result<Vec<String>> {
|
||||
let path: PathBuf = match dir {
|
||||
None | Some(".") | Some("./") => std::env::current_dir()?,
|
||||
|
||||
@@ -1,30 +1,24 @@
|
||||
use crate::utils::text::{BOLD, BRIGHT_GREEN, BRIGHT_RED, BRIGHT_YELLOW, colored};
|
||||
use crate::utils::text::{BOLD_CYAN, colored};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn error(msg: &str) {
|
||||
println!(
|
||||
"{}: {msg}",
|
||||
colored("error", &(BRIGHT_RED.to_owned() + BOLD))
|
||||
);
|
||||
println!("{}: {msg}", colored("error", BOLD_CYAN),);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn warn(msg: &str) {
|
||||
println!(
|
||||
"{}: {msg}",
|
||||
colored("warn", &(BRIGHT_YELLOW.to_owned() + BOLD))
|
||||
);
|
||||
println!("{}: {msg}", colored("warn", BOLD_CYAN),);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn info(msg: &str) {
|
||||
println!("{}: {msg}", colored("info", BOLD));
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn ok(msg: &str) {
|
||||
println!(
|
||||
"{}: {msg}",
|
||||
colored("ok", &(BRIGHT_GREEN.to_owned() + BOLD))
|
||||
);
|
||||
}
|
||||
// #[allow(dead_code)]
|
||||
// pub fn info(msg: &str) {
|
||||
// println!("{}: {msg}", colored("info", BOLD));
|
||||
// }
|
||||
//
|
||||
// #[allow(dead_code)]
|
||||
// pub fn ok(msg: &str) {
|
||||
// println!(
|
||||
// "{}: {msg}",
|
||||
// colored("ok", &(BRIGHT_GREEN.to_owned() + BOLD))
|
||||
// );
|
||||
// }
|
||||
|
||||
@@ -1,16 +1,32 @@
|
||||
#[allow(dead_code)]
|
||||
pub const RESET: &str = "\x1b[0m";
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub const BOLD: &str = "\x1b[1m";
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub const BRIGHT_RED: &str = "\x1b[91m";
|
||||
#[allow(dead_code)]
|
||||
pub const BRIGHT_GREEN: &str = "\x1b[92m";
|
||||
#[allow(dead_code)]
|
||||
pub const BRIGHT_YELLOW: &str = "\x1b[93m";
|
||||
#[allow(dead_code)]
|
||||
pub const BRIGHT_CYAN: &str = "\x1b[96m";
|
||||
#[allow(dead_code)]
|
||||
pub const BOLD_RED: &str = "\x1b[1m\x1b[91m";
|
||||
#[allow(dead_code)]
|
||||
pub const BOLD_GREEN: &str = "\x1b[1m\x1b[92m";
|
||||
#[allow(dead_code)]
|
||||
pub const BOLD_YELLOW: &str = "\x1b[1m\x1b[93m";
|
||||
#[allow(dead_code)]
|
||||
pub const BOLD_CYAN: &str = "\x1b[1m\x1b[96m";
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn colored(msg: &str, style: &str) -> String {
|
||||
format!("{style}{msg}{RESET}")
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn printc(msg: &str, style: &str) {
|
||||
println!("{style}{msg}{RESET}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user