10 examples of 'go compiler' in Go

Every line of 'go compiler' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
38func (gccgoToolchain) compiler() string {
39 checkGccgoBin()
40 return GccgoBin
41}
222func runCgo(pkgpath string, cgofiles, cppflags, cflags []string) (gofiles, cfiles []string, err error) {
223 args := []string{
224 "tool", "cgo",
225 "-gccgo",
226 "-gccgopkgpath", pkgpath,
227 "-gccgoprefix", "woobie",
228 "-objdir", workdir,
229 "--",
230 }
231 args = append(args, cppflags...)
232 args = append(args, cflags...)
233 args = append(args, cgofiles...)
234 cmd := exec.Command("go", args...)
235 cmd.Stdout = os.Stdout
236 cmd.Stderr = os.Stderr
237 err = runCmd(cmd)
238 if err != nil {
239 return nil, nil, err
240 }
241 // Get the names of the generated Go and C files.
242 gofiles = []string{filepath.Join(workdir, "_cgo_gotypes.go")}
243 cfiles = []string{filepath.Join(workdir, "_cgo_export.c")}
244 for _, fn := range cgofiles {
245 f := cgoRe.ReplaceAllString(fn[:len(fn)-2], "_")
246 gofiles = append(gofiles, filepath.Join(workdir, f+"cgo1.go"))
247 cfiles = append(cfiles, filepath.Join(workdir, f+"cgo2.c"))
248 }
249 cfiles = append(cfiles, filepath.Join(workdir, "_cgo_defun.c"))
250
251 // gccgo uses "//extern" to name external symbols;
252 // translate them to "// #llgo name:".
253 for _, gofile := range gofiles {
254 if err := translateGccgoExterns(gofile); err != nil {
255 return nil, nil, fmt.Errorf("failed to translate gccgo extern comments for %q: %v", gofile, err)
256 }
257 }
258 return gofiles, cfiles, nil
259}
40func (ci windowsCompiler) compiler() string {
41 return filepath.Join(ci.binDir(), "cl.exe")
42}
19func Compiler() core.RouteCompiler {
20 return &compiler{}
21}
2280func (b *Builder) gcc(a *Action, p *load.Package, workdir, out string, flags []string, cfile string) error {
2281 return b.ccompile(a, p, out, flags, cfile, b.GccCmd(p.Dir, workdir))
2282}
2454func (b *Builder) cxxExe() []string {
2455 return b.compilerExe(origCXX, cfg.DefaultCXX(cfg.Goos, cfg.Goarch))
2456}
50func (worker *defaultWorker) compileC(
51 ctx context.Context,
52 workDir sandbox.Path,
53 sourceFilename,
54 outputFilename string,
55) (*compilationResult, error) {
56 cmd := sandbox.Command{
57 Path: "gcc",
58 Args: []string{
59 "-o", outputFilename,
60 "-Wall",
61 "-std=gnu11",
62 "-O2",
63 sourceFilename,
64 },
65 Dir: workDir,
66 }
67 return worker.genericCompile(ctx, workDir, sourceFilename, outputFilename, cmd)
68}
43func NewCompiler(debug bool) *Compiler {
44 return &Compiler{
45 labels: make(map[string]int),
46 debug: debug,
47 }
48}
560func (tools gccgoToolchain) cc(b *Builder, a *Action, ofile, cfile string) error {
561 p := a.Package
562 inc := filepath.Join(cfg.GOROOT, "pkg", "include")
563 cfile = mkAbs(p.Dir, cfile)
564 defs := []string{"-D", "GOOS_" + cfg.Goos, "-D", "GOARCH_" + cfg.Goarch}
565 defs = append(defs, b.gccArchArgs()...)
566 if pkgpath := tools.gccgoCleanPkgpath(b, p); pkgpath != "" {
567 defs = append(defs, `-D`, `GOPKGPATH="`+pkgpath+`"`)
568 }
569 compiler := envList("CC", cfg.DefaultCC(cfg.Goos, cfg.Goarch))
570 if b.gccSupportsFlag(compiler, "-fsplit-stack") {
571 defs = append(defs, "-fsplit-stack")
572 }
573 defs = tools.maybePIC(defs)
574 if b.gccSupportsFlag(compiler, "-ffile-prefix-map=a=b") {
575 defs = append(defs, "-ffile-prefix-map="+base.Cwd+"=.")
576 defs = append(defs, "-ffile-prefix-map="+b.WorkDir+"=/tmp/go-build")
577 } else if b.gccSupportsFlag(compiler, "-fdebug-prefix-map=a=b") {
578 defs = append(defs, "-fdebug-prefix-map="+b.WorkDir+"=/tmp/go-build")
579 }
580 if b.gccSupportsFlag(compiler, "-gno-record-gcc-switches") {
581 defs = append(defs, "-gno-record-gcc-switches")
582 }
583 return b.run(a, p.Dir, p.ImportPath, nil, compiler, "-Wall", "-g",
584 "-I", a.Objdir, "-I", inc, "-o", ofile, defs, "-c", cfile)
585}
3042func (b *builder) ccompile(p *Package, outfile string, flags []string, file string, compiler []string) error {
3043 file = mkAbs(p.Dir, file)
3044 desc := p.ImportPath
3045 output, err := b.runOut(p.Dir, desc, nil, compiler, flags, "-o", outfile, "-c", file)
3046 if len(output) > 0 {
3047 b.showOutput(p.Dir, desc, b.processOutput(output))
3048 if err != nil {
3049 err = errPrintedOutput
3050 } else if os.Getenv("GO_BUILDER_NAME") != "" {
3051 return errors.New("C compiler warning promoted to error on Go builders")
3052 }
3053 }
3054 return err
3055}

Related snippets