A Rust library for fetching and downloading release binaries from multiple Git repositories (GitHub and Gitee) with semantic version matching.
- Multi-platform support: Fetch releases from both GitHub and Gitee
- Semantic versioning: Use semver requirements to match compatible versions
- Concurrent fetching: Parallel requests to multiple repositories for faster results
- Flexible configuration: Customizable timeout, download directory, and repository priorities
- Automatic binary download: Downloads matching binary assets automatically
Add this to your Cargo.toml:
[dependencies]
release-dep = "0.1.0"use release_dep::{Config, get_release};
use std::time::Duration;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config {
package: "your-package-name",
version: "^1.0.0", // semver requirement
repo: &[
"https://github.com/owner/repo",
"https://gitee.com/owner/repo",
],
download_dir: Some("./downloads"),
timeout: Some(Duration::from_secs(30)),
};
match get_release(config) {
Ok(release_dep) => {
println!("Found release:");
println!(" Name: {}", release_dep.name);
println!(" Version: {}", release_dep.version);
println!(" Binary: {:?}", release_dep.binary);
}
Err(e) => {
println!("Error: {e}");
}
}
Ok(())
}The Config struct accepts the following parameters:
package: The name of the package/binary to search forversion: A semver requirement string (e.g., "^1.0.0", ">=0.2.0", "1.2.3")repo: An array of repository URLs in order of prioritydownload_dir: Optional download directory (defaults to system temp directory)timeout: Optional timeout duration (defaults to no timeout)
- URL format:
https://github.com/owner/repo - API: Uses GitHub REST API v3
- Rate limits: Subject to GitHub API rate limits
- URL format:
https://gitee.com/owner/repo - API: Uses Gitee REST API v5
- Rate limits: Subject to Gitee API rate limits
The library supports full semver requirements:
- Exact version:
"1.0.0" - Caret requirements:
"^1.0.0"(compatible with 1.x.x) - Tilde requirements:
"~1.0.0"(compatible with 1.0.x) - Range requirements:
">=1.0.0, <2.0.0" - Wildcard:
"*"(any version)
use release_dep::{Config, get_release};
let config = Config {
package: "my-binary",
version: "0.2.0",
repo: &["https://github.com/owner/repo"],
download_dir: Some("./downloads"),
timeout: None,
};
let release = get_release(config)?;use release_dep::{Config, get_release};
use std::time::Duration;
let config = Config {
package: "my-binary",
version: "^1.0.0",
repo: &[
"https://gitee.com/owner/repo", // Try Gitee first
"https://github.com/owner/repo", // Fallback to GitHub
],
download_dir: Some("./target/downloads"),
timeout: Some(Duration::from_secs(30)),
};
let release = get_release(config)?;- Parse Configuration: Validates the semver requirement and repository URLs
- Concurrent Requests: Sends parallel requests to all specified repositories
- Version Matching: Checks each release against the semver requirement
- Binary Search: Looks for assets containing the package name
- Download: Downloads the first matching binary found
- Return Results: Returns the
ReleaseDepwith download information
The get_release function returns a ReleaseDep struct:
pub struct ReleaseDep {
pub name: String, // Package name
pub version: Version, // Exact version found
pub binary: PathBuf, // Path to downloaded binary
}The library returns detailed error messages for common scenarios:
- Invalid semver requirements
- Unsupported repository providers
- Network connection issues
- No matching releases found
- Download failures
- Timeout exceeded
- Rust 1.70 or later
- Internet connection for API access
- Write permissions for download directory
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Initial release
- Support for GitHub and Gitee repositories
- Semantic version matching
- Concurrent repository fetching
- Automatic binary download