5 Commits

9 changed files with 120 additions and 40 deletions

View File

@@ -112,27 +112,11 @@ jobs:
name: release-notes
path: .github
- name: Install apt packages
if: runner.os == 'Linux' && matrix.apt != ''
- name: Install cargo-zigbuild (Linux cross-compilation)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu musl-tools
case "${{ matrix.target }}" in
aarch64-unknown-linux-gnu)
echo "CC_aarch64-unknown-linux-gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "AR_aarch64-unknown-linux-gnu=aarch64-linux-gnu-ar" >> $GITHUB_ENV
;;
x86_64-unknown-linux-musl)
echo "CC_x86_64-unknown-linux-musl=x86_64-linux-musl-gcc" >> $GITHUB_ENV
;;
aarch64-unknown-linux-musl)
curl -L https://musl.cc/aarch64-linux-musl-cross.tgz -o /tmp/musl-aarch64.tgz
sudo tar xzf /tmp/musl-aarch64.tgz -C /opt
echo "/opt/aarch64-linux-musl-cross/bin" >> $GITHUB_PATH
echo "CC_aarch64-unknown-linux-musl=aarch64-linux-musl-gcc" >> $GITHUB_ENV
echo "AR_aarch64-unknown-linux-musl=aarch64-linux-musl-ar" >> $GITHUB_ENV
;;
esac
pip install cargo-zigbuild
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Setup LLVM + MinGW (gnullvm)
if: contains(matrix.target, 'gnullvm')
@@ -148,17 +132,12 @@ jobs:
- name: Build
shell: bash
env:
MATRIX_ENV_CC: ${{ matrix.env_cc }}
MATRIX_ENV_LINKER: ${{ matrix.env_linker }}
run: |
if [[ -n "${MATRIX_ENV_CC:-}" ]]; then
export "${MATRIX_ENV_CC?}"
if [ "${{ runner.os }}" = "Linux" ] && [ "${{ matrix.target }}" != "x86_64-unknown-linux-gnu" ]; then
cargo zigbuild --release --target ${{ matrix.target }}
else
cargo build --release --target ${{ matrix.target }}
fi
if [[ -n "${MATRIX_ENV_LINKER:-}" ]]; then
export "${MATRIX_ENV_LINKER?}"
fi
cargo build --release --target ${{ matrix.target }}
- name: Derive version string
shell: bash

51
Cargo.lock generated
View File

@@ -117,6 +117,7 @@ dependencies = [
"ctrlc",
"git2",
"glob",
"openssl",
"reqwest",
"self-replace",
"serde",
@@ -192,6 +193,21 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]]
name = "foreign-types"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
dependencies = [
"foreign-types-shared",
]
[[package]]
name = "foreign-types-shared"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "form_urlencoded"
version = "1.2.2"
@@ -730,12 +746,46 @@ version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "openssl"
version = "0.10.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf0b434746ee2832f4f0baf10137e1cabb18cbe6912c69e2e33263c45250f542"
dependencies = [
"bitflags",
"cfg-if",
"foreign-types",
"libc",
"openssl-macros",
"openssl-sys",
]
[[package]]
name = "openssl-macros"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "openssl-probe"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e"
[[package]]
name = "openssl-src"
version = "300.5.4+3.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a507b3792995dae9b0df8a1c1e3771e8418b7c2d9f0baeba32e6fe8b06c7cb72"
dependencies = [
"cc",
]
[[package]]
name = "openssl-sys"
version = "0.9.115"
@@ -744,6 +794,7 @@ checksum = "158fe5b292746440aa6e7a7e690e55aeb72d41505e2804c23c6973ad0e9c9781"
dependencies = [
"cc",
"libc",
"openssl-src",
"pkg-config",
"vcpkg",
]

View File

@@ -14,3 +14,4 @@ toml = "1.0.3"
git2 = "0.20.4"
serde_json = "1"
ctrlc = "3"
openssl = { version = "0.10", features = ["vendored"] }

View File

