# Build Targets Configuration for Nushell Plugins
# Defines supported cross-compilation targets and their requirements

[metadata]
version = "1.0.0"
description = "Cross-compilation targets for nushell plugins"
last_updated = "2024-09-20"

# Default settings applied to all targets unless overridden
[defaults]
docker_image = "nushell-plugins-cross:latest"
strip_binaries = true
optimize_size = true

# Linux AMD64 - Most common Linux target
[targets.linux-amd64]
rust_target = "x86_64-unknown-linux-gnu"
platform_name = "linux-amd64"
archive_format = "tar.gz"
docker_required = false
native_build = true
description = "Linux x86_64 (64-bit Intel/AMD)"

# Linux ARM64 - Growing in popularity with cloud instances
[targets.linux-arm64]
rust_target = "aarch64-unknown-linux-gnu"
platform_name = "linux-arm64"
archive_format = "tar.gz"
docker_required = true
native_build = false
description = "Linux ARM64 (64-bit ARM)"
linker = "aarch64-linux-gnu-gcc"

# macOS AMD64 - Intel Macs
[targets.darwin-amd64]
rust_target = "x86_64-apple-darwin"
platform_name = "darwin-amd64"
archive_format = "tar.gz"
docker_required = false
native_build = true
host_required = "darwin"
description = "macOS x86_64 (Intel Macs)"

# macOS ARM64 - Apple Silicon Macs
[targets.darwin-arm64]
rust_target = "aarch64-apple-darwin"
platform_name = "darwin-arm64"
archive_format = "tar.gz"
docker_required = false
native_build = true
host_required = "darwin"
description = "macOS ARM64 (Apple Silicon)"

# Windows AMD64 - Standard Windows target
[targets.windows-amd64]
rust_target = "x86_64-pc-windows-msvc"
platform_name = "windows-amd64"
archive_format = "zip"
docker_required = true
native_build = false
description = "Windows x86_64 (64-bit)"
binary_extension = ".exe"

# Additional targets that can be enabled
[targets.linux-arm32]
rust_target = "armv7-unknown-linux-gnueabihf"
platform_name = "linux-arm32"
archive_format = "tar.gz"
docker_required = true
native_build = false
enabled = false
description = "Linux ARM32 (32-bit ARM)"

[targets.windows-arm64]
rust_target = "aarch64-pc-windows-msvc"
platform_name = "windows-arm64"
archive_format = "zip"
docker_required = true
native_build = false
enabled = false
description = "Windows ARM64"
binary_extension = ".exe"

# Docker configuration for cross-compilation
[docker]
dockerfile = "Dockerfile.cross"
image_tag = "nushell-plugins-cross:latest"
cache_from = ["nushell-plugins-cross:cache"]
build_args = []

# Platform-specific configurations
[platform_configs.linux]
package_formats = ["tar.gz", "deb", "rpm"]
install_prefix = "/usr/local/bin"
config_dir = "/etc/nushell-plugins"

[platform_configs.darwin]
package_formats = ["tar.gz", "dmg"]
install_prefix = "/usr/local/bin"
config_dir = "/usr/local/etc/nushell-plugins"

[platform_configs.windows]
package_formats = ["zip", "msi"]
install_prefix = "C:\\Program Files\\nushell-plugins"
config_dir = "C:\\ProgramData\\nushell-plugins"

# Build optimization settings
[optimization]
# Enable link-time optimization for release builds
lto = true
# Code generation units for parallel compilation
codegen_units = 1
# Panic strategy (abort for smaller binaries)
panic_strategy = "abort"
# Strip debug symbols
strip = "symbols"

# Environment variables for cross-compilation
[environment]
# Common variables for all builds
RUST_BACKTRACE = "1"
CARGO_INCREMENTAL = "0"

# Target-specific environment variables
[environment.linux-arm64]
CC = "aarch64-linux-gnu-gcc"
CXX = "aarch64-linux-gnu-g++"
AR = "aarch64-linux-gnu-ar"
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = "aarch64-linux-gnu-gcc"

[environment.windows-amd64]
# Windows-specific environment setup would go here
# Usually handled by the Docker container

# Feature flags for conditional compilation
[features]
# Default features to enable for all builds
default = ["clipboard", "image", "networking"]

# Optional features that can be disabled for smaller binaries
optional = ["crypto", "database", "desktop-notifications"]

# Platform-specific features
[features.linux]
available = ["clipboard", "image", "networking", "desktop-notifications"]

[features.darwin]
available = ["clipboard", "image", "networking", "desktop-notifications"]

[features.windows]
available = ["clipboard", "image", "networking"]

# Validation rules for targets
[validation]
# Minimum required Rust version
min_rust_version = "1.70.0"

# Required tools for native compilation
required_tools = ["cargo", "rustc"]

# Required tools for Docker compilation
docker_tools = ["docker"]

# Testing configuration
[testing]
# Run tests for these targets during CI
ci_targets = ["linux-amd64", "darwin-amd64", "darwin-arm64"]

# Quick test targets for development
dev_targets = ["linux-amd64"]

# Full integration test targets
integration_targets = ["linux-amd64", "darwin-arm64"]