crossbuild-core 1.0.0

Core types, models, and traits for the cargo-crossbuild ecosystem
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
//! Provider implementations for toolchain, sysroot, and linker resolution.

use std::collections::BTreeMap;
use std::path::PathBuf;

use crate::{
    model::{Abi, Architecture, BuildRequest, HostInfo, OperatingSystem, TargetFamily, TargetTriple, ToolchainHint},
    error::CrossBuildError,
};

/// A toolchain provider supplies the compiler toolchain for a target.
pub trait ToolchainProvider: Send + Sync {
    /// Returns the unique name of this provider.
    fn name(&self) -> &'static str;

    /// Returns the priority of this provider (higher = preferred).
    fn priority(&self) -> i32 {
        0
    }

    /// Checks if this provider can handle the given target on this host.
    fn can_provide(&self, target: &TargetTriple, host: &HostInfo) -> bool;

    /// Resolves the toolchain for the target, returning environment variables
    /// and configuration needed to use it.
    fn resolve(
        &self,
        target: &TargetTriple,
        host: &HostInfo,
        request: &BuildRequest,
    ) -> Result<ToolchainResolution, CrossBuildError>;

    /// Returns the toolchain hint this provider satisfies.
    fn hint(&self) -> ToolchainHint;
}

/// Resolution result from a toolchain provider.
#[derive(Debug, Clone, PartialEq)]
pub struct ToolchainResolution {
    pub env: BTreeMap<String, String>,
    pub cargo_config: Option<toml::Table>,
    pub notes: Vec<String>,
    pub rustc_path: Option<PathBuf>,
    pub cargo_path: Option<PathBuf>,
    pub target_spec: Option<String>,
    pub rustflags: Vec<String>,
}

impl ToolchainResolution {
    pub fn new() -> Self {
        Self {
            env: BTreeMap::new(),
            cargo_config: None,
            notes: Vec::new(),
            rustc_path: None,
            cargo_path: None,
            target_spec: None,
            rustflags: Vec::new(),
        }
    }

    pub fn with_env(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
        self.env.insert(key.into(), value.into());
        self
    }

    pub fn with_cargo_config(mut self, config: toml::Table) -> Self {
        self.cargo_config = Some(config);
        self
    }

    pub fn with_note(mut self, note: impl Into<String>) -> Self {
        self.notes.push(note.into());
        self
    }

    pub fn with_rustc(mut self, path: PathBuf) -> Self {
        self.rustc_path = Some(path);
        self
    }

    pub fn with_cargo(mut self, path: PathBuf) -> Self {
        self.cargo_path = Some(path);
        self
    }

    pub fn with_target_spec(mut self, spec: String) -> Self {
        self.target_spec = Some(spec);
        self
    }

    pub fn with_rustflags(mut self, flags: Vec<String>) -> Self {
        self.rustflags = flags;
        self
    }
}

impl Default for ToolchainResolution {
    fn default() -> Self {
        Self::new()
    }
}

/// A sysroot provider supplies the target sysroot (libc, libstd, crt objects).
pub trait SysrootProvider: Send + Sync {
    /// Returns the unique name of this provider.
    fn name(&self) -> &'static str;

    /// Returns the priority of this provider (higher = preferred).
    fn priority(&self) -> i32 {
        0
    }

    /// Checks if this provider can handle the given target on this host.
    fn can_provide(&self, target: &TargetTriple, host: &HostInfo) -> bool;

    /// Resolves the sysroot for the target.
    fn resolve(
        &self,
        target: &TargetTriple,
        host: &HostInfo,
        request: &BuildRequest,
    ) -> Result<SysrootResolution, CrossBuildError>;
}

/// Resolution result from a sysroot provider.
#[derive(Debug, Clone, PartialEq)]
pub struct SysrootResolution {
    pub sysroot_path: PathBuf,
    pub env: BTreeMap<String, String>,
    pub cargo_config: Option<toml::Table>,
    pub notes: Vec<String>,
    pub is_builtin: bool,
}

impl SysrootResolution {
    pub fn new(sysroot_path: PathBuf) -> Self {
        Self {
            sysroot_path,
            env: BTreeMap::new(),
            cargo_config: None,
            notes: Vec::new(),
            is_builtin: false,
        }
    }

    pub fn with_env(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
        self.env.insert(key.into(), value.into());
        self
    }

    pub fn with_cargo_config(mut self, config: toml::Table) -> Self {
        self.cargo_config = Some(config);
        self
    }