@@ -50,7 +50,15 @@ pub fn build(args: &[String]) -> i32 {
Err(code) => return code,
};
// If no target specified, use default host target for target-specific config
if flags.target.is_none() {
let config_path = root.join("dcr.toml");
if let Ok(config) = Config::open(config_path.to_str().unwrap()) {
let bt = get_build_string_with_profile(&config, "target", "debug");
if !bt.is_empty() {
flags.target = Some(bt);
}
}
}
if flags.target.is_none() {
let default_target = if cfg!(target_os = "linux") {
"x86_64-unknown-linux-gnu"
@@ -490,10 +498,23 @@ fn build_project_at(
.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 =
let mut build_cflags =
get_list_with_profile_and_target(&config, "cflags", profile, build_target)?;
// Автоматически добавляем --target=..., если задан build.target и флаг ещё не указан
if let Some(t) = build_target {
if !t.trim().is_empty() {
let target_flag = format!("--target={}", t.trim());
if !build_cflags.iter().any(|f| f == &target_flag || f.starts_with("--target=")) {
build_cflags.insert(0, target_flag);
}
}
}
let build_ldflags =
get_list_with_profile_and_target(&config, "ldflags", profile, build_target)?;
// Новые поля: filename и extension
let output_filename = get_string_with_profile_and_target(&config, "filename", profile, build_target);
let output_extension = get_string_with_profile_and_target(&config, "extension", profile, build_target);
let build_excludes =
get_list_with_profile_and_target(&config, "exclude", profile, build_target)?;
let build_includes =
@@ -672,6 +693,8 @@ fn build_project_at(
libs: &resolved.libs,
cflags: &resolved_cflags,
ldflags: &resolved_ldflags,
output_filename: if output_filename.is_empty() { None } else { Some(output_filename.as_str()) },
output_extension: if output_extension.is_empty() { None } else { Some(output_extension.as_str()) },
};
if std::env::var("DCR_DEBUG").is_ok() {
eprintln!("[dcr] debug: compiler={}", ctx.compiler);
@@ -1265,13 +1288,23 @@ fn build_cache_path(profile: &str, target_dir: Option<&str>) -> std::path::PathB
}
fn build_output_path(ctx: &BuildContext) -> String {
let name = ctx.output_filename.unwrap_or(ctx.project_name);
let ext = ctx.output_extension.unwrap_or("");
let final_name = if ext.is_empty() {
name.to_string()
} else {
format!("{}.{}", name, ext)
};
if ctx.kind == "staticlib" {
return crate::platform::lib_path(ctx.profile, ctx.project_name, ctx.target_dir);
// Для библиотек добавляем lib префикс если нужно, но упростим
return crate::platform::lib_path(ctx.profile, &final_name, ctx.target_dir);
}
if ctx.kind == "sharedlib" {
return crate::platform::shared_lib_path(ctx.profile, ctx.project_name, ctx.target_dir);
return crate::platform::shared_lib_path(ctx.profile, &final_name, ctx.target_dir);
}
crate::platform::bin_path(ctx.profile, ctx.project_name, ctx.target_dir)
crate::platform::bin_path(ctx.profile, &final_name, ctx.target_dir)
}
fn collect_header_files(

View File

@@ -337,6 +337,8 @@ fn collect_project_info_inner(root: &Path, profile: &str) -> Result<ProjectInfo,
libs: &resolved.libs,
cflags: &resolved_cflags,
ldflags: &resolved_ldflags,
output_filename: None,
output_extension: None,
};
let sources = collect_sources(&ctx).map_err(|e| format!("Failed to collect sources: {e}"))?;

View File

@@ -70,10 +70,14 @@ pub fn build(ctx: &BuildContext) -> Result<f64, String> {
for flag in ctx.ldflags {
cmd.arg(flag);
}
let name = ctx.output_filename.unwrap_or(ctx.project_name);
let ext = ctx.output_extension.unwrap_or("");
let final_name = if ext.is_empty() { name.to_string() } else { format!("{}.{}", name, ext) };
let out_path = if ctx.kind == "sharedlib" {
platform::shared_lib_path(ctx.profile, ctx.project_name, ctx.target_dir)
platform::shared_lib_path(ctx.profile, &final_name, ctx.target_dir)
} else {
platform::bin_path(ctx.profile, ctx.project_name, ctx.target_dir)
platform::bin_path(ctx.profile, &final_name, ctx.target_dir)
};
cmd.arg("-o").arg(out_path);

View File

@@ -26,6 +26,8 @@ pub struct BuildContext<'a> {
pub libs: &'a [String],
pub cflags: &'a [String],
pub ldflags: &'a [String],
pub output_filename: Option<&'a str>,
pub output_extension: Option<&'a str>,
}
pub fn build(ctx: &BuildContext) -> Result<f64, String> {

View File

@@ -70,10 +70,14 @@ pub fn build(ctx: &BuildContext) -> Result<f64, String> {
for flag in ctx.ldflags {
cmd.arg(flag);
}
let name = ctx.output_filename.unwrap_or(ctx.project_name);
let ext = ctx.output_extension.unwrap_or("");
let final_name = if ext.is_empty() { name.to_string() } else { format!("{}.{}", name, ext) };
let out_path = if ctx.kind == "sharedlib" {
platform::shared_lib_path(ctx.profile, ctx.project_name, ctx.target_dir)
platform::shared_lib_path(ctx.profile, &final_name, ctx.target_dir)
} else {
platform::bin_path(ctx.profile, ctx.project_name, ctx.target_dir)
platform::bin_path(ctx.profile, &final_name, ctx.target_dir)
};
cmd.arg("-o").arg(out_path);

View File

@@ -63,10 +63,14 @@ pub fn build(ctx: &BuildContext) -> Result<f64, String> {
for flag in ctx.ldflags {
cmd.arg(flag);
}
let name = ctx.output_filename.unwrap_or(ctx.project_name);
let ext = ctx.output_extension.unwrap_or("");
let final_name = if ext.is_empty() { name.to_string() } else { format!("{}.{}", name, ext) };
let out_path = if ctx.kind == "sharedlib" {
platform::shared_lib_path(ctx.profile, ctx.project_name, ctx.target_dir)
platform::shared_lib_path(ctx.profile, &final_name, ctx.target_dir)
} else {
platform::bin_path(ctx.profile, ctx.project_name, ctx.target_dir)
platform::bin_path(ctx.profile, &final_name, ctx.target_dir)
};
cmd.arg("-o").arg(out_path);