Source file src/simd/archsimd/_gen/specgen/flag.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package specgen
     6  
     7  import (
     8  	"fmt"
     9  	"os"
    10  	"os/exec"
    11  	"path/filepath"
    12  	"strings"
    13  )
    14  
    15  // FindSpecDir returns the path to the standard spec package
    16  // $GOROOT/simd/internal/spec.
    17  func FindSpecDir() (string, error) {
    18  	goroot, err := goEnvGoroot()
    19  	if err != nil {
    20  		return "", fmt.Errorf("could not find GOROOT: %w", err)
    21  	}
    22  	path := filepath.Join(goroot, "src/simd/internal/spec")
    23  	if _, err := os.Stat(path); err != nil {
    24  		return "", fmt.Errorf("could not find spec package: %w (this tool requires a complete Go checkout)", err)
    25  	}
    26  	return path, nil
    27  }
    28  
    29  func MustFindSpecDir() string {
    30  	path, err := FindSpecDir()
    31  	if err != nil {
    32  		fmt.Fprintln(os.Stderr, err.Error())
    33  		os.Exit(1)
    34  	}
    35  	return path
    36  }
    37  
    38  func goEnvGoroot() (string, error) {
    39  	out, err := exec.Command("go", "env", "GOROOT").Output()
    40  	if err != nil {
    41  		return "", err
    42  	}
    43  	return strings.TrimSpace(string(out)), nil
    44  }
    45  

View as plain text