    pub fn with_note(mut self, note: impl Into<String>) -> Self {
        self.notes.push(note.into());
        self
    }

    pub fn with_builtin(mut self, builtin: bool) -> Self {
        self.is_builtin = builtin;
        self
    }
}

/// A linker provider supplies the appropriate linker for a target.
pub trait LinkerProvider: Send + Sync {
    /// Returns the unique name of this provider.
    fn name(&self) -> &'static str;

    /// Returns the priority of this provider (higher = preferred).
    fn priority(&self) -> i32 {
        0
    }

    /// Checks if this provider can handle the given target on this host.
    fn can_provide(&self, target: &TargetTriple, host: &HostInfo) -> bool;

    /// Resolves the linker for the target.
    fn resolve(
        &self,
        target: &TargetTriple,
        host: &HostInfo,
        request: &BuildRequest,
    ) -> Result<LinkerResolution, CrossBuildError>;
}

/// Resolution result from a linker provider.
#[derive(Debug, Clone, PartialEq)]
pub struct LinkerResolution {
    pub linker_path: PathBuf,
    pub linker_args: Vec<String>,
    pub env: BTreeMap<String, String>,
    pub cargo_config: Option<toml::Table>,
    pub notes: Vec<String>,
    pub flavor: LinkerFlavor,
}

impl LinkerResolution {
    pub fn new(linker_path: PathBuf, flavor: LinkerFlavor) -> Self {
        Self {
            linker_path,
            linker_args: Vec::new(),
            env: BTreeMap::new(),
            cargo_config: None,
            notes: Vec::new(),
            flavor,
        }
    }

    pub fn with_args(mut self, args: Vec<String>) -> Self {
        self.linker_args = args;
        self
    }

    pub fn with_env(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
        self.env.insert(key.into(), value.into());
        self
    }

    pub fn with_cargo_config(mut self, config: toml::Table) -> Self {
        self.cargo_config = Some(config);
        self
    }

    pub fn with_note(mut self, note: impl Into<String>) -> Self {
        self.notes.push(note.into());
        self
    }
}

/// Linker flavor for cargo configuration.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LinkerFlavor {
    Gnu,
    Msvc,
    Lld,
    Mold,
    WasmLld,
    Darwin,
}

impl LinkerFlavor {
    pub fn cargo_name(&self) -> &str {
        match self {
            LinkerFlavor::Gnu => "gcc",
            LinkerFlavor::Msvc => "msvc",
            LinkerFlavor::Lld => "ld.lld",
            LinkerFlavor::Mold => "mold",
            LinkerFlavor::WasmLld => "wasm-ld",
            LinkerFlavor::Darwin => "ld64",
        }
    }
}

/// Provider action returned to the build plan.
#[derive(Debug, Clone, PartialEq)]
pub struct ProviderAction {
    pub provider_name: String,
    pub notes: Vec<String>,
    pub env: BTreeMap<String, String>,
    pub cargo_config: Option<toml::Table>,
}

/// Trait for targets that can convert to zig target string.
trait ZigTarget {
    fn to_zig_target(&self) -> String;
}

impl ZigTarget for crate::model::TargetTriple {
    fn to_zig_target(&self) -> String {
        let arch = match self.arch {
            Architecture::X86_64 => "x86_64",
            Architecture::AArch64 => "aarch64",
            Architecture::X86 => "x86",
            Architecture::Arm => "arm",
            Architecture::Arm64 => "aarch64",
            Architecture::RiscV64 => "riscv64",
            Architecture::PowerPC64 => "powerpc64le",
            Architecture::S390x => "s390x",
            Architecture::Mips64 => "mips64",
            Architecture::LoongArch64 => "loongarch64",
            Architecture::Wasm32 => "wasm32",
            Architecture::Wasm64 => "wasm64",
            Architecture::Other(ref s) => s,
        };

        let os = match self.os {
            OperatingSystem::Linux => "linux",
            OperatingSystem::Windows => "windows",
            OperatingSystem::MacOs => "macos",
            OperatingSystem::FreeBSD => "freebsd",
            OperatingSystem::NetBSD => "netbsd",
            OperatingSystem::OpenBSD => "openbsd",
            OperatingSystem::DragonflyBSD => "dragonflybsd",
            OperatingSystem::Solaris => "solaris",
            OperatingSystem::Illumos => "illumos",
            OperatingSystem::Android => "android",
            OperatingSystem::Wasm => "wasi",
            OperatingSystem::Wasi => "wasi",
            OperatingSystem::None => "freestanding",
            OperatingSystem::Uefi => "uefi",
            OperatingSystem::Ios => "ios",
            OperatingSystem::TvOS => "tvos",
            OperatingSystem::WatchOS => "watchos",
            OperatingSystem::Heron => "heron",
            OperatingSystem::Zos => "zos",
            OperatingSystem::Fuchsia => "fuchsia",
            OperatingSystem::Redox => "redox",
            OperatingSystem::Other(ref s) => s,
        };

        let abi = match self.abi {
            Abi::Gnu => "gnu",
            Abi::Musl => "musl",
            Abi::Msvc => "msvc",
            Abi::Android => "android",
            Abi::Wasm32 => "wasi",
            Abi::None => "",
            Abi::Eabi => "eabi",
            Abi::Eabihf => "eabihf",
            Abi::Simulator => "simulator",
            Abi::Uwp => "uwp",
            Abi::Wasm64 => "wasi",
        };

        if abi.is_empty() {
            format!("{}-{}", arch, os)
        } else {
            format!("{}-{}-{}", arch, os, abi)
        }
    }
}

