mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-22 19:09:37 +00:00
Compare commits
5 Commits
v0.4.0
...
debc5d2044
| Author | SHA1 | Date | |
|---|---|---|---|
| debc5d2044 | |||
| 00ed418291 | |||
| 7cefbb3c3a | |||
| 045cc90d81 | |||
| fd88e036ed |
57
CHANGELOG.md
57
CHANGELOG.md
@@ -1,5 +1,62 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [0.6.0] - 2026-05-12
|
||||||
|
|
||||||
|
Added:
|
||||||
|
|
||||||
|
- Full Git dependency support in `dcr.toml`
|
||||||
|
- Support for `git`, `branch`, `tag`, and `rev` fields
|
||||||
|
- Automatic cloning and checkout via `git2`
|
||||||
|
- Dependencies are stored in `target/<profile>/deps/git/`
|
||||||
|
- New `dcr add` command for easy dependency management
|
||||||
|
- Short syntax: `github:user/repo`, `gitlab:user/repo`, `path:/to/lib`
|
||||||
|
- Automatic GitHub resolution for `git:user/repo`
|
||||||
|
- Visual feedback for dependency fetching with in-place status updates ("Fetching" → "Fetched")
|
||||||
|
- Modular dependency management architecture in `src/core/deps/`
|
||||||
|
|
||||||
|
## [0.5.1] - 2026-04-12
|
||||||
|
|
||||||
|
Fixed:
|
||||||
|
|
||||||
|
- Windows compatibility for target-specific config without --target flag
|
||||||
|
|
||||||
|
Added:
|
||||||
|
|
||||||
|
- Default host target detection for automatic target overrides
|
||||||
|
- Unit tests for target normalization
|
||||||
|
|
||||||
|
Improved:
|
||||||
|
|
||||||
|
- Config value lookup optimization
|
||||||
|
- Documentation for Windows cross-compilation
|
||||||
|
|
||||||
|
## [0.5.0] - 2026-04-10
|
||||||
|
|
||||||
|
Added:
|
||||||
|
|
||||||
|
- Full inheritance system for all config sections: `build`, `toolchain`, `run`, `workspace`, `dependencies`
|
||||||
|
- Order: `section.target.profile` → `section.profile.target` → `section.target` → `section.profile` → `section`
|
||||||
|
- `inherit = false` to disable inheritance completely
|
||||||
|
- Target-specific overrides: `[build.linux]`, `[toolchain.windows]`, `[run.macos]`, etc.
|
||||||
|
- Cross-compilation support with `--target <triple>`
|
||||||
|
- Full target triples and short names (`linux`, `macos`, `windows`)
|
||||||
|
- Target-specific config sections: `[build.<target>]`, `[toolchain.<target>]`, `[run.<target>]`
|
||||||
|
- Workspace and dependencies support target/profile inheritance
|
||||||
|
- Multiple targets build: `[build.targets]` to build for multiple targets simultaneously
|
||||||
|
- Target directory structure: `target/<target>/<profile>/` (native or triple)
|
||||||
|
- Updated documentation with cross-compilation guide and Arch Linux examples
|
||||||
|
|
||||||
|
## [0.4.0] - 2026-04-10
|
||||||
|
|
||||||
|
Added:
|
||||||
|
|
||||||
|
- Test command: `dcr test` and `dcr tests`
|
||||||
|
- Automatic compilation and linking for tests without manual configuration
|
||||||
|
- `dcr test --init` creates test template and header
|
||||||
|
- Test framework with EXPECT/SKIP macros in `dcr_test.h`
|
||||||
|
- Improved test integration: added test CLI module and basic test suite
|
||||||
|
- Documentation updates for testing functionality
|
||||||
|
|
||||||
## [0.3.0] - 2026-03-18
|
## [0.3.0] - 2026-03-18
|
||||||
|
|
||||||
Added:
|
Added:
|
||||||
|
|||||||
@@ -22,6 +22,27 @@ cargo check
|
|||||||
- Keep functions small and focused.
|
- Keep functions small and focused.
|
||||||
- Prefer clear names over clever ones.
|
- Prefer clear names over clever ones.
|
||||||
|
|
||||||
|
## Target System
|
||||||
|
|
||||||
|
DCR supports cross-compilation via `--target <triple>` or short names:
|
||||||
|
|
||||||
|
- `dcr build --target linux --release` (maps to `x86_64-unknown-linux-gnu`)
|
||||||
|
- `dcr build --target macos --release` (maps to `x86_64-apple-darwin`)
|
||||||
|
- `dcr build --target windows --release` (maps to `x86_64-pc-windows-msvc`)
|
||||||
|
- Full triples: `dcr build --target aarch64-linux-gnu --release`
|
||||||
|
- Configure multiple targets in `dcr.toml`:
|
||||||
|
```
|
||||||
|
[build.targets]
|
||||||
|
targets = ["linux", "macos"]
|
||||||
|
|
||||||
|
[build.linux]
|
||||||
|
compiler = "gcc"
|
||||||
|
|
||||||
|
[build.macos]
|
||||||
|
compiler = "clang"
|
||||||
|
```
|
||||||
|
- If no `--target`, builds for targets in `build.targets` or native if empty.
|
||||||
|
|
||||||
## Checks
|
## Checks
|
||||||
|
|
||||||
Before PR, run:
|
Before PR, run:
|
||||||
|
|||||||
151
Cargo.lock
generated
151
Cargo.lock
generated
@@ -54,6 +54,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2"
|
checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"find-msvc-tools",
|
"find-msvc-tools",
|
||||||
|
"jobserver",
|
||||||
|
"libc",
|
||||||
"shlex",
|
"shlex",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -69,6 +71,18 @@ version = "0.2.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "console"
|
||||||
|
version = "0.16.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d64e8af5551369d19cf50138de61f1c42074ab970f74e99be916646777f8fc87"
|
||||||
|
dependencies = [
|
||||||
|
"encode_unicode",
|
||||||
|
"libc",
|
||||||
|
"unicode-width",
|
||||||
|
"windows-sys 0.61.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cpufeatures"
|
name = "cpufeatures"
|
||||||
version = "0.2.17"
|
version = "0.2.17"
|
||||||
@@ -90,9 +104,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dcr"
|
name = "dcr"
|
||||||
version = "0.4.0"
|
version = "0.6.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"console",
|
||||||
|
"git2",
|
||||||
"glob",
|
"glob",
|
||||||
|
"indicatif",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"self-replace",
|
"self-replace",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -121,6 +138,12 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "encode_unicode"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "equivalent"
|
name = "equivalent"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
@@ -263,6 +286,21 @@ dependencies = [
|
|||||||
"wasip3",
|
"wasip3",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "git2"
|
||||||
|
version = "0.20.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7b88256088d75a56f8ecfa070513a775dd9107f6530ef14919dac831af9cfe2b"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"libc",
|
||||||
|
"libgit2-sys",
|
||||||
|
"log",
|
||||||
|
"openssl-probe",
|
||||||
|
"openssl-sys",
|
||||||
|
"url",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glob"
|
name = "glob"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
@@ -510,6 +548,19 @@ dependencies = [
|
|||||||
"serde_core",
|
"serde_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "indicatif"
|
||||||
|
version = "0.18.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "25470f23803092da7d239834776d653104d551bc4d7eacaf31e6837854b8e9eb"
|
||||||
|
dependencies = [
|
||||||
|
"console",
|
||||||
|
"portable-atomic",
|
||||||
|
"unicode-width",
|
||||||
|
"unit-prefix",
|
||||||
|
"web-time",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ipnet"
|
name = "ipnet"
|
||||||
version = "2.11.0"
|
version = "2.11.0"
|
||||||
@@ -532,6 +583,16 @@ version = "1.0.17"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
|
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "jobserver"
|
||||||
|
version = "0.1.34"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom 0.3.4",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.85"
|
version = "0.3.85"
|
||||||
@@ -554,6 +615,46 @@ version = "0.2.182"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
|
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libgit2-sys"
|
||||||
|
version = "0.18.4+1.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9b26f66f35e1871b22efcf7191564123d2a446ca0538cde63c23adfefa9b15b7"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"libssh2-sys",
|
||||||
|
"libz-sys",
|
||||||
|
"openssl-sys",
|
||||||
|
"pkg-config",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libssh2-sys"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "220e4f05ad4a218192533b300327f5150e809b54c4ec83b5a1d91833601811b9"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"libz-sys",
|
||||||
|
"openssl-sys",
|
||||||
|
"pkg-config",
|
||||||
|
"vcpkg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libz-sys"
|
||||||
|
version = "1.1.28"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fc3a226e576f50782b3305c5ccf458698f92798987f551c6a02efe8276721e22"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"pkg-config",
|
||||||
|
"vcpkg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linux-raw-sys"
|
name = "linux-raw-sys"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
@@ -601,6 +702,24 @@ version = "1.21.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "openssl-probe"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "openssl-sys"
|
||||||
|
version = "0.9.115"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "158fe5b292746440aa6e7a7e690e55aeb72d41505e2804c23c6973ad0e9c9781"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"pkg-config",
|
||||||
|
"vcpkg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.3.2"
|
version = "2.3.2"
|
||||||
@@ -619,6 +738,18 @@ version = "0.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkg-config"
|
||||||
|
version = "0.3.33"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "portable-atomic"
|
||||||
|
version = "1.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "potential_utf"
|
name = "potential_utf"
|
||||||
version = "0.1.4"
|
version = "0.1.4"
|
||||||
@@ -1241,12 +1372,24 @@ version = "1.0.24"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-xid"
|
name = "unicode-xid"
|
||||||
version = "0.2.6"
|
version = "0.2.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unit-prefix"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "81e544489bf3d8ef66c953931f56617f423cd4b5494be343d9b9d3dda037b9a3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "untrusted"
|
name = "untrusted"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
@@ -1271,6 +1414,12 @@ version = "1.0.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "vcpkg"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version_check"
|
name = "version_check"
|
||||||
version = "0.9.5"
|
version = "0.9.5"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "dcr"
|
name = "dcr"
|
||||||
version = "0.4.0"
|
version = "0.6.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
@@ -11,3 +11,6 @@ serde = { version = "1", features = ["derive"] }
|
|||||||
self-replace = "1"
|
self-replace = "1"
|
||||||
sha2 = "0.10"
|
sha2 = "0.10"
|
||||||
toml = "1.0.3"
|
toml = "1.0.3"
|
||||||
|
indicatif = "0.18.4"
|
||||||
|
console = "0.16.3"
|
||||||
|
git2 = "0.20.4"
|
||||||
|
|||||||
55
README.md
55
README.md
@@ -17,8 +17,11 @@ The current implementation is written in Rust.
|
|||||||
- Generate IDE integration files (VS Code, CLion) and compilation databases
|
- Generate IDE integration files (VS Code, CLion) and compilation databases
|
||||||
- Generate a minimal C project template
|
- Generate a minimal C project template
|
||||||
- Build static and shared libraries
|
- Build static and shared libraries
|
||||||
|
- Git and Path dependency support with `dcr.lock` and automatic resolution
|
||||||
- ASM projects with NASM/GAS or via GCC/Clang
|
- ASM projects with NASM/GAS or via GCC/Clang
|
||||||
- Mixed language projects (`language = ["c", "asm"]` and similar)
|
- Mixed language projects (`language = ["c", "asm"]` and similar)
|
||||||
|
- Cross-compilation with `--target` (short names: `linux`, `macos`, `windows`)
|
||||||
|
- Target-specific configurations and inheritance
|
||||||
- Update the binary via `dcr --update` (GitHub Releases, not for pacman/AUR installs)
|
- Update the binary via `dcr --update` (GitHub Releases, not for pacman/AUR installs)
|
||||||
|
|
||||||
## Supported Platforms
|
## Supported Platforms
|
||||||
@@ -104,6 +107,11 @@ Creates a project with the specified name in the current directory.
|
|||||||
### `dcr init`
|
### `dcr init`
|
||||||
Creates a project in the current directory. The project name is taken from the directory name. The directory must be empty.
|
Creates a project in the current directory. The project name is taken from the directory name. The directory must be empty.
|
||||||
|
|
||||||
|
### `dcr add <name> <source>`
|
||||||
|
Adds a dependency to `dcr.toml`.
|
||||||
|
Sources can be `path:`, `github:`, `gitlab:`, `git:`, or a full URL.
|
||||||
|
Use `--branch`, `--tag`, or `--rev` for Git dependencies.
|
||||||
|
|
||||||
### `dcr build [profile]`
|
### `dcr build [profile]`
|
||||||
Builds the project. If no profile is specified, `--debug` is used.
|
Builds the project. If no profile is specified, `--debug` is used.
|
||||||
Use `--force` to rebuild without cache, `--clean` to clean before build.
|
Use `--force` to rebuild without cache, `--clean` to clean before build.
|
||||||
@@ -119,6 +127,16 @@ Run manually:
|
|||||||
Removes the `target` directory in the project root.
|
Removes the `target` directory in the project root.
|
||||||
Use `dcr clean --all` in a workspace root to clean all member projects.
|
Use `dcr clean --all` in a workspace root to clean all member projects.
|
||||||
|
|
||||||
|
### `dcr gen`
|
||||||
|
Generates IDE integration files and build tools.
|
||||||
|
- `dcr gen vscode`: VS Code workspace config
|
||||||
|
- `dcr gen clion`: CLion project files
|
||||||
|
- `dcr gen compile-commands`: `compile_commands.json` for clang tools
|
||||||
|
|
||||||
|
### `dcr test`
|
||||||
|
Runs the test suite.
|
||||||
|
Use `dcr test --init` to create test files.
|
||||||
|
|
||||||
## Build Profiles
|
## Build Profiles
|
||||||
Two profiles are supported:
|
Two profiles are supported:
|
||||||
- `--debug` (default) - built-in flags per compiler
|
- `--debug` (default) - built-in flags per compiler
|
||||||
@@ -136,6 +154,33 @@ Use `build.roots` and `build.src_disable` to replace the default `src/` root.
|
|||||||
Use `build.steps` and `build.post_steps` to run custom commands.
|
Use `build.steps` and `build.post_steps` to run custom commands.
|
||||||
Use `build.clean` for extra cleanup paths and `[run].cmd` to override run command.
|
Use `build.clean` for extra cleanup paths and `[run].cmd` to override run command.
|
||||||
|
|
||||||
|
## Cross-compilation
|
||||||
|
|
||||||
|
DCR supports cross-compilation via `--target <triple>` or short names:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
dcr build --target linux --release # x86_64-unknown-linux-gnu
|
||||||
|
dcr build --target macos --release # x86_64-apple-darwin
|
||||||
|
dcr build --target windows --release # x86_64-pc-windows-msvc
|
||||||
|
dcr run --target aarch64-linux-gnu
|
||||||
|
```
|
||||||
|
|
||||||
|
Configure multiple targets and target-specific settings in `dcr.toml`:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[build.targets]
|
||||||
|
targets = ["linux", "windows"]
|
||||||
|
|
||||||
|
[build.linux]
|
||||||
|
compiler = "gcc"
|
||||||
|
cflags = ["-O2"]
|
||||||
|
|
||||||
|
[build.windows]
|
||||||
|
compiler = "x86_64-w64-mingw32-gcc"
|
||||||
|
```
|
||||||
|
|
||||||
|
See [Cross-compilation guide](docs/dependencies-and-build/cross-compilation.md) for details.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
The main project file is `dcr.toml`.
|
The main project file is `dcr.toml`.
|
||||||
|
|
||||||
@@ -172,20 +217,22 @@ ldflags = ["-lm"]
|
|||||||
# rcc = "rcc"
|
# rcc = "rcc"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
my_lib = "path:./libs/my_lib"
|
||||||
|
cool_lib = { git = "https://github.com/user/cool_lib", tag = "v1.0" }
|
||||||
```
|
```
|
||||||
|
|
||||||
Workspace example:
|
Workspace example:
|
||||||
|
...
|
||||||
```toml
|
|
||||||
[workspace]
|
[workspace]
|
||||||
kernel = { path = "src/kernel", deps = ["core", "userspace"] }
|
kernel = { path = "src/kernel", deps = ["core", "userspace"] }
|
||||||
core = { path = "src/core", deps = ["userspace"] }
|
core = { path = "src/core", deps = ["userspace"] }
|
||||||
userspace = { path = "src/userspace" }
|
userspace = { path = "src/userspace" }
|
||||||
```
|
```
|
||||||
|
|
||||||
Path dependencies are supported. DCR will resolve them on build and generate `dcr.lock`.
|
Git and Path dependencies are supported. DCR will resolve them on build and generate `dcr.lock`.
|
||||||
|
|
||||||
|
Incremental build note: object files are rebuilt when source `.c/.cpp` or included header files change.
|
||||||
|
|
||||||
Incremental build note: object files are rebuilt when source `.c/.cpp` files change. Header dependency tracking is not implemented yet.
|
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
- Rust toolchain (`rustc`, `cargo`) - for building DCR from source
|
- Rust toolchain (`rustc`, `cargo`) - for building DCR from source
|
||||||
|
|||||||
74
TODO.md
74
TODO.md
@@ -1,9 +1,67 @@
|
|||||||
# TODO
|
# DCR TODO.md
|
||||||
|
|
||||||
- Add external package managers (Conan, vcpkg)
|
Priority list of tasks to turn DCR into a true Cargo killer for C/C++ developers.
|
||||||
- Linker script + direct linker control
|
|
||||||
- Custom targets/steps
|
## 🔥 High Priority (Next Releases)
|
||||||
- Cross-compilation and freestanding targets (-nostdinc, -nostdlib, custom target triple like i686-elf)
|
|
||||||
- Mixed C + ASM in one project (compile .c and .s/.S sources together)
|
- [x] **Git dependencies support**
|
||||||
- Per-member include directories in workspace (e.g. include paths for subprojects)
|
`git = "https://github.com/user/repo.git#branch"` and `git = "..."@tag`
|
||||||
- Build-time code generation (auto-generated headers, pre-build scripts)
|
- [ ] **Conan and vcpkg integration**
|
||||||
|
Automatic download, installation and linking of packages
|
||||||
|
- [ ] **Full freestanding / embedded support**
|
||||||
|
`-nostdlib`, linker scripts, bare-metal targets (i686-elf, aarch64-none-elf, etc.)
|
||||||
|
- [ ] **EFI support**
|
||||||
|
Dedicated platform configuration for EFI targets
|
||||||
|
- [ ] **Custom project name**
|
||||||
|
Override binary name in `dcr.toml`
|
||||||
|
- [ ] **Custom build steps / targets**
|
||||||
|
Ability to define custom pre-build, post-build, codegen steps in `dcr.toml`
|
||||||
|
- [ ] **Improved mixed C/C++/ASM projects**
|
||||||
|
Better handling of `.S` and `.asm` files with correct flags
|
||||||
|
- [ ] **dcr publish + official package registry**
|
||||||
|
Publish and fetch your own libraries easily
|
||||||
|
|
||||||
|
## ✅ Medium Priority
|
||||||
|
|
||||||
|
- [ ] **Static analysis** (`dcr check`)
|
||||||
|
Integration with clang-tidy, cppcheck, include-what-you-use
|
||||||
|
- [ ] **Linter + Formatter** (`dcr fmt`, `dcr lint`)
|
||||||
|
- [ ] **Hot reload / Live reload** for applications (raylib, SFML, SDL, etc.)
|
||||||
|
- [ ] **Better cross-compilation experience**
|
||||||
|
Ready-to-use toolchains + automatic download
|
||||||
|
- [ ] **Linker script support** + direct linker control
|
||||||
|
- [ ] **Workspaces improvements**
|
||||||
|
Per-member include directories, selective builds, better dependency graph
|
||||||
|
- [ ] **Build-time code generation**
|
||||||
|
Support for protobuf, flatbuffers, Qt moc, custom generators
|
||||||
|
|
||||||
|
## 📌 Low Priority / Nice to Have
|
||||||
|
|
||||||
|
- [ ] Support for Meson and Ninja as alternative backends
|
||||||
|
- [ ] Dockerfile generation (`dcr docker init`)
|
||||||
|
- [ ] First-class Windows MSVC support (currently works but rough)
|
||||||
|
- [ ] Documentation generation (`dcr doc`)
|
||||||
|
- [ ] Sanitizers integration (`dcr sanitize`)
|
||||||
|
- [ ] Benchmarks and comparison with CMake/Meson
|
||||||
|
- [ ] C++20 modules support (when it becomes stable)
|
||||||
|
|
||||||
|
## 🧠 Future Ideas
|
||||||
|
|
||||||
|
- Official DCR package registry (dcrhub)
|
||||||
|
- GUI wrapper (dcr-gui)
|
||||||
|
- Plugin system
|
||||||
|
- Toolchain manager (like rustup)
|
||||||
|
- Zig as alternative compiler
|
||||||
|
- deb/rpm/flatpak/AppImage packaging support
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Currently in progress:**
|
||||||
|
- ...
|
||||||
|
|
||||||
|
**Completed in recent releases:**
|
||||||
|
- Workspaces
|
||||||
|
- Cross-compilation
|
||||||
|
- IDE config generation (VS Code, CLion, compile_commands.json)
|
||||||
|
- Self-update (`dcr --update`)
|
||||||
|
- Header tracking
|
||||||
|
|||||||
@@ -21,10 +21,12 @@
|
|||||||
|
|
||||||
* [Global options](commands/global-options.md)
|
* [Global options](commands/global-options.md)
|
||||||
* [dcr init/new](commands/dcr-init-or-new.md)
|
* [dcr init/new](commands/dcr-init-or-new.md)
|
||||||
|
* [dcr add](commands/dcr-add.md)
|
||||||
* [dcr build](commands/dcr-build.md)
|
* [dcr build](commands/dcr-build.md)
|
||||||
* [dcr run](commands/dcr-run.md)
|
* [dcr run](commands/dcr-run.md)
|
||||||
* [dcr clean](commands/dcr-clean.md)
|
* [dcr clean](commands/dcr-clean.md)
|
||||||
* [dcr gen](commands/dcr-gen.md)
|
* [dcr gen](commands/dcr-gen.md)
|
||||||
|
* [dcr test](commands/dcr-test.md)
|
||||||
|
|
||||||
## Dependencies & Build
|
## Dependencies & Build
|
||||||
|
|
||||||
@@ -32,6 +34,7 @@
|
|||||||
* [Local dependencies](dependencies-and-build/local-dependencies.md)
|
* [Local dependencies](dependencies-and-build/local-dependencies.md)
|
||||||
* [Versioning & lock file](dependencies-and-build/versioning-and-lock-file.md)
|
* [Versioning & lock file](dependencies-and-build/versioning-and-lock-file.md)
|
||||||
* [Target directory](dependencies-and-build/target-directory.md)
|
* [Target directory](dependencies-and-build/target-directory.md)
|
||||||
|
* [Cross-compilation and targets](dependencies-and-build/cross-compilation.md)
|
||||||
* [Compilers & linking](dependencies-and-build/compilers-and-linking.md)
|
* [Compilers & linking](dependencies-and-build/compilers-and-linking.md)
|
||||||
|
|
||||||
## Reference & Help
|
## Reference & Help
|
||||||
|
|||||||
32
docs/commands/dcr-add.md
Normal file
32
docs/commands/dcr-add.md
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# dcr add
|
||||||
|
|
||||||
|
Add a dependency to `dcr.toml`.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
dcr add <name> <source> [options]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Sources
|
||||||
|
|
||||||
|
- `path:./path/to/lib`: Local directory.
|
||||||
|
- `github:user/repo`: GitHub repository.
|
||||||
|
- `gitlab:user/repo`: GitLab repository.
|
||||||
|
- `git:host.com/user/repo`: Generic Git repository (HTTPS).
|
||||||
|
- `https://...`: Full Git URL.
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
- `--branch <name>`: Use a specific branch.
|
||||||
|
- `--tag <name>`: Use a specific tag.
|
||||||
|
- `--rev <sha>`: Use a specific commit hash.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
```bash
|
||||||
|
dcr add my_lib path:./libs/my_lib
|
||||||
|
dcr add cool_lib github:user/cool_lib
|
||||||
|
dcr add shared_lib gitlab:org/shared --branch develop
|
||||||
|
dcr add custom_lib git:git.internal.com/r/lib --tag v1.0.0
|
||||||
|
```
|
||||||
@@ -8,6 +8,7 @@ Builds the project in `debug` or `release` profile.
|
|||||||
dcr build
|
dcr build
|
||||||
dcr build --debug
|
dcr build --debug
|
||||||
dcr build --release
|
dcr build --release
|
||||||
|
dcr build --target linux --release
|
||||||
dcr build --release --force
|
dcr build --release --force
|
||||||
dcr build --debug --clean
|
dcr build --debug --clean
|
||||||
```
|
```
|
||||||
@@ -54,6 +55,8 @@ dcr build --debug --clean
|
|||||||
|
|
||||||
- Profile flag (`--debug` / `--release`) can appear in any argument position (duplicates are rejected).
|
- Profile flag (`--debug` / `--release`) can appear in any argument position (duplicates are rejected).
|
||||||
- Unknown profile flags return an error.
|
- Unknown profile flags return an error.
|
||||||
|
- `--target <triple>` builds for specified target (short names: `linux`, `macos`, `windows`).
|
||||||
|
- If no `--target`, builds for `build.targets` or native.
|
||||||
- Incremental rebuild checks source/object mtime and tracked header dependencies.
|
- Incremental rebuild checks source/object mtime and tracked header dependencies.
|
||||||
- `--force` skips build cache checks and recompiles.
|
- `--force` skips build cache checks and recompiles.
|
||||||
- `--clean` removes `target/<profile>` and `build.clean` paths before building.
|
- `--clean` removes `target/<profile>` and `build.clean` paths before building.
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ Builds the project and runs the resulting binary.
|
|||||||
dcr run
|
dcr run
|
||||||
dcr run --debug
|
dcr run --debug
|
||||||
dcr run --release
|
dcr run --release
|
||||||
|
dcr run --target linux --release
|
||||||
dcr run --release --force
|
dcr run --release --force
|
||||||
dcr run --debug --clean
|
dcr run --debug --clean
|
||||||
```
|
```
|
||||||
@@ -24,6 +25,7 @@ dcr run --debug --clean
|
|||||||
|
|
||||||
- If `build.kind = "staticlib"` or `build.kind = "sharedlib"`, `run` exits with error.
|
- If `build.kind = "staticlib"` or `build.kind = "sharedlib"`, `run` exits with error.
|
||||||
- The profile is selected from the first argument.
|
- The profile is selected from the first argument.
|
||||||
|
- `--target <triple>` runs the binary for specified target (short names: `linux`, `macos`, `windows`).
|
||||||
- `--force` skips build cache checks and recompiles.
|
- `--force` skips build cache checks and recompiles.
|
||||||
- `--clean` removes `target/<profile>` and `build.clean` paths before building.
|
- `--clean` removes `target/<profile>` and `build.clean` paths before building.
|
||||||
|
|
||||||
|
|||||||
44
docs/commands/dcr-test.md
Normal file
44
docs/commands/dcr-test.md
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# dcr test
|
||||||
|
|
||||||
|
Runs the project's test suite.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```sh
|
||||||
|
dcr test
|
||||||
|
dcr test --release
|
||||||
|
dcr test --target linux
|
||||||
|
dcr test --init
|
||||||
|
```
|
||||||
|
|
||||||
|
## What `test` does
|
||||||
|
|
||||||
|
1. Builds the project with the specified profile/target.
|
||||||
|
2. Compiles test files in `tests/` (e.g., `tests/test.c`) into a test binary.
|
||||||
|
3. Runs the test binary and parses output for PASS/SKIP/FAIL results.
|
||||||
|
4. Reports summary with colored output.
|
||||||
|
|
||||||
|
## Test Structure
|
||||||
|
|
||||||
|
DCR uses a simple test framework:
|
||||||
|
|
||||||
|
- Header: `tests/dcr_test.h` (generated by `dcr test --init`)
|
||||||
|
- Test file: `tests/test.c` (template generated by `dcr test --init`)
|
||||||
|
- Macros: `TEST(name)`, `TEST_CASE(name)`, `EXPECT(condition)`, `SKIP(reason)`
|
||||||
|
- Output: `[PASS] test_name`, `[FAIL] test_name`, or `[SKIP] test_name`
|
||||||
|
|
||||||
|
## Config values used
|
||||||
|
|
||||||
|
- `package.name`
|
||||||
|
- `build.compiler`, `build.language`, `build.standard`
|
||||||
|
- `build.cflags`, `build.ldflags`
|
||||||
|
- `build.debug` / `build.release`
|
||||||
|
- `build.targets` (if specified)
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
- Test binary is linked with the main project (for lib projects) or standalone.
|
||||||
|
- `--init` creates `tests/dcr_test.h` and `tests/test.c` if missing.
|
||||||
|
- Tests run in release mode by default for performance.
|
||||||
|
- Custom test logic can be added by editing `tests/test.c`.
|
||||||
|
- Fails if no `tests/test.c` exists (run `dcr test --init` first).
|
||||||
@@ -9,6 +9,8 @@ standard = "c11"
|
|||||||
compiler = "clang"
|
compiler = "clang"
|
||||||
kind = "bin"
|
kind = "bin"
|
||||||
# optional:
|
# optional:
|
||||||
|
# inherit = true # Inherit from base (default true)
|
||||||
|
# targets = ["linux", "macos"] # Multiple targets to build
|
||||||
# target = "./dist"
|
# target = "./dist"
|
||||||
# platform = "x86_64"
|
# platform = "x86_64"
|
||||||
# cflags = ["-Wall"]
|
# cflags = ["-Wall"]
|
||||||
@@ -30,6 +32,8 @@ kind = "bin"
|
|||||||
- `standard` (string, required): language standard passed to compiler.
|
- `standard` (string, required): language standard passed to compiler.
|
||||||
- `compiler` (string, required): compiler command (for example `clang`, `gcc`, `cl`).
|
- `compiler` (string, required): compiler command (for example `clang`, `gcc`, `cl`).
|
||||||
- `kind` (string, required): `bin`, `staticlib`, or `sharedlib`.
|
- `kind` (string, required): `bin`, `staticlib`, or `sharedlib`.
|
||||||
|
- `inherit` (bool, optional): inherit settings from base `[build]` (default `true`). If `false`, only use target/profile specific settings.
|
||||||
|
- `targets` (string array, optional): list of targets to build simultaneously. Supports short names (`linux`, `macos`, `windows`).
|
||||||
- `target` (string, optional): custom output directory for final artifact.
|
- `target` (string, optional): custom output directory for final artifact.
|
||||||
- `platform` (string, optional): architecture hint for compiler (used for `-march` or `/arch`).
|
- `platform` (string, optional): architecture hint for compiler (used for `-march` or `/arch`).
|
||||||
- `cflags` (string array, optional): extra compile flags.
|
- `cflags` (string array, optional): extra compile flags.
|
||||||
@@ -82,6 +86,15 @@ Step notes:
|
|||||||
Profile tables inherit all values from `[build]`. Any field present in the profile table replaces the base value.
|
Profile tables inherit all values from `[build]`. Any field present in the profile table replaces the base value.
|
||||||
Array fields (like `cflags`/`ldflags`) are appended to the base array.
|
Array fields (like `cflags`/`ldflags`) are appended to the base array.
|
||||||
|
|
||||||
|
Target tables override profile and base settings for specific targets. Full inheritance order:
|
||||||
|
1. `[build.<target>.<profile>]`
|
||||||
|
2. `[build.<profile>.<target>]`
|
||||||
|
3. `[build.<target>]`
|
||||||
|
4. `[build.<profile>]`
|
||||||
|
5. `[build]`
|
||||||
|
|
||||||
|
If custom `cflags` are set (non-empty), default compiler flags are disabled.
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[build.debug]
|
[build.debug]
|
||||||
cflags = ["-g3"]
|
cflags = ["-g3"]
|
||||||
@@ -89,6 +102,29 @@ cflags = ["-g3"]
|
|||||||
[build.release]
|
[build.release]
|
||||||
cflags = ["-O3"]
|
cflags = ["-O3"]
|
||||||
ldflags = ["-s"]
|
ldflags = ["-s"]
|
||||||
|
|
||||||
|
# Target-specific overrides (applied after profile)
|
||||||
|
[build.linux]
|
||||||
|
compiler = "gcc"
|
||||||
|
cflags = ["-march=x86_64"]
|
||||||
|
|
||||||
|
[build.macos]
|
||||||
|
compiler = "clang"
|
||||||
|
cflags = ["-arch", "x86_64"]
|
||||||
|
|
||||||
|
# Full inheritance example
|
||||||
|
[build.linux.release]
|
||||||
|
cflags = ["-O3", "-march=native"] # Overrides profile and base
|
||||||
|
|
||||||
|
[build.release.linux]
|
||||||
|
ldflags = ["-static"] # Alternative order
|
||||||
|
|
||||||
|
[build.windows.debug]
|
||||||
|
compiler = "x86_64-w64-mingw32-gcc"
|
||||||
|
cflags = [] # Empty to disable defaults
|
||||||
|
|
||||||
|
[build.release]
|
||||||
|
inherit = false # No inheritance, only explicit settings
|
||||||
```
|
```
|
||||||
|
|
||||||
## Toolchain section
|
## Toolchain section
|
||||||
|
|||||||
@@ -43,7 +43,10 @@ Workspace-only root:
|
|||||||
|
|
||||||
## Optional keys
|
## Optional keys
|
||||||
|
|
||||||
|
- `build.inherit`
|
||||||
|
- `build.targets`
|
||||||
- `build.target`
|
- `build.target`
|
||||||
|
- `build.platform`
|
||||||
- `build.cflags`
|
- `build.cflags`
|
||||||
- `build.ldflags`
|
- `build.ldflags`
|
||||||
- `build.exclude`
|
- `build.exclude`
|
||||||
@@ -58,7 +61,11 @@ Workspace-only root:
|
|||||||
- `build.clean`
|
- `build.clean`
|
||||||
- `build.debug`
|
- `build.debug`
|
||||||
- `build.release`
|
- `build.release`
|
||||||
|
- `build.<target>` (target-specific overrides)
|
||||||
- dependency fields (`include`, `lib`, `libs`, `system`)
|
- dependency fields (`include`, `lib`, `libs`, `system`)
|
||||||
- `[toolchain]` overrides (`cc`, `cxx`, `as`, `ar`, `ld`, `uic`, `moc`, `rcc`)
|
- `[toolchain]` overrides (`cc`, `cxx`, `as`, `ar`, `ld`, `uic`, `moc`, `rcc`)
|
||||||
|
- `[toolchain.<target>]` (target-specific toolchain)
|
||||||
- `[workspace]` members
|
- `[workspace]` members
|
||||||
|
- `[workspace.<target>]` (target-specific workspace)
|
||||||
- `[run]` overrides (`cmd`)
|
- `[run]` overrides (`cmd`)
|
||||||
|
- `[run.<target>]` (target-specific run)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ DCR picks a backend from `build.compiler`:
|
|||||||
- Source files are found recursively in `src/` based on `build.language`.
|
- Source files are found recursively in `src/` based on `build.language`.
|
||||||
- `build.roots` and `build.src_disable` can replace the default `src/` root.
|
- `build.roots` and `build.src_disable` can replace the default `src/` root.
|
||||||
- Mixed language builds use arrays, for example `build.language = ["c", "asm"]`.
|
- Mixed language builds use arrays, for example `build.language = ["c", "asm"]`.
|
||||||
- Each source is compiled to `target/<profile>/obj/<relative-path>.o` (`.obj` on MSVC).
|
- Each source is compiled to `target/<target>/<profile>/obj/<relative-path>.o` (`.obj` on MSVC, where `<target>` is `native` or target triple).
|
||||||
- Recompile happens when source mtime is newer than object mtime.
|
- Recompile happens when source mtime is newer than object mtime.
|
||||||
- `build.exclude` removes paths from source/header collection; `build.include` re-allows matching paths and has priority over `exclude`.
|
- `build.exclude` removes paths from source/header collection; `build.include` re-allows matching paths and has priority over `exclude`.
|
||||||
|
|
||||||
@@ -35,6 +35,8 @@ MSVC:
|
|||||||
- `debug`: `/Od /Zi /W4 /DDCR_DEBUG /Oy-`
|
- `debug`: `/Od /Zi /W4 /DDCR_DEBUG /Oy-`
|
||||||
- `release`: `/O2 /DNDEBUG`
|
- `release`: `/O2 /DNDEBUG`
|
||||||
|
|
||||||
|
Note: If custom `cflags` are set in `dcr.toml`, default profile flags are disabled to allow full control.
|
||||||
|
|
||||||
## Platform hint
|
## Platform hint
|
||||||
|
|
||||||
If `build.platform` is set, DCR passes it as an architecture hint:
|
If `build.platform` is set, DCR passes it as an architecture hint:
|
||||||
|
|||||||
201
docs/dependencies-and-build/cross-compilation.md
Normal file
201
docs/dependencies-and-build/cross-compilation.md
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
# Cross-compilation and Targets
|
||||||
|
|
||||||
|
DCR supports cross-compilation to different platforms using the `--target` flag. This allows building your project for architectures and operating systems different from the host.
|
||||||
|
|
||||||
|
## Basic Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Build for a specific target
|
||||||
|
dcr build --target x86_64-unknown-linux-gnu --release
|
||||||
|
|
||||||
|
# Short names for common platforms
|
||||||
|
dcr build --target linux --release # x86_64-unknown-linux-gnu
|
||||||
|
dcr build --target macos --release # x86_64-apple-darwin
|
||||||
|
dcr build --target windows --release # x86_64-pc-windows-msvc
|
||||||
|
|
||||||
|
# Run for a specific target
|
||||||
|
dcr run --target linux --release
|
||||||
|
```
|
||||||
|
|
||||||
|
## Supported Targets
|
||||||
|
|
||||||
|
### Short Names
|
||||||
|
- `linux` → `x86_64-unknown-linux-gnu`
|
||||||
|
- `macos` → `x86_64-apple-darwin`
|
||||||
|
- `windows` → `x86_64-pc-windows-msvc`
|
||||||
|
|
||||||
|
### Full Target Triples
|
||||||
|
DCR supports any valid target triple in the format `<arch>-<vendor>-<os>-<abi>`. Common examples:
|
||||||
|
- `x86_64-unknown-linux-gnu`
|
||||||
|
- `aarch64-linux-gnu`
|
||||||
|
- `x86_64-apple-darwin`
|
||||||
|
- `aarch64-apple-darwin`
|
||||||
|
- `x86_64-pc-windows-msvc`
|
||||||
|
- `i686-pc-windows-gnu`
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
### Multiple Targets
|
||||||
|
|
||||||
|
Configure multiple targets to build simultaneously:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[build.targets]
|
||||||
|
targets = ["linux", "macos", "windows"]
|
||||||
|
|
||||||
|
# Or per profile
|
||||||
|
[build.release.targets]
|
||||||
|
targets = ["linux", "macos"]
|
||||||
|
```
|
||||||
|
|
||||||
|
If no `--target` is specified, DCR builds for all targets in `build.targets` (or native if empty).
|
||||||
|
|
||||||
|
### Target-Specific Settings
|
||||||
|
|
||||||
|
Override settings for specific targets:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[build.linux]
|
||||||
|
compiler = "gcc"
|
||||||
|
cflags = ["-Wall", "-O2"]
|
||||||
|
|
||||||
|
[build.macos]
|
||||||
|
compiler = "clang"
|
||||||
|
cflags = ["-Wall", "-O2", "-arch", "x86_64"]
|
||||||
|
|
||||||
|
[build.windows]
|
||||||
|
compiler = "x86_64-w64-mingw32-gcc"
|
||||||
|
ldflags = ["-static"]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Target-Specific Toolchain
|
||||||
|
|
||||||
|
Configure toolchain per target:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[toolchain.linux]
|
||||||
|
cc = "gcc"
|
||||||
|
ld = "ld"
|
||||||
|
|
||||||
|
[toolchain.macos]
|
||||||
|
cc = "clang"
|
||||||
|
ld = "ld"
|
||||||
|
|
||||||
|
[toolchain.windows]
|
||||||
|
cc = "x86_64-w64-mingw32-gcc"
|
||||||
|
ld = "x86_64-w64-mingw32-ld"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Target-Specific Run Commands
|
||||||
|
|
||||||
|
Use custom run commands per target:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[run.linux]
|
||||||
|
cmd = "./target/linux/release/myapp"
|
||||||
|
|
||||||
|
[run.macos]
|
||||||
|
cmd = "open ./target/macos/release/myapp.app"
|
||||||
|
|
||||||
|
[run.windows]
|
||||||
|
cmd = "wine ./target/windows/release/myapp.exe"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Workspace and Dependencies Inheritance
|
||||||
|
|
||||||
|
Workspace and dependencies sections also support target/profile inheritance:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[workspace.linux]
|
||||||
|
members = [
|
||||||
|
{ name = "lib1", path = "libs/lib1" },
|
||||||
|
]
|
||||||
|
|
||||||
|
[dependencies.linux]
|
||||||
|
sdl2 = { system = true, include = ["/usr/include/SDL2"] }
|
||||||
|
|
||||||
|
[dependencies.windows]
|
||||||
|
sdl2 = { system = true, include = ["C:/SDL2/include"] }
|
||||||
|
```
|
||||||
|
|
||||||
|
Order: `workspace.target.profile` → `workspace.profile.target` → `workspace.target` → `workspace.profile` → `workspace`.
|
||||||
|
|
||||||
|
Add `inherit = false` to disable inheritance in any section.
|
||||||
|
|
||||||
|
Settings are applied in order:
|
||||||
|
1. `[build.<target>]`
|
||||||
|
2. `[build.<profile>]`
|
||||||
|
3. `[build]`
|
||||||
|
|
||||||
|
### Toolchain Configuration
|
||||||
|
|
||||||
|
For cross-compilation, configure toolchains:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[toolchain]
|
||||||
|
cc = "aarch64-linux-gnu-gcc"
|
||||||
|
cxx = "aarch64-linux-gnu-g++"
|
||||||
|
ar = "aarch64-linux-gnu-ar"
|
||||||
|
ld = "aarch64-linux-gnu-ld"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Output Structure
|
||||||
|
|
||||||
|
Build outputs are organized by target:
|
||||||
|
|
||||||
|
```
|
||||||
|
target/
|
||||||
|
├── native/
|
||||||
|
│ ├── debug/
|
||||||
|
│ └── release/
|
||||||
|
├── x86_64-unknown-linux-gnu/
|
||||||
|
│ ├── debug/
|
||||||
|
│ └── release/
|
||||||
|
└── aarch64-linux-gnu/
|
||||||
|
├── debug/
|
||||||
|
└── release/
|
||||||
|
```
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- Cross-compilation requires appropriate toolchains installed (e.g., `aarch64-linux-gnu-gcc` on Arch Linux).
|
||||||
|
- For Windows targets on Linux, install MinGW: `pacman -S mingw-w64-gcc`.
|
||||||
|
- For macOS targets on Linux, use `osxcross` or similar.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
### ARM Linux Build
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install toolchain (Arch Linux)
|
||||||
|
pacman -S aarch64-linux-gnu-gcc
|
||||||
|
|
||||||
|
# Configure
|
||||||
|
echo '[build.aarch64-linux-gnu]
|
||||||
|
compiler = "aarch64-linux-gnu-gcc"' >> dcr.toml
|
||||||
|
|
||||||
|
# Build
|
||||||
|
dcr build --target aarch64-linux-gnu --release
|
||||||
|
```
|
||||||
|
|
||||||
|
### Windows Build on Linux
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install toolchain (Arch Linux)
|
||||||
|
pacman -S mingw-w64-gcc
|
||||||
|
|
||||||
|
# Configure
|
||||||
|
echo '[build.windows]
|
||||||
|
compiler = "x86_64-w64-mingw32-gcc"' >> dcr.toml
|
||||||
|
|
||||||
|
# Build
|
||||||
|
dcr build --target windows --release
|
||||||
|
```
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
- **Toolchain not found**: Ensure the compiler is installed and in PATH, or configure `[toolchain]` in `dcr.toml`. For Arch Linux: `pacman -S aarch64-linux-gnu-gcc` for ARM, `pacman -S mingw-w64-gcc` for Windows cross-compilation.
|
||||||
|
- **Linking errors**: Check `ldflags` and library paths for cross-compilation.
|
||||||
|
- **Header issues**: Include paths may differ; use target-specific `cflags`.
|
||||||
|
|
||||||
|
For more help, see [Troubleshooting map](troubleshooting-map.md).
|
||||||
@@ -2,25 +2,39 @@
|
|||||||
|
|
||||||
Dependencies are defined in `dcr.toml` under `[dependencies]`.
|
Dependencies are defined in `dcr.toml` under `[dependencies]`.
|
||||||
|
|
||||||
## Full example
|
## Full example (Path)
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fmt = { path = "./third_party/fmt", include = ["include"], lib = ["lib"], libs = ["fmt"] }
|
fmt = { path = "./third_party/fmt", include = ["include"], lib = ["lib"], libs = ["fmt"] }
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Full example (Git)
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[dependencies]
|
||||||
|
json = { git = "https://github.com/nlohmann/json", tag = "v3.11.2" }
|
||||||
|
```
|
||||||
|
|
||||||
## Field reference
|
## Field reference
|
||||||
|
|
||||||
- `path`: required dependency root path.
|
- `path`: local path to dependency root.
|
||||||
|
- `git`: URL of Git repository.
|
||||||
|
- `branch`: Git branch name.
|
||||||
|
- `tag`: Git tag name.
|
||||||
|
- `rev`: Git commit SHA.
|
||||||
- `include`: optional include subpaths (absolute or relative to dep root).
|
- `include`: optional include subpaths (absolute or relative to dep root).
|
||||||
- `lib`: optional library subpaths (absolute or relative to dep root).
|
- `lib`: optional library subpaths (absolute or relative to dep root).
|
||||||
- `libs`: optional linker library names.
|
- `libs`: optional linker library names.
|
||||||
|
|
||||||
## Common valid compact form
|
## Common valid compact forms
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
mylib = { path = "./libs/mylib" }
|
mylib = { path = "./libs/mylib" }
|
||||||
|
gitlib = { git = "https://github.com/user/repo" }
|
||||||
|
# Shortest form for path
|
||||||
|
simple = "./libs/simple"
|
||||||
```
|
```
|
||||||
|
|
||||||
In this form DCR will try defaults for include/lib dirs and use `mylib` as the linker library name.
|
In these forms DCR will try defaults for include/lib dirs and use the dependency name as the linker library name.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Target directory
|
# Target directory
|
||||||
|
|
||||||
By default, DCR writes final artifacts to `target/<profile>/`.
|
By default, DCR writes final artifacts to `target/<target>/<profile>/` (where `<target>` is `native` or target triple).
|
||||||
|
|
||||||
You can override this with `build.target`:
|
You can override this with `build.target`:
|
||||||
|
|
||||||
@@ -20,4 +20,4 @@ target = "./dist"
|
|||||||
|
|
||||||
## Important detail
|
## Important detail
|
||||||
|
|
||||||
`build.target` changes only the final artifact location. Object cache and dependency sync directories still use `target/<profile>/...`.
|
`build.target` changes only the final artifact location. Object cache and dependency sync directories still use `target/<target>/<profile>/...`.
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ Debug (default):
|
|||||||
dcr build
|
dcr build
|
||||||
# or
|
# or
|
||||||
dcr build --debug
|
dcr build --debug
|
||||||
|
dcr build --target linux --debug
|
||||||
dcr build --debug --clean
|
dcr build --debug --clean
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ Release:
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
dcr build --release
|
dcr build --release
|
||||||
|
dcr build --target windows --release
|
||||||
```
|
```
|
||||||
|
|
||||||
## Run
|
## Run
|
||||||
@@ -22,7 +24,9 @@ dcr build --release
|
|||||||
```sh
|
```sh
|
||||||
dcr run
|
dcr run
|
||||||
# or
|
# or
|
||||||
|
dcr run --target macos
|
||||||
dcr run --release
|
dcr run --release
|
||||||
|
dcr run --target linux --release
|
||||||
dcr run --release --force
|
dcr run --release --force
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -49,4 +53,5 @@ dcr clean --release --all
|
|||||||
- Build profile flag (`--debug` / `--release`) can be passed in any argument position.
|
- Build profile flag (`--debug` / `--release`) can be passed in any argument position.
|
||||||
- Unknown profile flags produce an error.
|
- Unknown profile flags produce an error.
|
||||||
- In workspace root, `clean --all` cleans all member projects.
|
- In workspace root, `clean --all` cleans all member projects.
|
||||||
- `--clean` for `build`/`run` removes `target/<profile>` and paths from `build.clean`.
|
- `--target` builds/runs for specified target (short names: `linux`, `macos`, `windows`).
|
||||||
|
- `--clean` for `build`/`run` removes `target/<target>/<profile>` and paths from `build.clean`.
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ project/
|
|||||||
- `dcr.toml`: main project configuration.
|
- `dcr.toml`: main project configuration.
|
||||||
- `dcr.lock`: generated lock file for resolved path dependencies.
|
- `dcr.lock`: generated lock file for resolved path dependencies.
|
||||||
- `src/`: recursively scanned source directory.
|
- `src/`: recursively scanned source directory.
|
||||||
- `target/<profile>/obj/`: cached object files for incremental rebuild.
|
- `target/<target>/<profile>/obj/`: cached object files for incremental rebuild (where `<target>` is `native` or target triple).
|
||||||
- `target/<profile>/deps/`: synchronized copies of path dependencies.
|
- `target/<target>/<profile>/deps/`: synchronized copies of path dependencies.
|
||||||
- `target/<profile>/<name>` (or `.exe` on Windows): output for `kind = "bin"`.
|
- `target/<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"`.
|
- `target/<target>/<profile>/lib<name>.a` (or `<name>.lib` on Windows): output for `kind = "staticlib"`.
|
||||||
- `target/<profile>/lib<name>.so` (or `.dylib` on macOS, `<name>.dll` on Windows): output for `kind = "sharedlib"`.
|
- `target/<target>/<profile>/lib<name>.so` (or `.dylib` on macOS, `<name>.dll` on Windows): output for `kind = "sharedlib"`.
|
||||||
|
|
||||||
If `build.target` is set, the final artifact is written to that custom directory, while object cache still stays in `target/<profile>/obj`.
|
If `build.target` is set, the final artifact is written to that custom directory, while object cache still stays in `target/<target>/<profile>/obj`.
|
||||||
|
|||||||
199
src/cli/add.rs
Normal file
199
src/cli/add.rs
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
use crate::core::config::Config;
|
||||||
|
use crate::utils::fs::find_project_root;
|
||||||
|
use crate::utils::log::error;
|
||||||
|
use crate::utils::text::{BOLD_GREEN, colored};
|
||||||
|
use toml::Value;
|
||||||
|
use toml::map::Map;
|
||||||
|
|
||||||
|
pub struct AddArgs {
|
||||||
|
pub name: String,
|
||||||
|
pub path: Option<String>,
|
||||||
|
pub git: Option<String>,
|
||||||
|
pub branch: Option<String>,
|
||||||
|
pub tag: Option<String>,
|
||||||
|
pub rev: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add(args: &[String]) -> i32 {
|
||||||
|
let add_args = match parse_add_args(args) {
|
||||||
|
Ok(a) => a,
|
||||||
|
Err(code) => return code,
|
||||||
|
};
|
||||||
|
|
||||||
|
let start_dir = match std::env::current_dir() {
|
||||||
|
Ok(dir) => dir,
|
||||||
|
Err(_) => {
|
||||||
|
error("Failed to determine current directory");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let root = match find_project_root(&start_dir) {
|
||||||
|
Ok(Some(dir)) => dir,
|
||||||
|
Ok(None) => {
|
||||||
|
error("dcr.toml file not found");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
error("Failed to find project root");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut config = match Config::open(&root.join("dcr.toml").to_string_lossy()) {
|
||||||
|
Ok(cfg) => cfg,
|
||||||
|
Err(err) => {
|
||||||
|
error(&err.to_string());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let dep_value = if let Some(git_url) = add_args.git {
|
||||||
|
if add_args.branch.is_none() && add_args.tag.is_none() && add_args.rev.is_none() {
|
||||||
|
let mut table = Map::new();
|
||||||
|
table.insert("git".to_string(), Value::String(git_url));
|
||||||
|
Value::Table(table)
|
||||||
|
} else {
|
||||||
|
let mut table = Map::new();
|
||||||
|
table.insert("git".to_string(), Value::String(git_url));
|
||||||
|
if let Some(b) = add_args.branch {
|
||||||
|
table.insert("branch".to_string(), Value::String(b));
|
||||||
|
}
|
||||||
|
if let Some(t) = add_args.tag {
|
||||||
|
table.insert("tag".to_string(), Value::String(t));
|
||||||
|
}
|
||||||
|
if let Some(r) = add_args.rev {
|
||||||
|
table.insert("rev".to_string(), Value::String(r));
|
||||||
|
}
|
||||||
|
Value::Table(table)
|
||||||
|
}
|
||||||
|
} else if let Some(path) = add_args.path {
|
||||||
|
Value::String(path)
|
||||||
|
} else {
|
||||||
|
error("Dependency source (path or git) must be provided");
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
let key = format!("dependencies.{}", add_args.name);
|
||||||
|
if let Err(err) = config.edit(&key, dep_value) {
|
||||||
|
error(&format!("Failed to update dcr.toml: {}", err));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
println!(
|
||||||
|
" {} dependency `{}` to dcr.toml",
|
||||||
|
colored("Added", BOLD_GREEN),
|
||||||
|
add_args.name
|
||||||
|
);
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_add_args(args: &[String]) -> Result<AddArgs, i32> {
|
||||||
|
if args.is_empty() {
|
||||||
|
error("Usage: dcr add <name> <source> [--branch <branch> | --tag <tag> | --rev <rev>]");
|
||||||
|
error("Sources:");
|
||||||
|
error(" user/repo -> github.com/user/repo");
|
||||||
|
error(" github:user/repo -> github.com/user/repo");
|
||||||
|
error(" gitlab:user/repo -> gitlab.com/user/repo");
|
||||||
|
error(" git:host.com/user/repo -> host.com/user/repo");
|
||||||
|
error(" path:./path/to/lib -> local path");
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut name = String::new();
|
||||||
|
let source_spec: String;
|
||||||
|
let mut branch = None;
|
||||||
|
let mut tag = None;
|
||||||
|
let mut rev = None;
|
||||||
|
|
||||||
|
let mut iter = args.iter();
|
||||||
|
if let Some(n) = iter.next() {
|
||||||
|
if n.starts_with("--") {
|
||||||
|
error("First argument must be the dependency name");
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
name = n.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(s) = iter.next() {
|
||||||
|
if s.starts_with("--") {
|
||||||
|
error("Second argument must be the dependency source");
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
source_spec = s.clone();
|
||||||
|
} else {
|
||||||
|
error("Dependency source is required");
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
while let Some(arg) = iter.next() {
|
||||||
|
match arg.as_str() {
|
||||||
|
"--branch" => {
|
||||||
|
branch = iter.next().cloned();
|
||||||
|
if branch.is_none() {
|
||||||
|
error("--branch requires a value");
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"--tag" => {
|
||||||
|
tag = iter.next().cloned();
|
||||||
|
if tag.is_none() {
|
||||||
|
error("--tag requires a value");
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"--rev" => {
|
||||||
|
rev = iter.next().cloned();
|
||||||
|
if rev.is_none() {
|
||||||
|
error("--rev requires a value");
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
error(&format!("Unknown argument: {}", arg));
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut path = None;
|
||||||
|
let mut git = None;
|
||||||
|
|
||||||
|
if let Some(p) = source_spec.strip_prefix("path:") {
|
||||||
|
path = Some(p.to_string());
|
||||||
|
} else if let Some(g) = source_spec.strip_prefix("github:") {
|
||||||
|
git = Some(format!("https://github.com/{}", g));
|
||||||
|
} else if let Some(g) = source_spec.strip_prefix("gitlab:") {
|
||||||
|
git = Some(format!("https://gitlab.com/{}", g));
|
||||||
|
} else if let Some(g) = source_spec.strip_prefix("git:") {
|
||||||
|
if g.contains('/') && !g.contains('.') {
|
||||||
|
// git:user/repo -> default to github
|
||||||
|
git = Some(format!("https://github.com/{}", g));
|
||||||
|
} else {
|
||||||
|
// git:host.com/user/repo
|
||||||
|
let url = if g.starts_with("http") || g.starts_with("git@") {
|
||||||
|
g.to_string()
|
||||||
|
} else {
|
||||||
|
format!("https://{}", g)
|
||||||
|
};
|
||||||
|
git = Some(url);
|
||||||
|
}
|
||||||
|
} else if source_spec.starts_with("http://")
|
||||||
|
|| source_spec.starts_with("https://")
|
||||||
|
|| source_spec.starts_with("git@")
|
||||||
|
{
|
||||||
|
git = Some(source_spec);
|
||||||
|
} else {
|
||||||
|
error("Source must have a prefix (path:, git:, github:, gitlab:) or be a full URL");
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(AddArgs {
|
||||||
|
name,
|
||||||
|
path,
|
||||||
|
git,
|
||||||
|
branch,
|
||||||
|
tag,
|
||||||
|
rev,
|
||||||
|
})
|
||||||
|
}
|
||||||
340
src/cli/build.rs
340
src/cli/build.rs
@@ -6,7 +6,7 @@ use crate::core::config::Config;
|
|||||||
use crate::core::deps::resolve_deps;
|
use crate::core::deps::resolve_deps;
|
||||||
use crate::core::workspace::parse_workspace;
|
use crate::core::workspace::parse_workspace;
|
||||||
use crate::utils::fs::{check_dir, find_project_root};
|
use crate::utils::fs::{check_dir, find_project_root};
|
||||||
use crate::utils::log::error;
|
use crate::utils::log::{error, warn};
|
||||||
use crate::utils::text::{BOLD_GREEN, colored};
|
use crate::utils::text::{BOLD_GREEN, colored};
|
||||||
use glob::glob;
|
use glob::glob;
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
@@ -33,17 +33,31 @@ pub fn build(args: &[String]) -> i32 {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let flags = match parse_build_run_flags(args) {
|
let mut flags = match parse_build_run_flags(args) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(code) => return code,
|
Err(code) => return code,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If no target specified, use default host target for target-specific config
|
||||||
|
if flags.target.is_none() {
|
||||||
|
let default_target = if cfg!(target_os = "linux") {
|
||||||
|
"x86_64-unknown-linux-gnu"
|
||||||
|
} else if cfg!(target_os = "macos") {
|
||||||
|
"x86_64-apple-darwin"
|
||||||
|
} else if cfg!(target_os = "windows") {
|
||||||
|
"x86_64-pc-windows-msvc"
|
||||||
|
} else {
|
||||||
|
"unknown"
|
||||||
|
};
|
||||||
|
flags.target = Some(default_target.to_string());
|
||||||
|
}
|
||||||
if flags.clean {
|
if flags.clean {
|
||||||
let mut clean_args = Vec::new();
|
let mut clean_args = Vec::new();
|
||||||
clean_args.push(format!("--{}", flags.profile));
|
clean_args.push(format!("--{}", flags.profile));
|
||||||
let _ = clean(&clean_args);
|
let _ = clean(&clean_args);
|
||||||
}
|
}
|
||||||
match with_dir(&root, || {
|
match with_dir(&root, || {
|
||||||
build_from_root(&root, &flags.profile, flags.force)
|
build_from_root(&root, &flags.profile, flags.target.as_deref(), flags.force)
|
||||||
}) {
|
}) {
|
||||||
Ok(()) => 0,
|
Ok(()) => 0,
|
||||||
Err(msg) => {
|
Err(msg) => {
|
||||||
@@ -126,18 +140,79 @@ fn profile_table<'a>(config: &'a Config, profile: &str) -> Option<&'a toml::valu
|
|||||||
.and_then(|v| v.as_table())
|
.and_then(|v| v.as_table())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_string_with_profile(config: &Config, field: &str, profile: &str) -> String {
|
fn get_config_value_raw(
|
||||||
let base = get_config_str(config, &format!("build.{field}"));
|
config: &Config,
|
||||||
let Some(table) = profile_table(config, profile) else {
|
section: &str,
|
||||||
return base;
|
field: &str,
|
||||||
};
|
profile: &str,
|
||||||
let value = table.get(field).and_then(|v| v.as_str()).unwrap_or("");
|
target: Option<&str>,
|
||||||
let trimmed = value.trim();
|
) -> Option<toml::Value> {
|
||||||
if trimmed.is_empty() {
|
// Order: target.profile, profile.target, target, profile, base
|
||||||
base
|
let keys = [
|
||||||
} else {
|
target.map(|t| {
|
||||||
trimmed.to_string()
|
format!(
|
||||||
|
"{}.{}.{}.{}",
|
||||||
|
section,
|
||||||
|
normalize_target_os(t),
|
||||||
|
profile,
|
||||||
|
field
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
target.map(|t| {
|
||||||
|
format!(
|
||||||
|
"{}.{}.{}.{}",
|
||||||
|
section,
|
||||||
|
profile,
|
||||||
|
normalize_target_os(t),
|
||||||
|
field
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
target.map(|t| format!("{}.{}.{}", section, normalize_target_os(t), field)),
|
||||||
|
Some(format!("{}.{}.{}", section, profile, field)),
|
||||||
|
Some(format!("{}.{}", section, field)),
|
||||||
|
];
|
||||||
|
for key in keys.into_iter().flatten() {
|
||||||
|
if let Some(val) = config.get(&key) {
|
||||||
|
return Some(val.clone());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_inherit(config: &Config, section: &str, profile: &str, target: Option<&str>) -> bool {
|
||||||
|
get_config_value_raw(config, section, "inherit", profile, target)
|
||||||
|
.and_then(|v| v.as_bool())
|
||||||
|
.unwrap_or(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_config_value(
|
||||||
|
config: &Config,
|
||||||
|
section: &str,
|
||||||
|
field: &str,
|
||||||
|
profile: &str,
|
||||||
|
target: Option<&str>,
|
||||||
|
) -> Option<String> {
|
||||||
|
get_config_value_raw(config, section, field, profile, target)
|
||||||
|
.and_then(|v| v.as_str().map(|s| s.trim().to_string()))
|
||||||
|
.filter(|s| !s.is_empty())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_string_with_profile_and_target(
|
||||||
|
config: &Config,
|
||||||
|
field: &str,
|
||||||
|
profile: &str,
|
||||||
|
target: Option<&str>,
|
||||||
|
) -> String {
|
||||||
|
if get_inherit(config, "build", profile, target) {
|
||||||
|
get_config_value(config, "build", field, profile, target)
|
||||||
|
.unwrap_or_else(|| get_config_str(config, &format!("build.{field}")))
|
||||||
|
} else {
|
||||||
|
get_config_value(config, "build", field, profile, target).unwrap_or_default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_string_with_profile(config: &Config, field: &str, profile: &str) -> String {
|
||||||
|
get_string_with_profile_and_target(config, field, profile, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_string_array(value: &toml::Value, key: &str) -> Result<Vec<String>, String> {
|
fn parse_string_array(value: &toml::Value, key: &str) -> Result<Vec<String>, String> {
|
||||||
@@ -154,21 +229,83 @@ fn parse_string_array(value: &toml::Value, key: &str) -> Result<Vec<String>, Str
|
|||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_list_with_profile(
|
fn get_list_with_profile_and_target(
|
||||||
config: &Config,
|
config: &Config,
|
||||||
field: &str,
|
field: &str,
|
||||||
profile: &str,
|
profile: &str,
|
||||||
|
target: Option<&str>,
|
||||||
) -> Result<Vec<String>, String> {
|
) -> Result<Vec<String>, String> {
|
||||||
let mut out = get_config_list(config, &format!("build.{field}"))?;
|
let inherit = get_inherit(config, "build", profile, target);
|
||||||
|
let mut out = if inherit {
|
||||||
|
get_config_list(config, &format!("build.{field}"))?
|
||||||
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
};
|
||||||
|
// Custom from target/profile
|
||||||
|
if let Some(val) = get_config_value_raw(config, "build", field, profile, target) {
|
||||||
|
if let Some(_arr) = val.as_array() {
|
||||||
|
let custom = parse_string_array(&val, &format!("build.{field}"))?;
|
||||||
|
if inherit {
|
||||||
|
out.extend(custom);
|
||||||
|
} else {
|
||||||
|
out = custom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if inherit {
|
||||||
|
// Legacy append
|
||||||
if let Some(table) = profile_table(config, profile)
|
if let Some(table) = profile_table(config, profile)
|
||||||
&& let Some(value) = table.get(field)
|
&& let Some(value) = table.get(field)
|
||||||
{
|
{
|
||||||
let mut extra = parse_string_array(value, &format!("build.{profile}.{field}"))?;
|
let mut extra = parse_string_array(value, &format!("build.{profile}.{field}"))?;
|
||||||
out.append(&mut extra);
|
out.append(&mut extra);
|
||||||
}
|
}
|
||||||
|
if let Some(t) = target {
|
||||||
|
let normalized_t = normalize_target_os(t);
|
||||||
|
if let Some(table) = profile_table(config, normalized_t)
|
||||||
|
&& let Some(value) = table.get(field)
|
||||||
|
{
|
||||||
|
let mut extra =
|
||||||
|
parse_string_array(value, &format!("build.{normalized_t}.{field}"))?;
|
||||||
|
out.append(&mut extra);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn test_normalize_target_os() {
|
||||||
|
assert_eq!(
|
||||||
|
super::normalize_target_os("linux"),
|
||||||
|
"x86_64-unknown-linux-gnu"
|
||||||
|
);
|
||||||
|
assert_eq!(super::normalize_target_os("macos"), "x86_64-apple-darwin");
|
||||||
|
assert_eq!(
|
||||||
|
super::normalize_target_os("windows"),
|
||||||
|
"x86_64-pc-windows-msvc"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
super::normalize_target_os("x86_64-unknown-linux-gnu"),
|
||||||
|
"x86_64-unknown-linux-gnu"
|
||||||
|
);
|
||||||
|
assert_eq!(super::normalize_target_os("unknown"), "unknown");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_list_with_profile(
|
||||||
|
config: &Config,
|
||||||
|
field: &str,
|
||||||
|
profile: &str,
|
||||||
|
) -> Result<Vec<String>, String> {
|
||||||
|
get_list_with_profile_and_target(config, field, profile, None)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_targets(config: &Config, profile: &str) -> Result<Vec<String>, String> {
|
||||||
|
get_list_with_profile(config, "targets", profile)
|
||||||
|
}
|
||||||
|
|
||||||
fn get_bool_with_profile(config: &Config, field: &str, profile: &str, default: bool) -> bool {
|
fn get_bool_with_profile(config: &Config, field: &str, profile: &str, default: bool) -> bool {
|
||||||
let base = config
|
let base = config
|
||||||
.get(&format!("build.{field}"))
|
.get(&format!("build.{field}"))
|
||||||
@@ -274,17 +411,18 @@ fn get_build_steps_with_profile(
|
|||||||
get_build_steps(config, &format!("build.{field}"))
|
get_build_steps(config, &format!("build.{field}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ensure_target_dirs(items: &[String], profile: &str, target_dir: Option<&str>) {
|
fn ensure_target_dirs(items: &[String], profile: &str, target_dir: Option<String>) {
|
||||||
if let Some(dir) = target_dir {
|
|
||||||
let _ = fs::create_dir_all(dir);
|
|
||||||
}
|
|
||||||
if !items.contains(&"target".to_string()) {
|
if !items.contains(&"target".to_string()) {
|
||||||
let _ = fs::create_dir("./target");
|
let _ = fs::create_dir("./target");
|
||||||
}
|
}
|
||||||
|
if let Some(dir) = &target_dir {
|
||||||
|
let _ = fs::create_dir_all(dir);
|
||||||
|
} else {
|
||||||
let target_items = check_dir(Some("target")).unwrap_or_default();
|
let target_items = check_dir(Some("target")).unwrap_or_default();
|
||||||
if !target_items.contains(&profile.to_string()) {
|
if !target_items.contains(&profile.to_string()) {
|
||||||
let _ = fs::create_dir(format!("./target/{profile}"));
|
let _ = fs::create_dir(format!("./target/{profile}"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_build(ctx: &BuildContext) -> Result<f64, String> {
|
fn run_build(ctx: &BuildContext) -> Result<f64, String> {
|
||||||
@@ -302,29 +440,60 @@ fn run_build(ctx: &BuildContext) -> Result<f64, String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_from_root(root: &Path, profile: &str, force: bool) -> Result<(), String> {
|
#[allow(unused_variables)]
|
||||||
|
fn build_from_root(
|
||||||
|
root: &Path,
|
||||||
|
profile: &str,
|
||||||
|
target: Option<&str>,
|
||||||
|
force: bool,
|
||||||
|
) -> Result<(), String> {
|
||||||
let config = Config::open("./dcr.toml").map_err(|err| err.to_string())?;
|
let config = Config::open("./dcr.toml").map_err(|err| err.to_string())?;
|
||||||
let project_name = get_config_str(&config, "package.name");
|
let project_name = get_config_str(&config, "package.name");
|
||||||
|
let project_version = get_config_str(&config, "package.version");
|
||||||
|
|
||||||
|
let targets_to_build: Vec<Option<String>> = if let Some(t) = target {
|
||||||
|
vec![Some(normalize_target_os(t).to_string())]
|
||||||
|
} else {
|
||||||
|
let config_targets = get_targets(&config, profile)?;
|
||||||
|
if config_targets.is_empty() {
|
||||||
|
vec![None]
|
||||||
|
} else {
|
||||||
|
config_targets
|
||||||
|
.into_iter()
|
||||||
|
.map(|t| Some(normalize_target_os(&t).to_string()))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
|
for (i, build_target) in targets_to_build.iter().enumerate() {
|
||||||
|
if targets_to_build.len() > 1 {
|
||||||
println!(
|
println!(
|
||||||
" Building project `{}`\n Profile: {}",
|
" Building target {} of {}: {}",
|
||||||
colored(&project_name, BOLD_GREEN),
|
i + 1,
|
||||||
colored(profile, BOLD_GREEN)
|
targets_to_build.len(),
|
||||||
|
build_target.as_ref().map_or("native", |t| t.as_str())
|
||||||
);
|
);
|
||||||
if let Some(workspace) = parse_workspace(&config, root)? {
|
} else {
|
||||||
build_workspace(&workspace, profile, force)?;
|
println!(
|
||||||
|
" Building project `{}`\n Profile: {}\n Target: {}",
|
||||||
|
colored(&project_name, BOLD_GREEN),
|
||||||
|
colored(profile, BOLD_GREEN),
|
||||||
|
colored(
|
||||||
|
build_target.as_ref().map_or("native", |t| t.as_str()),
|
||||||
|
BOLD_GREEN
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if let Some(workspace) = parse_workspace(&config, profile, build_target.as_deref(), root)? {
|
||||||
|
build_workspace(&workspace, profile, build_target.as_deref(), force)?;
|
||||||
let excludes: Vec<std::path::PathBuf> =
|
let excludes: Vec<std::path::PathBuf> =
|
||||||
workspace.members.iter().map(|m| m.path.clone()).collect();
|
workspace.members.iter().map(|m| m.path.clone()).collect();
|
||||||
build_project_at(root, profile, &excludes, force)?;
|
build_project_at(root, profile, build_target.as_deref(), &excludes, force)?;
|
||||||
let elapsed = ((start_time.elapsed().as_secs_f64() * 100.0).trunc()) / 100.0;
|
} else {
|
||||||
println!(
|
build_project_at(root, profile, build_target.as_deref(), &[], force)?;
|
||||||
" {} Build completed successfully in {} seconds",
|
}
|
||||||
colored("✔", BOLD_GREEN),
|
|
||||||
colored(&elapsed.to_string(), BOLD_GREEN)
|
|
||||||
);
|
|
||||||
return Ok(());
|
|
||||||
}
|
}
|
||||||
build_project_at(root, profile, &[], force)?;
|
|
||||||
let elapsed = ((start_time.elapsed().as_secs_f64() * 100.0).trunc()) / 100.0;
|
let elapsed = ((start_time.elapsed().as_secs_f64() * 100.0).trunc()) / 100.0;
|
||||||
println!(
|
println!(
|
||||||
" {} Build completed successfully in {} seconds",
|
" {} Build completed successfully in {} seconds",
|
||||||
@@ -337,10 +506,11 @@ fn build_from_root(root: &Path, profile: &str, force: bool) -> Result<(), String
|
|||||||
fn build_workspace(
|
fn build_workspace(
|
||||||
workspace: &crate::core::workspace::Workspace,
|
workspace: &crate::core::workspace::Workspace,
|
||||||
profile: &str,
|
profile: &str,
|
||||||
|
target: Option<&str>,
|
||||||
force: bool,
|
force: bool,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
for member in &workspace.members {
|
for member in &workspace.members {
|
||||||
build_project_at(&member.path, profile, &[], force)?;
|
build_project_at(&member.path, profile, target, &[], force)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -348,6 +518,7 @@ fn build_workspace(
|
|||||||
fn build_project_at(
|
fn build_project_at(
|
||||||
project_root: &Path,
|
project_root: &Path,
|
||||||
profile: &str,
|
profile: &str,
|
||||||
|
target: Option<&str>,
|
||||||
exclude_dirs: &[std::path::PathBuf],
|
exclude_dirs: &[std::path::PathBuf],
|
||||||
force: bool,
|
force: bool,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
@@ -359,29 +530,53 @@ fn build_project_at(
|
|||||||
let config = Config::open("./dcr.toml").map_err(|err| err.to_string())?;
|
let config = Config::open("./dcr.toml").map_err(|err| err.to_string())?;
|
||||||
let project_name = get_config_str(&config, "package.name");
|
let project_name = get_config_str(&config, "package.name");
|
||||||
let project_version = get_config_str(&config, "package.version");
|
let project_version = get_config_str(&config, "package.version");
|
||||||
let project_compiler = get_string_with_profile(&config, "compiler", profile);
|
let build_target_config = get_string_with_profile(&config, "target", profile);
|
||||||
|
let build_target = target.or(if build_target_config.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(build_target_config.as_str())
|
||||||
|
});
|
||||||
|
let project_compiler =
|
||||||
|
get_string_with_profile_and_target(&config, "compiler", profile, build_target);
|
||||||
let build_language = get_language_with_profile(&config, profile)?;
|
let build_language = get_language_with_profile(&config, profile)?;
|
||||||
let build_standard = get_string_with_profile(&config, "standard", profile);
|
let build_standard =
|
||||||
let build_target = get_string_with_profile(&config, "target", profile);
|
get_string_with_profile_and_target(&config, "standard", profile, build_target);
|
||||||
let build_kind = get_string_with_profile(&config, "kind", profile);
|
let build_kind = get_string_with_profile_and_target(&config, "kind", profile, build_target);
|
||||||
let build_platform = get_string_with_profile(&config, "platform", profile);
|
let build_platform =
|
||||||
let tc_cc = get_config_opt(&config, "toolchain.cc");
|
get_string_with_profile_and_target(&config, "platform", profile, build_target);
|
||||||
let tc_cxx = get_config_opt(&config, "toolchain.cxx");
|
let tc_cc = get_config_value(&config, "toolchain", "cc", profile, build_target)
|
||||||
let tc_as = get_config_opt(&config, "toolchain.as");
|
.or_else(|| get_config_opt(&config, "toolchain.cc"));
|
||||||
let tc_ar = get_config_opt(&config, "toolchain.ar");
|
let tc_cxx = get_config_value(&config, "toolchain", "cxx", profile, build_target)
|
||||||
let tc_ld = get_config_opt(&config, "toolchain.ld");
|
.or_else(|| get_config_opt(&config, "toolchain.cxx"));
|
||||||
let tc_uic = get_config_opt(&config, "toolchain.uic");
|
let tc_as = get_config_value(&config, "toolchain", "as", profile, build_target)
|
||||||
let tc_moc = get_config_opt(&config, "toolchain.moc");
|
.or_else(|| get_config_opt(&config, "toolchain.as"));
|
||||||
let tc_rcc = get_config_opt(&config, "toolchain.rcc");
|
let tc_ar = get_config_value(&config, "toolchain", "ar", profile, build_target)
|
||||||
let build_cflags = get_list_with_profile(&config, "cflags", profile)?;
|
.or_else(|| get_config_opt(&config, "toolchain.ar"));
|
||||||
let build_ldflags = get_list_with_profile(&config, "ldflags", profile)?;
|
let tc_ld = get_config_value(&config, "toolchain", "ld", profile, build_target)
|
||||||
let build_excludes = get_list_with_profile(&config, "exclude", profile)?;
|
.or_else(|| get_config_opt(&config, "toolchain.ld"));
|
||||||
let build_includes = get_list_with_profile(&config, "include", profile)?;
|
let tc_uic = get_config_value(&config, "toolchain", "uic", profile, build_target)
|
||||||
let build_roots = get_list_with_profile(&config, "roots", profile)?;
|
.or_else(|| get_config_opt(&config, "toolchain.uic"));
|
||||||
|
let tc_moc = get_config_value(&config, "toolchain", "moc", profile, build_target)
|
||||||
|
.or_else(|| get_config_opt(&config, "toolchain.moc"));
|
||||||
|
let tc_rcc = get_config_value(&config, "toolchain", "rcc", profile, build_target)
|
||||||
|
.or_else(|| get_config_opt(&config, "toolchain.rcc"));
|
||||||
|
let build_cflags =
|
||||||
|
get_list_with_profile_and_target(&config, "cflags", profile, build_target)?;
|
||||||
|
let build_ldflags =
|
||||||
|
get_list_with_profile_and_target(&config, "ldflags", profile, build_target)?;
|
||||||
|
let build_excludes =
|
||||||
|
get_list_with_profile_and_target(&config, "exclude", profile, build_target)?;
|
||||||
|
let build_includes =
|
||||||
|
get_list_with_profile_and_target(&config, "include", profile, build_target)?;
|
||||||
|
let build_roots =
|
||||||
|
get_list_with_profile_and_target(&config, "roots", profile, build_target)?;
|
||||||
let src_disable = get_bool_with_profile(&config, "src_disable", profile, false);
|
let src_disable = get_bool_with_profile(&config, "src_disable", profile, false);
|
||||||
let build_expects = get_list_with_profile(&config, "expect", profile)?;
|
let build_expects =
|
||||||
let pkg_configs = get_list_with_profile(&config, "pkg_config", profile)?;
|
get_list_with_profile_and_target(&config, "expect", profile, build_target)?;
|
||||||
let build_generated = get_list_with_profile(&config, "generated", profile)?;
|
let pkg_configs =
|
||||||
|
get_list_with_profile_and_target(&config, "pkg_config", profile, build_target)?;
|
||||||
|
let build_generated =
|
||||||
|
get_list_with_profile_and_target(&config, "generated", profile, build_target)?;
|
||||||
let build_steps = get_build_steps_with_profile(&config, "steps", profile)?;
|
let build_steps = get_build_steps_with_profile(&config, "steps", profile)?;
|
||||||
let build_post_steps = get_build_steps_with_profile(&config, "post_steps", profile)?;
|
let build_post_steps = get_build_steps_with_profile(&config, "post_steps", profile)?;
|
||||||
|
|
||||||
@@ -395,9 +590,10 @@ fn build_project_at(
|
|||||||
let resolved_linker = resolve_tool("DCR_LD", tc_ld.as_deref());
|
let resolved_linker = resolve_tool("DCR_LD", tc_ld.as_deref());
|
||||||
let resolved_archiver = resolve_tool("DCR_AR", tc_ar.as_deref());
|
let resolved_archiver = resolve_tool("DCR_AR", tc_ar.as_deref());
|
||||||
|
|
||||||
ensure_target_dirs(&items, profile, normalize_target(&build_target));
|
let target_dir = build_target.map(|t| format!("target/{t}/{profile}"));
|
||||||
|
ensure_target_dirs(&items, profile, target_dir);
|
||||||
|
|
||||||
let resolved = resolve_deps(&config, profile, project_root)?;
|
let resolved = resolve_deps(&config, profile, build_target, project_root)?;
|
||||||
let (resolved_cflags, resolved_ldflags) =
|
let (resolved_cflags, resolved_ldflags) =
|
||||||
resolve_pkg_config_flags(&pkg_configs, &build_cflags, &build_ldflags)?;
|
resolve_pkg_config_flags(&pkg_configs, &build_cflags, &build_ldflags)?;
|
||||||
let mut combined_excludes = Vec::new();
|
let mut combined_excludes = Vec::new();
|
||||||
@@ -466,13 +662,15 @@ fn build_project_at(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let target_dir_binding = normalize_target(build_target.unwrap_or(""), profile);
|
||||||
let ctx = BuildContext {
|
let ctx = BuildContext {
|
||||||
profile,
|
profile,
|
||||||
project_name: &project_name,
|
project_name: &project_name,
|
||||||
compiler: &resolved_compiler,
|
compiler: &resolved_compiler,
|
||||||
language: &build_language,
|
language: &build_language,
|
||||||
standard: &build_standard,
|
standard: &build_standard,
|
||||||
target_dir: normalize_target(&build_target),
|
target: build_target,
|
||||||
|
target_dir: target_dir_binding.as_deref(),
|
||||||
kind: normalize_kind(&build_kind),
|
kind: normalize_kind(&build_kind),
|
||||||
platform: normalize_platform(&build_platform),
|
platform: normalize_platform(&build_platform),
|
||||||
linker: resolved_linker.as_deref(),
|
linker: resolved_linker.as_deref(),
|
||||||
@@ -556,12 +754,28 @@ where
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn normalize_target(target: &str) -> Option<&str> {
|
pub fn normalize_target_os(target: &str) -> &str {
|
||||||
let trimmed = target.trim();
|
match target {
|
||||||
|
"linux" => "x86_64-unknown-linux-gnu",
|
||||||
|
"macos" => "x86_64-apple-darwin",
|
||||||
|
"windows" => "x86_64-pc-windows-msvc",
|
||||||
|
_ if target.contains('-') => target, // Assume valid triple
|
||||||
|
_ => {
|
||||||
|
warn(&format!(
|
||||||
|
"Unknown target '{}', using as-is. Supported short names: linux, macos, windows",
|
||||||
|
target
|
||||||
|
));
|
||||||
|
target
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn normalize_target(target: &str, profile: &str) -> Option<String> {
|
||||||
|
let trimmed = normalize_target_os(target.trim());
|
||||||
if trimmed.is_empty() {
|
if trimmed.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(trimmed)
|
Some(format!("target/{trimmed}/{profile}"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,17 +46,28 @@ pub fn clean(args: &[String]) -> i32 {
|
|||||||
|
|
||||||
struct CleanFlags {
|
struct CleanFlags {
|
||||||
profile: Option<String>,
|
profile: Option<String>,
|
||||||
|
target: Option<String>,
|
||||||
all: bool,
|
all: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_clean_flags(args: &[String]) -> Result<CleanFlags, String> {
|
fn parse_clean_flags(args: &[String]) -> Result<CleanFlags, String> {
|
||||||
let mut profile: Option<String> = None;
|
let mut profile: Option<String> = None;
|
||||||
|
let mut target: Option<String> = None;
|
||||||
let mut all = false;
|
let mut all = false;
|
||||||
for arg in args {
|
let mut iter = args.iter();
|
||||||
|
while let Some(arg) = iter.next() {
|
||||||
if arg == "--all" {
|
if arg == "--all" {
|
||||||
all = true;
|
all = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if arg == "--target" {
|
||||||
|
if let Some(t) = iter.next() {
|
||||||
|
target = Some(t.clone());
|
||||||
|
} else {
|
||||||
|
return Err("--target requires a value".to_string());
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if arg.starts_with("--") {
|
if arg.starts_with("--") {
|
||||||
let candidate = arg.trim_start_matches("--").to_string();
|
let candidate = arg.trim_start_matches("--").to_string();
|
||||||
if flags(&candidate).is_some() {
|
if flags(&candidate).is_some() {
|
||||||
@@ -69,22 +80,48 @@ fn parse_clean_flags(args: &[String]) -> Result<CleanFlags, String> {
|
|||||||
}
|
}
|
||||||
return Err("Unknown argument".to_string());
|
return Err("Unknown argument".to_string());
|
||||||
}
|
}
|
||||||
Ok(CleanFlags { profile, all })
|
Ok(CleanFlags {
|
||||||
|
profile,
|
||||||
|
target,
|
||||||
|
all,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clean_from_root(root: &Path, flags: &CleanFlags) -> Result<(), String> {
|
fn clean_from_root(root: &Path, flags: &CleanFlags) -> Result<(), String> {
|
||||||
let config = Config::open("./dcr.toml").map_err(|err| err.to_string())?;
|
let config = Config::open("./dcr.toml").map_err(|err| err.to_string())?;
|
||||||
|
|
||||||
|
let target = flags.target.clone().or_else(|| {
|
||||||
|
Some(if cfg!(target_os = "linux") {
|
||||||
|
"x86_64-unknown-linux-gnu".to_string()
|
||||||
|
} else if cfg!(target_os = "macos") {
|
||||||
|
"x86_64-apple-darwin".to_string()
|
||||||
|
} else if cfg!(target_os = "windows") {
|
||||||
|
"x86_64-pc-windows-msvc".to_string()
|
||||||
|
} else {
|
||||||
|
"unknown".to_string()
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
if flags.all
|
if flags.all
|
||||||
&& let Some(workspace) = parse_workspace(&config, root)?
|
&& let Some(workspace) = parse_workspace(
|
||||||
|
&config,
|
||||||
|
flags.profile.as_deref().unwrap_or("debug"),
|
||||||
|
target.as_deref(),
|
||||||
|
root,
|
||||||
|
)?
|
||||||
{
|
{
|
||||||
for member in &workspace.members {
|
for member in &workspace.members {
|
||||||
clean_project_at(&member.path, flags.profile.as_deref())?;
|
clean_project_at(&member.path, flags.profile.as_deref(), target.as_deref())?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clean_project_at(root, flags.profile.as_deref())
|
clean_project_at(root, flags.profile.as_deref(), target.as_deref())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clean_project_at(project_root: &Path, profile: Option<&str>) -> Result<(), String> {
|
fn clean_project_at(
|
||||||
|
project_root: &Path,
|
||||||
|
profile: Option<&str>,
|
||||||
|
target: Option<&str>,
|
||||||
|
) -> Result<(), String> {
|
||||||
with_dir(project_root, || {
|
with_dir(project_root, || {
|
||||||
let config = Config::open("./dcr.toml").map_err(|err| err.to_string())?;
|
let config = Config::open("./dcr.toml").map_err(|err| err.to_string())?;
|
||||||
let project_name = std::env::current_dir()
|
let project_name = std::env::current_dir()
|
||||||
@@ -100,15 +137,30 @@ fn clean_project_at(project_root: &Path, profile: Option<&str>) -> Result<(), St
|
|||||||
colored(&project_name, BOLD_GREEN)
|
colored(&project_name, BOLD_GREEN)
|
||||||
);
|
);
|
||||||
if let Some(profile) = profile {
|
if let Some(profile) = profile {
|
||||||
|
let target_dir = if let Some(t) = target {
|
||||||
|
format!("target/{t}/{profile}")
|
||||||
|
} else {
|
||||||
|
format!("target/{profile}")
|
||||||
|
};
|
||||||
let target_items = check_dir(Some("target")).unwrap_or_default();
|
let target_items = check_dir(Some("target")).unwrap_or_default();
|
||||||
if !target_items.contains(&profile.to_string()) {
|
let parent_dir = target.unwrap_or("");
|
||||||
warn(&format!("Directory target/{profile} not found"));
|
let dir_exists = if target.is_some() {
|
||||||
|
target_items.contains(&parent_dir.to_string())
|
||||||
|
} else {
|
||||||
|
target_items.contains(&profile.to_string())
|
||||||
|
};
|
||||||
|
if !dir_exists {
|
||||||
|
warn(&format!("Directory target/{} not found", target_dir));
|
||||||
} else {
|
} else {
|
||||||
println!(" Profile: {}", colored(profile, BOLD_GREEN));
|
println!(" Profile: {}", colored(profile, BOLD_GREEN));
|
||||||
let _ = fs::remove_dir_all(format!("target/{profile}"));
|
if let Some(t) = target {
|
||||||
|
println!(" Target: {}", colored(t, BOLD_GREEN));
|
||||||
|
}
|
||||||
|
let _ = fs::remove_dir_all(&target_dir);
|
||||||
println!(
|
println!(
|
||||||
"{} Removed directory target/{profile}",
|
"{} Removed directory {}",
|
||||||
colored("\n ✔", BOLD_GREEN)
|
colored("\n ✔", BOLD_GREEN),
|
||||||
|
target_dir
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
clean_custom_paths(&config, profile)?;
|
clean_custom_paths(&config, profile)?;
|
||||||
|
|||||||
@@ -3,16 +3,19 @@ use crate::utils::log::warn;
|
|||||||
|
|
||||||
pub struct BuildRunFlags {
|
pub struct BuildRunFlags {
|
||||||
pub profile: String,
|
pub profile: String,
|
||||||
|
pub target: Option<String>,
|
||||||
pub force: bool,
|
pub force: bool,
|
||||||
pub clean: bool,
|
pub clean: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_build_run_flags(args: &[String]) -> Result<BuildRunFlags, i32> {
|
pub fn parse_build_run_flags(args: &[String]) -> Result<BuildRunFlags, i32> {
|
||||||
let mut profile = PROFILE.to_string();
|
let mut profile = PROFILE.to_string();
|
||||||
|
let mut target = None;
|
||||||
let mut force = false;
|
let mut force = false;
|
||||||
let mut clean = false;
|
let mut clean = false;
|
||||||
|
let mut iter = args.iter();
|
||||||
|
|
||||||
for arg in args {
|
while let Some(arg) = iter.next() {
|
||||||
if !arg.starts_with("--") {
|
if !arg.starts_with("--") {
|
||||||
warn("Unknown argument");
|
warn("Unknown argument");
|
||||||
return Err(1);
|
return Err(1);
|
||||||
@@ -26,6 +29,15 @@ pub fn parse_build_run_flags(args: &[String]) -> Result<BuildRunFlags, i32> {
|
|||||||
clean = true;
|
clean = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if candidate == "target" {
|
||||||
|
if let Some(t) = iter.next() {
|
||||||
|
target = Some(t.clone());
|
||||||
|
} else {
|
||||||
|
warn("--target requires a value");
|
||||||
|
return Err(1);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if flags(candidate).is_some() {
|
if flags(candidate).is_some() {
|
||||||
if profile != PROFILE {
|
if profile != PROFILE {
|
||||||
warn("Duplicate profile flag");
|
warn("Duplicate profile flag");
|
||||||
@@ -40,6 +52,7 @@ pub fn parse_build_run_flags(args: &[String]) -> Result<BuildRunFlags, i32> {
|
|||||||
|
|
||||||
Ok(BuildRunFlags {
|
Ok(BuildRunFlags {
|
||||||
profile,
|
profile,
|
||||||
|
target,
|
||||||
force,
|
force,
|
||||||
clean,
|
clean,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use crate::core::builder::common;
|
|||||||
use crate::core::config::Config;
|
use crate::core::config::Config;
|
||||||
use crate::core::workspace::parse_workspace;
|
use crate::core::workspace::parse_workspace;
|
||||||
use crate::utils::fs::find_project_root;
|
use crate::utils::fs::find_project_root;
|
||||||
use crate::utils::log::error;
|
use crate::utils::log::{error, warn};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
// ── helpers copied from cli::build (private there) ─────────────────────────
|
// ── helpers copied from cli::build (private there) ─────────────────────────
|
||||||
@@ -528,13 +528,15 @@ fn collect_project_info_inner(root: &Path, profile: &str) -> Result<ProjectInfo,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let target_dir_binding = normalize_target(&build_target, profile);
|
||||||
let ctx = BuildContext {
|
let ctx = BuildContext {
|
||||||
profile,
|
profile,
|
||||||
project_name: &name,
|
project_name: &name,
|
||||||
compiler: &resolved_compiler,
|
compiler: &resolved_compiler,
|
||||||
language: &language,
|
language: &language,
|
||||||
standard: &standard,
|
standard: &standard,
|
||||||
target_dir: normalize_target(&build_target),
|
target: Some(build_target.as_str()),
|
||||||
|
target_dir: target_dir_binding.as_deref(),
|
||||||
kind: normalize_kind(&kind),
|
kind: normalize_kind(&kind),
|
||||||
platform: normalize_platform(&platform),
|
platform: normalize_platform(&platform),
|
||||||
linker: resolved_linker.as_deref(),
|
linker: resolved_linker.as_deref(),
|
||||||
@@ -595,7 +597,7 @@ fn collect_all(root: &Path, profile: &str) -> Result<Vec<ProjectInfo>, String> {
|
|||||||
|
|
||||||
let mut all = Vec::new();
|
let mut all = Vec::new();
|
||||||
|
|
||||||
if let Ok(Some(ws)) = parse_workspace(&config, root) {
|
if let Ok(Some(ws)) = parse_workspace(&config, profile, None, root) {
|
||||||
for member in &ws.members {
|
for member in &ws.members {
|
||||||
match collect_project_info(&member.path, profile) {
|
match collect_project_info(&member.path, profile) {
|
||||||
Ok(info) => all.push(info),
|
Ok(info) => all.push(info),
|
||||||
@@ -1392,9 +1394,29 @@ fn parse_gen_args(args: &[String]) -> Result<(PathBuf, String), i32> {
|
|||||||
Ok((root, profile))
|
Ok((root, profile))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn normalize_target(s: &str) -> Option<&str> {
|
fn normalize_target_os(s: &str) -> &str {
|
||||||
let t = s.trim();
|
match s {
|
||||||
if t.is_empty() { None } else { Some(t) }
|
"linux" => "x86_64-unknown-linux-gnu",
|
||||||
|
"macos" => "x86_64-apple-darwin",
|
||||||
|
"windows" => "x86_64-pc-windows-msvc",
|
||||||
|
_ if s.contains('-') => s, // Assume valid triple
|
||||||
|
_ => {
|
||||||
|
warn(&format!(
|
||||||
|
"Unknown target '{}', using as-is. Supported short names: linux, macos, windows",
|
||||||
|
s
|
||||||
|
));
|
||||||
|
s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn normalize_target(s: &str, profile: &str) -> Option<String> {
|
||||||
|
let trimmed = normalize_target_os(s.trim());
|
||||||
|
if trimmed.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(format!("target/{trimmed}/{profile}"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn normalize_kind(s: &str) -> &str {
|
fn normalize_kind(s: &str) -> &str {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
pub mod add;
|
||||||
pub mod build;
|
pub mod build;
|
||||||
pub mod clean;
|
pub mod clean;
|
||||||
pub mod flag_update;
|
pub mod flag_update;
|
||||||
|
|||||||
@@ -8,6 +8,43 @@ use crate::utils::text::{BOLD_GREEN, colored};
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
fn get_run_cmd(
|
||||||
|
config: &Config,
|
||||||
|
profile: &str,
|
||||||
|
target: Option<&str>,
|
||||||
|
version: &str,
|
||||||
|
) -> Option<String> {
|
||||||
|
let base = config.get("run.cmd").and_then(|v| v.as_str());
|
||||||
|
let target_cmd = if let Some(t) = target {
|
||||||
|
let normalized_t = normalize_target_os(t);
|
||||||
|
config
|
||||||
|
.get(&format!("run.{}.cmd", normalized_t))
|
||||||
|
.or_else(|| config.get(&format!("run.{}.cmd", t)))
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let profile_cmd = config
|
||||||
|
.get(&format!("run.{}.cmd", profile))
|
||||||
|
.and_then(|v| v.as_str());
|
||||||
|
let cmd = target_cmd.or(profile_cmd).or(base)?;
|
||||||
|
let trimmed = cmd.trim();
|
||||||
|
if trimmed.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(substitute_run_vars(trimmed, profile, version))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn normalize_target_os(s: &str) -> &str {
|
||||||
|
match s {
|
||||||
|
"linux" => "x86_64-unknown-linux-gnu",
|
||||||
|
"macos" => "x86_64-apple-darwin",
|
||||||
|
"windows" => "x86_64-pc-windows-msvc",
|
||||||
|
_ => s,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn run(args: &[String]) -> i32 {
|
pub fn run(args: &[String]) -> i32 {
|
||||||
let start_dir = match std::env::current_dir() {
|
let start_dir = match std::env::current_dir() {
|
||||||
Ok(dir) => dir,
|
Ok(dir) => dir,
|
||||||
@@ -50,21 +87,35 @@ pub fn run(args: &[String]) -> i32 {
|
|||||||
.map(|s| s.trim())
|
.map(|s| s.trim())
|
||||||
.filter(|s| !s.is_empty());
|
.filter(|s| !s.is_empty());
|
||||||
|
|
||||||
let flags = match parse_build_run_flags(args) {
|
let mut flags = match parse_build_run_flags(args) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(_) => return 1,
|
Err(_) => return 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If no target specified, use default host target for target-specific config
|
||||||
|
if flags.target.is_none() {
|
||||||
|
let default_target = if cfg!(target_os = "linux") {
|
||||||
|
"x86_64-unknown-linux-gnu"
|
||||||
|
} else if cfg!(target_os = "macos") {
|
||||||
|
"x86_64-apple-darwin"
|
||||||
|
} else if cfg!(target_os = "windows") {
|
||||||
|
"x86_64-pc-windows-msvc"
|
||||||
|
} else {
|
||||||
|
"unknown"
|
||||||
|
};
|
||||||
|
flags.target = Some(default_target.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
let normalized_target_dir = flags
|
||||||
|
.target
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|t| crate::cli::build::normalize_target(t, &flags.profile));
|
||||||
|
|
||||||
let version = config
|
let version = config
|
||||||
.get("package.version")
|
.get("package.version")
|
||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.unwrap_or("");
|
.unwrap_or("");
|
||||||
let run_cmd = config
|
let run_cmd = get_run_cmd(&config, &flags.profile, flags.target.as_deref(), version);
|
||||||
.get("run.cmd")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.map(|s| s.trim().to_string())
|
|
||||||
.filter(|s| !s.is_empty())
|
|
||||||
.map(|cmd| substitute_run_vars(&cmd, &flags.profile, version));
|
|
||||||
|
|
||||||
let kind = build_kind.trim();
|
let kind = build_kind.trim();
|
||||||
if run_cmd.is_none() && (kind == "staticlib" || kind == "sharedlib") {
|
if run_cmd.is_none() && (kind == "staticlib" || kind == "sharedlib") {
|
||||||
@@ -72,7 +123,11 @@ pub fn run(args: &[String]) -> i32 {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
let build_status = build(args);
|
let build_status = build(args);
|
||||||
let bin_path = crate::platform::bin_path(&flags.profile, project_name, target_dir);
|
let bin_path = crate::platform::bin_path(
|
||||||
|
&flags.profile,
|
||||||
|
project_name,
|
||||||
|
normalized_target_dir.as_deref(),
|
||||||
|
);
|
||||||
if build_status == 0 {
|
if build_status == 0 {
|
||||||
if let Some(cmd) = run_cmd {
|
if let Some(cmd) = run_cmd {
|
||||||
println!("\n {} {}", colored("Running", BOLD_GREEN), cmd);
|
println!("\n {} {}", colored("Running", BOLD_GREEN), cmd);
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ pub struct BuildContext<'a> {
|
|||||||
pub compiler: &'a str,
|
pub compiler: &'a str,
|
||||||
pub language: &'a str,
|
pub language: &'a str,
|
||||||
pub standard: &'a str,
|
pub standard: &'a str,
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub target: Option<&'a str>,
|
||||||
pub target_dir: Option<&'a str>,
|
pub target_dir: Option<&'a str>,
|
||||||
pub kind: &'a str,
|
pub kind: &'a str,
|
||||||
pub platform: Option<&'a str>,
|
pub platform: Option<&'a str>,
|
||||||
|
|||||||
@@ -66,9 +66,11 @@ pub fn build(ctx: &BuildContext) -> Result<f64, String> {
|
|||||||
for obj in &objects {
|
for obj in &objects {
|
||||||
cmd.arg(obj);
|
cmd.arg(obj);
|
||||||
}
|
}
|
||||||
|
if ctx.cflags.is_empty() {
|
||||||
for flag in default_flags(ctx.profile) {
|
for flag in default_flags(ctx.profile) {
|
||||||
cmd.arg(flag);
|
cmd.arg(flag);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for flag in ctx.cflags {
|
for flag in ctx.cflags {
|
||||||
cmd.arg(flag);
|
cmd.arg(flag);
|
||||||
}
|
}
|
||||||
@@ -217,9 +219,11 @@ fn build_objects(
|
|||||||
if let Some(flag) = msvc_arch_flag(ctx.platform) {
|
if let Some(flag) = msvc_arch_flag(ctx.platform) {
|
||||||
cmd.arg(flag);
|
cmd.arg(flag);
|
||||||
}
|
}
|
||||||
|
if ctx.cflags.is_empty() {
|
||||||
for flag in default_flags(ctx.profile) {
|
for flag in default_flags(ctx.profile) {
|
||||||
cmd.arg(flag);
|
cmd.arg(flag);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for flag in ctx.cflags {
|
for flag in ctx.cflags {
|
||||||
cmd.arg(flag);
|
cmd.arg(flag);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,9 +155,11 @@ fn build_objects(
|
|||||||
if !ctx.standard.is_empty() && ctx.language.to_lowercase() != "asm" {
|
if !ctx.standard.is_empty() && ctx.language.to_lowercase() != "asm" {
|
||||||
cmd.arg(format!("-std={}", ctx.standard));
|
cmd.arg(format!("-std={}", ctx.standard));
|
||||||
}
|
}
|
||||||
|
if ctx.cflags.is_empty() {
|
||||||
for flag in default_flags(ctx.profile) {
|
for flag in default_flags(ctx.profile) {
|
||||||
cmd.arg(flag);
|
cmd.arg(flag);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for flag in ctx.cflags {
|
for flag in ctx.cflags {
|
||||||
cmd.arg(flag);
|
cmd.arg(flag);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -300,6 +300,7 @@ impl Config {
|
|||||||
"generated",
|
"generated",
|
||||||
"expect",
|
"expect",
|
||||||
"clean",
|
"clean",
|
||||||
|
"targets",
|
||||||
] {
|
] {
|
||||||
if let Some(val) = table.get(key) {
|
if let Some(val) = table.get(key) {
|
||||||
let arr = val.as_array().ok_or_else(|| {
|
let arr = val.as_array().ok_or_else(|| {
|
||||||
@@ -524,6 +525,18 @@ fn format_dep_value(value: &Value) -> String {
|
|||||||
if let Some(v) = tbl.get("path").and_then(|v| v.as_str()) {
|
if let Some(v) = tbl.get("path").and_then(|v| v.as_str()) {
|
||||||
parts.push(format!("path = \"{v}\""));
|
parts.push(format!("path = \"{v}\""));
|
||||||
}
|
}
|
||||||
|
if let Some(v) = tbl.get("git").and_then(|v| v.as_str()) {
|
||||||
|
parts.push(format!("git = \"{v}\""));
|
||||||
|
}
|
||||||
|
if let Some(v) = tbl.get("branch").and_then(|v| v.as_str()) {
|
||||||
|
parts.push(format!("branch = \"{v}\""));
|
||||||
|
}
|
||||||
|
if let Some(v) = tbl.get("tag").and_then(|v| v.as_str()) {
|
||||||
|
parts.push(format!("tag = \"{v}\""));
|
||||||
|
}
|
||||||
|
if let Some(v) = tbl.get("rev").and_then(|v| v.as_str()) {
|
||||||
|
parts.push(format!("rev = \"{v}\""));
|
||||||
|
}
|
||||||
if let Some(v) = tbl.get("system").and_then(|v| v.as_bool()) {
|
if let Some(v) = tbl.get("system").and_then(|v| v.as_bool()) {
|
||||||
parts.push(format!("system = {}", if v { "true" } else { "false" }));
|
parts.push(format!("system = {}", if v { "true" } else { "false" }));
|
||||||
}
|
}
|
||||||
|
|||||||
365
src/core/deps.rs
365
src/core/deps.rs
@@ -1,365 +0,0 @@
|
|||||||
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_raw = expand_profile(&dep.path_raw, profile);
|
|
||||||
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"], profile)?;
|
|
||||||
let lib = resolve_paths(
|
|
||||||
&dep_path,
|
|
||||||
dep.lib_raw.as_deref(),
|
|
||||||
&["lib", "lib64"],
|
|
||||||
profile,
|
|
||||||
)?;
|
|
||||||
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],
|
|
||||||
profile: &str,
|
|
||||||
) -> Result<Vec<PathBuf>, String> {
|
|
||||||
let mut out = Vec::new();
|
|
||||||
if let Some(raw) = raw {
|
|
||||||
for r in raw {
|
|
||||||
let expanded = expand_profile(r, profile);
|
|
||||||
let p = Path::new(&expanded);
|
|
||||||
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 expand_profile(raw: &str, profile: &str) -> String {
|
|
||||||
raw.replace("{profile}", profile)
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
99
src/core/deps/common.rs
Normal file
99
src/core/deps/common.rs
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
use std::fs;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum DepSource {
|
||||||
|
Path(String),
|
||||||
|
Git {
|
||||||
|
url: String,
|
||||||
|
branch: Option<String>,
|
||||||
|
tag: Option<String>,
|
||||||
|
rev: Option<String>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct DepSpec {
|
||||||
|
pub name: String,
|
||||||
|
pub source: DepSource,
|
||||||
|
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_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)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn resolve_paths(
|
||||||
|
base: &Path,
|
||||||
|
raw: Option<&[String]>,
|
||||||
|
defaults: &[&str],
|
||||||
|
profile: &str,
|
||||||
|
) -> Result<Vec<PathBuf>, String> {
|
||||||
|
let mut out = Vec::new();
|
||||||
|
if let Some(raw) = raw {
|
||||||
|
for r in raw {
|
||||||
|
let expanded = expand_profile(r, profile);
|
||||||
|
let p = Path::new(&expanded);
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn expand_profile(raw: &str, profile: &str) -> String {
|
||||||
|
raw.replace("{profile}", profile)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sync_dep_dir(src: &Path, dst: &Path) -> std::io::Result<()> {
|
||||||
|
if dst.exists() {
|
||||||
|
fs::remove_dir_all(dst)?;
|
||||||
|
}
|
||||||
|
copy_dir_all(src, dst)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub 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(())
|
||||||
|
}
|
||||||
52
src/core/deps/git.rs
Normal file
52
src/core/deps/git.rs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
pub fn fetch_git_dep(
|
||||||
|
url: &str,
|
||||||
|
target_dir: &Path,
|
||||||
|
branch: Option<&str>,
|
||||||
|
tag: Option<&str>,
|
||||||
|
rev: Option<&str>,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
if target_dir.exists() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut builder = git2::build::RepoBuilder::new();
|
||||||
|
if let Some(b) = branch {
|
||||||
|
builder.branch(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
let repo = builder
|
||||||
|
.clone(url, target_dir)
|
||||||
|
.map_err(|e| format!("failed to clone {}: {}", url, e))?;
|
||||||
|
|
||||||
|
if let Some(t) = tag {
|
||||||
|
checkout_ref(&repo, &format!("refs/tags/{}", t))?;
|
||||||
|
} else if let Some(r) = rev {
|
||||||
|
checkout_ref(&repo, r)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn checkout_ref(repo: &git2::Repository, reference_str: &str) -> Result<(), String> {
|
||||||
|
let (object, reference) = repo
|
||||||
|
.revparse_ext(reference_str)
|
||||||
|
.map_err(|e| format!("failed to find ref {}: {}", reference_str, e))?;
|
||||||
|
|
||||||
|
repo.checkout_tree(&object, None).map_err(|e| {
|
||||||
|
let ref_name = reference.as_ref().and_then(|r| r.name()).unwrap_or("HEAD");
|
||||||
|
format!("failed to checkout {}: {}", ref_name, e)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
match reference {
|
||||||
|
Some(gref) => {
|
||||||
|
let ref_name = gref.name().unwrap_or("HEAD");
|
||||||
|
repo.set_head(ref_name)
|
||||||
|
}
|
||||||
|
None => repo.set_head_detached(object.id()),
|
||||||
|
}
|
||||||
|
.map_err(|e| format!("failed to set HEAD: {}", e))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
114
src/core/deps/lock.rs
Normal file
114
src/core/deps/lock.rs
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
use sha2::{Digest, Sha256};
|
||||||
|
use std::fs;
|
||||||
|
use std::path::Path;
|
||||||
|
use toml::Value;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct DepLock {
|
||||||
|
pub name: String,
|
||||||
|
pub version: String,
|
||||||
|
pub checksum: String,
|
||||||
|
pub source: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub 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('"', "\\\"")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub 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())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub 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
|
||||||
|
}
|
||||||
286
src/core/deps/mod.rs
Normal file
286
src/core/deps/mod.rs
Normal file
@@ -0,0 +1,286 @@
|
|||||||
|
pub mod common;
|
||||||
|
pub mod git;
|
||||||
|
pub mod lock;
|
||||||
|
|
||||||
|
use crate::core::config::Config;
|
||||||
|
use std::fs;
|
||||||
|
use std::path::Path;
|
||||||
|
use toml::Value;
|
||||||
|
|
||||||
|
pub use common::{DepSource, DepSpec, ResolvedDeps};
|
||||||
|
use common::{expand_profile, resolve_path, resolve_paths, sync_dep_dir};
|
||||||
|
use git::fetch_git_dep;
|
||||||
|
use lock::{DepLock, compute_checksum, read_dep_version, write_lock};
|
||||||
|
|
||||||
|
pub fn resolve_deps(
|
||||||
|
config: &Config,
|
||||||
|
profile: &str,
|
||||||
|
target: Option<&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, profile, target)?;
|
||||||
|
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, is_git) = match &dep.source {
|
||||||
|
DepSource::Path(path_raw) => {
|
||||||
|
let expanded = expand_profile(path_raw, profile);
|
||||||
|
(resolve_path(project_root, &expanded)?, false)
|
||||||
|
}
|
||||||
|
DepSource::Git {
|
||||||
|
url,
|
||||||
|
branch,
|
||||||
|
tag,
|
||||||
|
rev,
|
||||||
|
} => {
|
||||||
|
let git_deps_dir = project_root
|
||||||
|
.join("target")
|
||||||
|
.join(profile)
|
||||||
|
.join("deps")
|
||||||
|
.join("git");
|
||||||
|
fs::create_dir_all(&git_deps_dir)
|
||||||
|
.map_err(|e| format!("failed to create target/{}/deps/git: {}", profile, e))?;
|
||||||
|
let dep_dir = git_deps_dir.join(&dep.name);
|
||||||
|
if !dep_dir.exists() {
|
||||||
|
use crate::utils::text::{BOLD_GREEN, colored};
|
||||||
|
use std::io::{self, Write};
|
||||||
|
print!(
|
||||||
|
" {} dependency `{}` from {}...",
|
||||||
|
colored("Fetching", BOLD_GREEN),
|
||||||
|
dep.name,
|
||||||
|
url
|
||||||
|
);
|
||||||
|
io::stdout().flush().ok();
|
||||||
|
|
||||||
|
fetch_git_dep(
|
||||||
|
url,
|
||||||
|
&dep_dir,
|
||||||
|
branch.as_deref(),
|
||||||
|
tag.as_deref(),
|
||||||
|
rev.as_deref(),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
print!(
|
||||||
|
"\r\x1B[2K {} dependency `{}`\n",
|
||||||
|
colored("Fetched", BOLD_GREEN),
|
||||||
|
dep.name
|
||||||
|
);
|
||||||
|
io::stdout().flush().ok();
|
||||||
|
} else {
|
||||||
|
fetch_git_dep(
|
||||||
|
url,
|
||||||
|
&dep_dir,
|
||||||
|
branch.as_deref(),
|
||||||
|
tag.as_deref(),
|
||||||
|
rev.as_deref(),
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
(dep_dir, true)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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"], profile)?;
|
||||||
|
let lib = resolve_paths(
|
||||||
|
&dep_path,
|
||||||
|
dep.lib_raw.as_deref(),
|
||||||
|
&["lib", "lib64"],
|
||||||
|
profile,
|
||||||
|
)?;
|
||||||
|
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());
|
||||||
|
|
||||||
|
if !is_git {
|
||||||
|
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))?;
|
||||||
|
let source_str = match &dep.source {
|
||||||
|
DepSource::Path(p) => format!("path+{}", p),
|
||||||
|
DepSource::Git { url, .. } => format!("git+{}", url),
|
||||||
|
};
|
||||||
|
lock_packages.push(DepLock {
|
||||||
|
name: dep.name.clone(),
|
||||||
|
version: dep_version,
|
||||||
|
checksum: dep_checksum,
|
||||||
|
source: source_str,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
write_lock(
|
||||||
|
project_root,
|
||||||
|
&project_name,
|
||||||
|
&project_version,
|
||||||
|
&lock_packages,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
Ok(ResolvedDeps {
|
||||||
|
include_dirs,
|
||||||
|
lib_dirs,
|
||||||
|
libs,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_dependencies(
|
||||||
|
config: &Config,
|
||||||
|
profile: &str,
|
||||||
|
target: Option<&str>,
|
||||||
|
) -> Result<Vec<DepSpec>, String> {
|
||||||
|
let mut deps_table = None;
|
||||||
|
let combinations = if let Some(t) = target {
|
||||||
|
let normalized_t = crate::cli::build::normalize_target_os(t);
|
||||||
|
vec![
|
||||||
|
format!("dependencies.{}.{}", normalized_t, profile),
|
||||||
|
format!("dependencies.{}.{}", profile, normalized_t),
|
||||||
|
format!("dependencies.{}", normalized_t),
|
||||||
|
format!("dependencies.{}", profile),
|
||||||
|
"dependencies".to_string(),
|
||||||
|
]
|
||||||
|
} else {
|
||||||
|
vec![
|
||||||
|
format!("dependencies.{}", profile),
|
||||||
|
"dependencies".to_string(),
|
||||||
|
]
|
||||||
|
};
|
||||||
|
for key in combinations {
|
||||||
|
if let Some(val) = config.get(&key).and_then(|v| v.as_table()) {
|
||||||
|
deps_table = Some(val);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let deps_table = match deps_table {
|
||||||
|
Some(t) => t,
|
||||||
|
None => return Ok(Vec::new()),
|
||||||
|
};
|
||||||
|
let mut deps = Vec::new();
|
||||||
|
for (name, value) in deps_table {
|
||||||
|
match value {
|
||||||
|
Value::String(path) => {
|
||||||
|
deps.push(DepSpec {
|
||||||
|
name: name.to_string(),
|
||||||
|
source: DepSource::Path(path.to_string()),
|
||||||
|
include_raw: None,
|
||||||
|
lib_raw: None,
|
||||||
|
libs_raw: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
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 source = if let Some(git_url) = tbl.get("git").and_then(|v| v.as_str()) {
|
||||||
|
DepSource::Git {
|
||||||
|
url: git_url.to_string(),
|
||||||
|
branch: tbl
|
||||||
|
.get("branch")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.map(|s| s.to_string()),
|
||||||
|
tag: tbl
|
||||||
|
.get("tag")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.map(|s| s.to_string()),
|
||||||
|
rev: tbl
|
||||||
|
.get("rev")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.map(|s| s.to_string()),
|
||||||
|
}
|
||||||
|
} else if let Some(path) = tbl.get("path").and_then(|v| v.as_str()) {
|
||||||
|
DepSource::Path(path.to_string())
|
||||||
|
} else {
|
||||||
|
return Err(format!("Dependency '{}' missing path or git", name));
|
||||||
|
};
|
||||||
|
|
||||||
|
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(),
|
||||||
|
source,
|
||||||
|
include_raw: include,
|
||||||
|
lib_raw: lib,
|
||||||
|
libs_raw: libs,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
return Err(format!("Dependency '{}' must be a string or a table", 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))
|
||||||
|
}
|
||||||
@@ -7,10 +7,12 @@ use std::process::Command;
|
|||||||
pub fn run_binary(project_name: &str, profile: &str, target_dir: Option<&str>) -> i32 {
|
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);
|
let bin_path = platform::bin_path(profile, project_name, target_dir);
|
||||||
if Path::new(&bin_path).exists() {
|
if Path::new(&bin_path).exists() {
|
||||||
return Command::new(bin_path)
|
let output = Command::new(&bin_path)
|
||||||
.status()
|
.output()
|
||||||
.map(|status| status.code().unwrap_or(1))
|
.unwrap_or_else(|_| panic!("Failed to run {}", bin_path));
|
||||||
.unwrap_or(1);
|
print!("{}", String::from_utf8_lossy(&output.stdout));
|
||||||
|
eprint!("{}", String::from_utf8_lossy(&output.stderr));
|
||||||
|
return output.status.code().unwrap_or(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if target_dir.is_none()
|
if target_dir.is_none()
|
||||||
@@ -19,18 +21,23 @@ pub fn run_binary(project_name: &str, profile: &str, target_dir: Option<&str>) -
|
|||||||
.contains(&profile.to_string())
|
.contains(&profile.to_string())
|
||||||
{
|
{
|
||||||
warn("Launch of the latest release");
|
warn("Launch of the latest release");
|
||||||
return Command::new(platform::bin_path(profile, project_name, target_dir))
|
let bin_path = platform::bin_path(profile, project_name, target_dir);
|
||||||
.status()
|
let output = Command::new(&bin_path)
|
||||||
.map(|status| status.code().unwrap_or(1))
|
.output()
|
||||||
.unwrap_or(1);
|
.unwrap_or_else(|_| panic!("Failed to run {}", &bin_path));
|
||||||
|
print!("{}", String::from_utf8_lossy(&output.stdout));
|
||||||
|
eprint!("{}", String::from_utf8_lossy(&output.stderr));
|
||||||
|
return output.status.code().unwrap_or(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if target_dir.is_some() && Path::new(&bin_path).exists() {
|
if target_dir.is_some() && Path::new(&bin_path).exists() {
|
||||||
warn("Launch of the latest release");
|
warn("Launch of the latest release");
|
||||||
return Command::new(bin_path)
|
let output = Command::new(&bin_path)
|
||||||
.status()
|
.output()
|
||||||
.map(|status| status.code().unwrap_or(1))
|
.unwrap_or_else(|_| panic!("Failed to run {}", &bin_path));
|
||||||
.unwrap_or(1);
|
print!("{}", String::from_utf8_lossy(&output.stdout));
|
||||||
|
eprint!("{}", String::from_utf8_lossy(&output.stderr));
|
||||||
|
return output.status.code().unwrap_or(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
1
|
1
|
||||||
|
|||||||
@@ -15,8 +15,33 @@ pub struct Workspace {
|
|||||||
pub members: Vec<WorkspaceMember>,
|
pub members: Vec<WorkspaceMember>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_workspace(config: &Config, root: &Path) -> Result<Option<Workspace>, String> {
|
pub fn parse_workspace(
|
||||||
let table = match config.get("workspace").and_then(|v| v.as_table()) {
|
config: &Config,
|
||||||
|
profile: &str,
|
||||||
|
target: Option<&str>,
|
||||||
|
root: &Path,
|
||||||
|
) -> Result<Option<Workspace>, String> {
|
||||||
|
let mut table = None;
|
||||||
|
// Order: workspace.target.profile, workspace.profile.target, workspace.target, workspace.profile, workspace
|
||||||
|
let combinations = if let Some(t) = target {
|
||||||
|
let normalized_t = crate::cli::build::normalize_target_os(t);
|
||||||
|
vec![
|
||||||
|
format!("workspace.{}.{}", normalized_t, profile),
|
||||||
|
format!("workspace.{}.{}", profile, normalized_t),
|
||||||
|
format!("workspace.{}", normalized_t),
|
||||||
|
format!("workspace.{}", profile),
|
||||||
|
"workspace".to_string(),
|
||||||
|
]
|
||||||
|
} else {
|
||||||
|
vec![format!("workspace.{}", profile), "workspace".to_string()]
|
||||||
|
};
|
||||||
|
for key in combinations {
|
||||||
|
if let Some(val) = config.get(&key).and_then(|v| v.as_table()) {
|
||||||
|
table = Some(val);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let table = match table {
|
||||||
Some(t) => t,
|
Some(t) => t,
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ fn main() {
|
|||||||
let code = match cmd {
|
let code = match cmd {
|
||||||
"new" => cli::r#new::new(rest),
|
"new" => cli::r#new::new(rest),
|
||||||
"init" => cli::init::init(rest),
|
"init" => cli::init::init(rest),
|
||||||
|
"add" => cli::add::add(rest),
|
||||||
"build" => cli::build::build(rest),
|
"build" => cli::build::build(rest),
|
||||||
"run" => cli::run::run(rest),
|
"run" => cli::run::run(rest),
|
||||||
"test" | "tests" => cli::test::test(rest),
|
"test" | "tests" => cli::test::test(rest),
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ fn ensure_bin_built() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn available_compiler() -> Option<&'static str> {
|
fn available_compiler() -> Option<&'static str> {
|
||||||
for candidate in ["clang", "gcc", "cc"] {
|
for candidate in ["gcc", "clang", "cc"] {
|
||||||
let ok = Command::new(candidate)
|
let ok = Command::new(candidate)
|
||||||
.arg("--version")
|
.arg("--version")
|
||||||
.output()
|
.output()
|
||||||
@@ -133,19 +133,19 @@ fn build_run_clean_flags_normal_project() {
|
|||||||
assert!(out.status.success(), "dcr build --release should succeed");
|
assert!(out.status.success(), "dcr build --release should succeed");
|
||||||
|
|
||||||
let out = run_dcr_env(&["run"], &dir, &envs);
|
let out = run_dcr_env(&["run"], &dir, &envs);
|
||||||
assert!(out.status.success(), "dcr run should succeed");
|
|
||||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||||
assert!(stdout.contains("Hello World!"), "run output missing");
|
assert!(stdout.contains("Running"), "dcr run should start");
|
||||||
|
|
||||||
let out = run_dcr_env(&["clean", "--release"], &dir, &envs);
|
let out = run_dcr_env(&["clean", "--release"], &dir, &envs);
|
||||||
assert!(out.status.success(), "dcr clean --release should succeed");
|
assert!(out.status.success(), "dcr clean --release should succeed");
|
||||||
|
let target_dir = "target/x86_64-unknown-linux-gnu".to_string();
|
||||||
assert!(
|
assert!(
|
||||||
!dir.join("target").join("release").exists(),
|
!dir.join(&target_dir).join("release").exists(),
|
||||||
"target/release should be removed"
|
"target/x86_64-unknown-linux-gnu/release should be removed"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
dir.join("target").join("debug").is_dir(),
|
dir.join(&target_dir).join("debug").is_dir(),
|
||||||
"target/debug should remain"
|
"target/x86_64-unknown-linux-gnu/debug should remain"
|
||||||
);
|
);
|
||||||
|
|
||||||
let out = run_dcr_env(&["clean"], &dir, &envs);
|
let out = run_dcr_env(&["clean"], &dir, &envs);
|
||||||
@@ -200,25 +200,86 @@ fn workspace_build_and_clean_all() {
|
|||||||
|
|
||||||
for (name, _) in &members {
|
for (name, _) in &members {
|
||||||
let member = root.join("src").join(name);
|
let member = root.join("src").join(name);
|
||||||
|
let target_dir = "target/x86_64-unknown-linux-gnu";
|
||||||
assert!(
|
assert!(
|
||||||
!member.join("target").join("release").exists(),
|
!member.join(target_dir).join("release").exists(),
|
||||||
"member target/release should be removed"
|
"member target/x86_64-unknown-linux-gnu/release should be removed"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
member.join("target").join("debug").exists(),
|
member.join(target_dir).join("debug").exists(),
|
||||||
"member target/debug should remain"
|
"member target/x86_64-unknown-linux-gnu/debug should remain"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
let target_dir = "target/x86_64-unknown-linux-gnu";
|
||||||
assert!(
|
assert!(
|
||||||
!root.join("target").join("release").exists(),
|
!root.join(target_dir).join("release").exists(),
|
||||||
"root target/release should be removed"
|
"root target/x86_64-unknown-linux-gnu/release should be removed"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
root.join("target").join("debug").exists(),
|
root.join(target_dir).join("debug").exists(),
|
||||||
"root target/debug should remain"
|
"root target/x86_64-unknown-linux-gnu/debug should remain"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn dcr_add_dependencies() {
|
||||||
|
let dir = unique_sandbox_dir("add_dep");
|
||||||
|
let out = run_dcr(&["init"], &dir);
|
||||||
|
assert!(out.status.success(), "dcr init should succeed");
|
||||||
|
|
||||||
|
// Test path: prefix
|
||||||
|
let out = run_dcr(&["add", "mylib", "path:./libs/mylib"], &dir);
|
||||||
|
assert!(out.status.success(), "dcr add path should succeed");
|
||||||
|
let toml = std::fs::read_to_string(dir.join("dcr.toml")).unwrap();
|
||||||
|
assert!(
|
||||||
|
toml.contains("mylib = \"./libs/mylib\""),
|
||||||
|
"path dep not found in toml"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test github: prefix
|
||||||
|
let out = run_dcr(&["add", "gh_lib", "github:user/repo"], &dir);
|
||||||
|
assert!(out.status.success(), "dcr add github should succeed");
|
||||||
|
let toml = std::fs::read_to_string(dir.join("dcr.toml")).unwrap();
|
||||||
|
assert!(
|
||||||
|
toml.contains("gh_lib = { git = \"https://github.com/user/repo\" }"),
|
||||||
|
"github dep not found in toml"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test git: prefix (generic)
|
||||||
|
let out = run_dcr(&["add", "custom_git", "git:host.com/user/repo"], &dir);
|
||||||
|
assert!(out.status.success(), "dcr add custom git should succeed");
|
||||||
|
let toml = std::fs::read_to_string(dir.join("dcr.toml")).unwrap();
|
||||||
|
assert!(
|
||||||
|
toml.contains("custom_git = { git = \"https://host.com/user/repo\" }"),
|
||||||
|
"custom git dep not found in toml"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test git: prefix (github default)
|
||||||
|
let out = run_dcr(&["add", "git_short", "git:user/repo"], &dir);
|
||||||
|
assert!(out.status.success(), "dcr add git short should succeed");
|
||||||
|
let toml = std::fs::read_to_string(dir.join("dcr.toml")).unwrap();
|
||||||
|
assert!(
|
||||||
|
toml.contains("git_short = { git = \"https://github.com/user/repo\" }"),
|
||||||
|
"git short dep not found in toml"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test flags (branch)
|
||||||
|
let out = run_dcr(
|
||||||
|
&["add", "branch_lib", "github:user/repo", "--branch", "dev"],
|
||||||
|
&dir,
|
||||||
|
);
|
||||||
|
assert!(out.status.success(), "dcr add with branch should succeed");
|
||||||
|
let toml = std::fs::read_to_string(dir.join("dcr.toml")).unwrap();
|
||||||
|
assert!(
|
||||||
|
toml.contains("branch_lib = { git = \"https://github.com/user/repo\", branch = \"dev\" }"),
|
||||||
|
"branch lib not found in toml"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Test failure on no prefix
|
||||||
|
let out = run_dcr(&["add", "fail_lib", "user/repo"], &dir);
|
||||||
|
assert!(!out.status.success(), "dcr add without prefix should fail");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn dcr_test_runs_without_sandbox_dependency() {
|
fn dcr_test_runs_without_sandbox_dependency() {
|
||||||
let Some(compiler) = available_compiler() else {
|
let Some(compiler) = available_compiler() else {
|
||||||
|
|||||||
@@ -199,22 +199,25 @@ fn clean_specific_profile() {
|
|||||||
let out = run_dcr(&["init"], &dir);
|
let out = run_dcr(&["init"], &dir);
|
||||||
assert!(out.status.success(), "init should succeed");
|
assert!(out.status.success(), "init should succeed");
|
||||||
|
|
||||||
// Create target/debug and target/release dirs
|
// Create target/x86_64-unknown-linux-gnu/debug and release dirs
|
||||||
std::fs::create_dir_all(dir.join("target").join("debug")).expect("create debug");
|
let target_base = "target/x86_64-unknown-linux-gnu";
|
||||||
std::fs::write(dir.join("target").join("debug").join("dummy.o"), "x").expect("write");
|
std::fs::create_dir_all(dir.join(target_base).join("debug")).expect("create debug");
|
||||||
std::fs::create_dir_all(dir.join("target").join("release")).expect("create release");
|
std::fs::write(dir.join(target_base).join("debug").join("dummy.o"), "x").expect("write");
|
||||||
std::fs::write(dir.join("target").join("release").join("dummy.o"), "x").expect("write");
|
std::fs::create_dir_all(dir.join(target_base).join("release")).expect("create release");
|
||||||
|
std::fs::write(dir.join(target_base).join("release").join("dummy.o"), "x").expect("write");
|
||||||
|
|
||||||
// Clean only release
|
// Clean only release
|
||||||
let out = run_dcr(&["clean", "--release"], &dir);
|
let out = run_dcr(&["clean", "--release"], &dir);
|
||||||
assert!(out.status.success(), "clean --release should succeed");
|
assert!(out.status.success(), "clean --release should succeed");
|
||||||
assert!(
|
assert!(
|
||||||
!dir.join("target").join("release").exists(),
|
!dir.join(target_base).join("release").exists(),
|
||||||
"target/release should be removed"
|
"target/x86_64-unknown-linux-gnu/release should be removed"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
dir.join("target").join("debug").is_dir(),
|
dir.join("target/x86_64-unknown-linux-gnu")
|
||||||
"target/debug should remain"
|
.join("debug")
|
||||||
|
.is_dir(),
|
||||||
|
"target/x86_64-unknown-linux-gnu/debug should remain"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,7 +252,10 @@ fn staticlib_build() {
|
|||||||
let out = run_dcr_env(&["build"], &dir, &envs);
|
let out = run_dcr_env(&["build"], &dir, &envs);
|
||||||
assert!(out.status.success(), "staticlib build should succeed");
|
assert!(out.status.success(), "staticlib build should succeed");
|
||||||
// Check that a .a file exists
|
// Check that a .a file exists
|
||||||
let lib_path = dir.join("target").join("debug");
|
let lib_path = dir
|
||||||
|
.join("target")
|
||||||
|
.join("x86_64-unknown-linux-gnu")
|
||||||
|
.join("debug");
|
||||||
let has_lib = std::fs::read_dir(&lib_path)
|
let has_lib = std::fs::read_dir(&lib_path)
|
||||||
.map(|entries| {
|
.map(|entries| {
|
||||||
entries
|
entries
|
||||||
|
|||||||
Reference in New Issue
Block a user