msvcEnvs provider the MSVC environment variables required by msys2.
()
| 923 | |
| 924 | // msvcEnvs provider the MSVC environment variables required by msys2. |
| 925 | func (b BuildConfig) msvcEnvs() (string, error) { |
| 926 | // Append args if exist. |
| 927 | var args []string |
| 928 | var appendEnv = func(envKey, envValue string) { |
| 929 | if envValue != "" { |
| 930 | args = append(args, fmt.Sprintf(`%s="%s"`, envKey, envValue)) |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | var cflags, cxxflags, ldflags []string |
| 935 | |
| 936 | // Set CFLAGS/CXXFLAGS/LDFLAGS. |
| 937 | tmpDepsDir := filepath.Join(dirs.TmpDepsDir, b.PortConfig.LibraryDir) |
| 938 | var appendIncludeDir = func(includeDir string) { |
| 939 | includeDir = fileio.ToCygpath(includeDir) |
| 940 | includeFlag := "-I" + includeDir |
| 941 | cflags = append(cflags, includeFlag) |
| 942 | cxxflags = append(cxxflags, includeFlag) |
| 943 | } |
| 944 | var appendLibDir = func(libdir string) { |
| 945 | libdir = fileio.ToCygpath(libdir) |
| 946 | lFlag := "-L" + libdir |
| 947 | rFlag := "-Wl,-rpath-link," + libdir |
| 948 | |
| 949 | // Add -L/rpath-link flag. |
| 950 | if !slices.Contains(ldflags, lFlag) { |
| 951 | ldflags = append(ldflags, lFlag) |
| 952 | } |
| 953 | if !slices.Contains(ldflags, rFlag) { |
| 954 | ldflags = append(ldflags, rFlag) |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | var ( |
| 959 | toolchain = b.Ctx.Platform().GetToolchain() |
| 960 | rootfs = b.Ctx.Platform().GetRootFS() |
| 961 | ) |
| 962 | |
| 963 | // sysroot and tmp dir. |
| 964 | if b.DevDep || b.HostDev { |
| 965 | // Append CFLAGS/CXXFLAGS/LDFLAGS |
| 966 | appendIncludeDir(filepath.Join(tmpDepsDir, "include")) |
| 967 | appendLibDir(filepath.Join(tmpDepsDir, "lib")) |
| 968 | } else if rootfs != nil { |
| 969 | // Update CFLAGS/CXXFLAGS |
| 970 | sysrootDir := rootfs.GetAbsDir() |
| 971 | appendIncludeDir(filepath.Join(tmpDepsDir, "include")) |
| 972 | for _, dir := range rootfs.GetIncludeDirs() { |
| 973 | appendIncludeDir(filepath.Join(sysrootDir, dir)) |
| 974 | } |
| 975 | |
| 976 | // Append LDFLAGS |
| 977 | appendLibDir(filepath.Join(tmpDepsDir, "lib")) |
| 978 | for _, dir := range rootfs.GetLibDirs() { |
| 979 | appendLibDir(filepath.Join(sysrootDir, dir)) |
| 980 | } |
| 981 | } |
| 982 | appendEnv("CFLAGS", strings.Join(cflags, " ")) |
no test coverage detected