/// Rustup-based toolchain provider.
pub struct RustupToolchainProvider;

impl ToolchainProvider for RustupToolchainProvider {
    fn name(&self) -> &'static str {
        "rustup"
    }

    fn priority(&self) -> i32 {
        100
    }

    fn can_provide(&self, target: &TargetTriple, host: &HostInfo) -> bool {
        // Can provide if target is available via rustup
        if target.triple == host.host_triple.triple {
            return true;
        }
        crate::platform::rustup_target_available(target)
    }

    fn resolve(
        &self,
        target: &TargetTriple,
        host: &HostInfo,
        _request: &BuildRequest,
    ) -> Result<ToolchainResolution, CrossBuildError> {
        let mut resolution = ToolchainResolution::new();

        if target.triple == host.host_triple.triple {
            resolution = resolution
                .with_note("Using host toolchain for native build")
                .with_rustc(which::which("rustc")?)
                .with_cargo(which::which("cargo")?);
        } else {
            // Cross-compilation with rustup target
            let rustup_home = std::env::var("RUSTUP_HOME")
                .map(PathBuf::from)
                .or_else(|_| {
                    std::env::var("HOME")
                        .or_else(|_| std::env::var("USERPROFILE"))
                        .map(|h| PathBuf::from(h).join(".rustup"))
                })
                .unwrap_or_else(|_| PathBuf::from("/rustup"));

            let toolchain = find_rustup_toolchain(&rustup_home.to_string_lossy())?;
            let toolchain_path = rustup_home.join("toolchains").join(&toolchain);

            let rustc_path = toolchain_path.join("bin").join("rustc");
            let cargo_path = toolchain_path.join("bin").join("cargo");

            resolution = resolution
                .with_note(format!("Using rustup toolchain: {toolchain}"))
                .with_rustc(rustc_path)
                .with_cargo(cargo_path)
                .with_env("RUSTUP_TOOLCHAIN", toolchain);
        }

        // Add target specification if not native
        if target.triple != host.host_triple.triple {
            resolution = resolution
                .with_target_spec(target.triple.clone())
                .with_env("CARGO_BUILD_TARGET", target.triple.clone());
        }

        Ok(resolution)
    }

    fn hint(&self) -> ToolchainHint {
        ToolchainHint::Rustup
    }
}

/// Zig-based toolchain provider.
pub struct ZigToolchainProvider;

impl ToolchainProvider for ZigToolchainProvider {
    fn name(&self) -> &'static str {
        "zig"
    }

    fn priority(&self) -> i32 {
        50
    }

    fn can_provide(&self, target: &TargetTriple, _host: &HostInfo) -> bool {
        // Zig can target most platforms
        !matches!(target.family(), TargetFamily::Other | TargetFamily::BareMetal)
            || target.is_wasm()
    }

    fn resolve(
        &self,
        target: &TargetTriple,
        _host: &HostInfo,
        _request: &BuildRequest,
    ) -> Result<ToolchainResolution, CrossBuildError> {
        let zig_path = which::which("zig").map_err(|_| CrossBuildError::ToolNotFound {
            tool: "zig".to_string(),
        })?;

        let target_arg = target.to_zig_target();

        let mut resolution = ToolchainResolution::new()
            .with_note(format!("Using zig cc for target: {target_arg}"))
            .with_rustc(zig_path.clone())
            .with_cargo(which::which("cargo")?)
            .with_env("CC", format!("zig cc -target {}", target_arg))
            .with_env("CXX", format!("zig c++ -target {}", target_arg))
            .with_env("AR", "zig ar")
            .with_env("CARGO_TARGET_RUNNER", format!("zig cc -target {}", target_arg));

        // Add linker flags for zig
        resolution = resolution.with_env(
            "CARGO_TARGET_RUSTFLAGS",
            format!("-C linker=zig cc -target {}", target_arg),
        );

        Ok(resolution)
    }

    fn hint(&self) -> ToolchainHint {
        ToolchainHint::Zig
    }
}

