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

Method Detect

configs/toolchain_windows.go:248–298  ·  view source on GitHub ↗

Detect detect local installed MSVC.

(toolchainName string)

Source from the content-addressed store, hash-verified

246
247// Detect detect local installed MSVC.
248func (t *Toolchain) Detect(toolchainName string) error {
249 if err := buildtools.CheckTools(t.ctx, "git", "vswhere"); err != nil {
250 return fmt.Errorf("vswhere is not available -> %w", err)
251 }
252
253 // Query all available msvc installation paths.
254 command := "vswhere -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath"
255 exector := cmd.NewExecutor("", command)
256 output, err := exector.ExecuteOutput()
257 if err != nil {
258 return err
259 }
260
261 // Trim the output.
262 msvcDir := strings.TrimSpace(output)
263 if msvcDir == "" {
264 return fmt.Errorf("msvc not found, please install msvc first")
265 }
266
267 switch toolchainName {
268 case "", "msvc", "clang-cl":
269 version, err := t.findLatestMSVCVersion(filepath.Join(msvcDir, "VC", "Tools", "MSVC"))
270 if err != nil {
271 return err
272 }
273 t.Version = version
274
275 case "clang":
276 t.Version = "" // clang version is not required
277
278 default:
279 return fmt.Errorf("unsupported toolchain name: %s", toolchainName)
280 }
281
282 t.Url = "file:///" + msvcDir
283 // In windows, if no toolchain name is specified, use msvc as default.
284 t.Name = expr.If(toolchainName == "", "msvc", toolchainName)
285 t.SystemName = "Windows"
286 t.SystemProcessor = "x86_64"
287 t.Host = "x86_64-w64-mingw32"
288
289 if err := t.Validate(); err != nil {
290 return err
291 }
292
293 if err := t.CheckAndRepair(true); err != nil {
294 return err
295 }
296
297 return nil
298}
299
300func (Toolchain) arch() string {
301 switch runtime.GOARCH {

Callers

nothing calls this directly

Calls 7

findLatestMSVCVersionMethod · 0.95
ValidateMethod · 0.95
CheckAndRepairMethod · 0.95
CheckToolsFunction · 0.92
NewExecutorFunction · 0.92
IfFunction · 0.92
ExecuteOutputMethod · 0.80

Tested by

no test coverage detected