(rootfs context.RootFS, buildsystem string, portEnvs []string)
| 490 | } |
| 491 | |
| 492 | func (t Toolchain) SetEnvs(rootfs context.RootFS, buildsystem string, portEnvs []string) { |
| 493 | crosstoolPrefix := t.GetCrosstoolPrefix() |
| 494 | cc := t.GetCC() |
| 495 | cxx := t.GetCXX() |
| 496 | |
| 497 | // Capture CC/CXX from portEnvs if they are set. |
| 498 | for _, env := range portEnvs { |
| 499 | if before, after, ok := strings.Cut(env, "="); ok { |
| 500 | switch strings.TrimSpace(before) { |
| 501 | case "CC": |
| 502 | cc = strings.TrimSpace(after) |
| 503 | case "CXX": |
| 504 | cxx = strings.TrimSpace(after) |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | // cross tool prefix maybe empty for msvc in windows. |
| 510 | if crosstoolPrefix != "" { |
| 511 | os.Setenv("CROSSTOOL_PREFIX", crosstoolPrefix) |
| 512 | } |
| 513 | os.Setenv("HOST", t.GetHost()) |
| 514 | |
| 515 | // For CMake, compiler tools are defined in toolchain_file.cmake, skip environment variable setup. |
| 516 | if buildsystem == "cmake" { |
| 517 | return |
| 518 | } |
| 519 | |
| 520 | var ccFlags, cxxFlags []string |
| 521 | if t.ctx.CCacheEnabled() { |
| 522 | // For Windows + MSVC with Makefiles, don't set ccache in CC/CXX environment variables, |
| 523 | // because MSYS2 shell cannot handle "ccache cl.exe" as a command. |
| 524 | if runtime.GOOS == "windows" && (t.GetName() == "msvc" || t.GetName() == "clang-cl") && buildsystem == "makefiles" { |
| 525 | os.Setenv("CC", cc) |
| 526 | os.Setenv("CXX", cxx) |
| 527 | } else { |
| 528 | ccFlags = append(ccFlags, "ccache", cc) |
| 529 | cxxFlags = append(cxxFlags, "ccache", cxx) |
| 530 | |
| 531 | if rootfs != nil { |
| 532 | ccFlags = append(ccFlags, "--sysroot="+rootfs.GetAbsDir()) |
| 533 | cxxFlags = append(cxxFlags, "--sysroot="+rootfs.GetAbsDir()) |
| 534 | |
| 535 | // For Clang, add --gcc-toolchain to help find GCC runtime files (crtbeginS.o, etc.) |
| 536 | if t.GetName() == "clang" { |
| 537 | ccFlags = append(ccFlags, "--gcc-toolchain=/usr") |
| 538 | cxxFlags = append(cxxFlags, "--gcc-toolchain=/usr") |
| 539 | } |
| 540 | |
| 541 | // For clang with lld, add LLVM runtime library flags. |
| 542 | if t.GetName() == "clang" && strings.Contains(t.GetLD(), "lld") { |
| 543 | ccFlags = append(ccFlags, "-fuse-ld=lld", "--rtlib=compiler-rt", "--unwindlib=libunwind") |
| 544 | cxxFlags = append(cxxFlags, "-stdlib=libc++", "-fuse-ld=lld", "--rtlib=compiler-rt", "--unwindlib=libunwind") |
| 545 | } |
| 546 | } |
| 547 | os.Setenv("CC", strings.Join(ccFlags, " ")) |
| 548 | os.Setenv("CXX", strings.Join(cxxFlags, " ")) |
| 549 | } |
nothing calls this directly
no test coverage detected