/// Built-in toolchain provider (host native only).
pub struct BuiltinToolchainProvider;

impl ToolchainProvider for BuiltinToolchainProvider {
    fn name(&self) -> &'static str {
        "builtin"
    }

    fn priority(&self) -> i32 {
        200
    }

    fn can_provide(&self, target: &TargetTriple, host: &HostInfo) -> bool {
        target.triple == host.host_triple.triple
    }

    fn resolve(
        &self,
        _target: &TargetTriple,
        _host: &HostInfo,
        _request: &BuildRequest,
    ) -> Result<ToolchainResolution, CrossBuildError> {
        Ok(ToolchainResolution::new()
            .with_note("Using host toolchain")
            .with_rustc(which::which("rustc")?)
            .with_cargo(which::which("cargo")?))
    }

    fn hint(&self) -> ToolchainHint {
        ToolchainHint::Rustup
    }
}

/// Rustup-based sysroot provider.
pub struct RustupSysrootProvider;

impl SysrootProvider for RustupSysrootProvider {
    fn name(&self) -> &'static str {
        "rustup"
    }

    fn priority(&self) -> i32 {
        100
    }

    fn can_provide(&self, target: &TargetTriple, host: &HostInfo) -> bool {
        if target.triple == host.host_triple.triple {
            return false; // Native builds don't need sysroot
        }
        crate::platform::rustup_target_available(target)
    }

    fn resolve(
        &self,
        target: &TargetTriple,
        host: &HostInfo,
        _request: &BuildRequest,
    ) -> Result<SysrootResolution, CrossBuildError> {
        if target.triple == host.host_triple.triple {
            return Err(CrossBuildError::SysrootNotNeeded);
        }

        let rustup_home = std::env::var("RUSTUP_HOME")
            .map(PathBuf::from)
            .or_else(|_| {
                std::env::var("HOME")
                    .or_else(|_| std::env::var("USERPROFILE"))
                    .map(|h| PathBuf::from(h).join(".rustup"))
            })
            .unwrap_or_else(|_| PathBuf::from("/rustup"));

        let toolchain = find_rustup_toolchain(&rustup_home.to_string_lossy())?;
        let sysroot = rustup_home
            .join("toolchains")
            .join(&toolchain)
            .join("lib")
            .join("rustlib")
            .join(&target.triple);

        if !sysroot.exists() {
            return Err(CrossBuildError::SysrootNotFound {
                target: target.triple.clone(),
            });
        }

        let mut resolution = SysrootResolution::new(sysroot.clone())
            .with_note(format!("Using rustup sysroot from toolchain: {toolchain}"))
            .with_env("CARGO_SYSROOT", sysroot.to_string_lossy())
            .with_builtin(true);

        // Add linker search paths
        let lib_dir = sysroot.join("lib");
        if lib_dir.exists() {
            resolution = resolution.with_env("LIBRARY_PATH", lib_dir.to_string_lossy());
        }

        Ok(resolution)
    }
}

/// Zig-based sysroot provider.
pub struct ZigSysrootProvider;

impl SysrootProvider for ZigSysrootProvider {
    fn name(&self) -> &'static str {
        "zig"
    }

    fn priority(&self) -> i32 {
        50
    }

    fn can_provide(&self, target: &TargetTriple, _host: &HostInfo) -> bool {
        // Zig provides sysroots for many targets
        !matches!(target.os, OperatingSystem::None)
    }

    fn resolve(
        &self,
        target: &TargetTriple,
        _host: &HostInfo,
        _request: &BuildRequest,
    ) -> Result<SysrootResolution, CrossBuildError> {
        let _ = which::which("zig").map_err(|_| CrossBuildError::ToolNotFound {
            tool: "zig".to_string(),
        })?;

        // Zig doesn't have a separate sysroot - it uses its internal libc
        let sysroot = std::env::temp_dir().join("zig-sysroot").join(&target.triple);

        let resolution = SysrootResolution::new(sysroot)
            .with_note("Using zig's built-in libc/sysroot")
            .with_env("ZIG_SYSROOT", "1");

        Ok(resolution)
    }
}

