MCPcopy Create free account
hub / github.com/celer-pkg/celer / SetEnvs

Method SetEnvs

configs/toolchain.go:492–613  ·  view source on GitHub ↗
(rootfs context.RootFS, buildsystem string, portEnvs []string)

Source from the content-addressed store, hash-verified

490}
491
492func (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 }

Callers

nothing calls this directly

Calls 15

GetCrosstoolPrefixMethod · 0.95
GetCCMethod · 0.95
GetCXXMethod · 0.95
GetHostMethod · 0.95
GetNameMethod · 0.95
GetLDMethod · 0.95
GetASMethod · 0.95
GetFCMethod · 0.95
GetRANLIBMethod · 0.95
GetARMethod · 0.95
GetNMMethod · 0.95
GetOBJCOPYMethod · 0.95

Tested by

no test coverage detected