/// No sysroot needed (wasm, bare metal).
pub struct NoSysrootProvider;

impl SysrootProvider for NoSysrootProvider {
    fn name(&self) -> &'static str {
        "none"
    }

    fn priority(&self) -> i32 {
        200
    }

    fn can_provide(&self, target: &TargetTriple, host: &HostInfo) -> bool {
        target.triple == host.host_triple.triple
            || target.is_wasm()
            || target.is_bare_metal()
    }

    fn resolve(
        &self,
        target: &TargetTriple,
        host: &HostInfo,
        _request: &BuildRequest,
    ) -> Result<SysrootResolution, CrossBuildError> {
        if target.triple == host.host_triple.triple {
            return Err(CrossBuildError::SysrootNotNeeded);
        }

        Ok(SysrootResolution::new(PathBuf::new())
            .with_note("No sysroot required for this target"))
    }
}

#[allow(dead_code)]
/// Checks if a target is available via rustup.
fn is_rustup_target_available(target: &TargetTriple) -> bool {
    // Check common rustup targets
    const RUSTUP_TARGETS: &[&str] = &[
        "x86_64-unknown-linux-gnu",
        "x86_64-unknown-linux-musl",
        "aarch64-unknown-linux-gnu",
        "aarch64-unknown-linux-musl",
        "x86_64-pc-windows-msvc",
        "x86_64-pc-windows-gnu",
        "aarch64-pc-windows-msvc",
        "i686-pc-windows-msvc",
        "i686-pc-windows-gnu",
        "x86_64-apple-darwin",
        "aarch64-apple-darwin",
        "wasm32-wasi",
        "wasm32-unknown-unknown",
        "wasm32-unknown-emscripten",
        "x86_64-unknown-freebsd",
        "aarch64-unknown-freebsd",
        "powerpc64le-unknown-linux-gnu",
        "s390x-unknown-linux-gnu",
        "riscv64gc-unknown-linux-gnu",
    ];

    RUSTUP_TARGETS.contains(&target.triple.as_str())
}

/// Finds the default rustup toolchain.
fn find_rustup_toolchain(rustup_home: &str) -> Result<String, CrossBuildError> {
    let toolchains_dir = PathBuf::from(rustup_home).join("toolchains");
    if !toolchains_dir.exists() {
        return Err(CrossBuildError::SysrootNotFound {
            target: "rustup".to_string(),
        });
    }

    // Read the default toolchain
    let default_file = PathBuf::from(rustup_home).join("settings").join("default-toolchain");
    if default_file.exists() {
        let content = std::fs::read_to_string(&default_file)
            .map_err(|_| CrossBuildError::SysrootNotFound {
                target: "rustup".to_string(),
            })?;
        let toolchain = content.trim().to_string();
        if toolchains_dir.join(&toolchain).exists() {
            return Ok(toolchain);
        }
    }

    // Fallback: find first stable toolchain
    for entry in std::fs::read_dir(&toolchains_dir).map_err(|_| CrossBuildError::SysrootNotFound {
        target: "rustup".to_string(),
    })? {
        let entry = entry.map_err(|_| CrossBuildError::SysrootNotFound {
            target: "rustup".to_string(),
        })?;
        let name = entry.file_name().to_string_lossy().to_string();
        if name.contains("stable") || name.contains("1.") {
            return Ok(name);
        }
    }

    Err(CrossBuildError::SysrootNotFound {
        target: "rustup".to_string(),
    })
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::model::TargetTriple;

    #[test]
    fn zig_target_conversion() {
        let targets = [
            ("x86_64-unknown-linux-gnu", "x86_64-linux-gnu"),
            ("aarch64-unknown-linux-musl", "aarch64-linux-musl"),
            ("x86_64-pc-windows-msvc", "x86_64-windows-msvc"),
            ("wasm32-wasi", "wasm32-wasi"),
        ];

        for (input, expected) in targets {
            let target = TargetTriple::parse(input).unwrap();
            assert_eq!(target.to_zig_target(), expected);
        }
    }

    #[test]
    fn rustup_provider_native() {
        let provider = RustupToolchainProvider;
        let host = crate::model::HostInfo::detect().unwrap();
        let target = TargetTriple::parse(&host.host_triple.triple).unwrap();
        assert!(provider.can_provide(&target, &host));
    }
}