github.com/jd-ly/tools@v0.5.7/internal/typesinternal/types.go (about)

     1  // Copyright 2020 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 typesinternal
     6  
     7  import (
     8  	"go/types"
     9  	"reflect"
    10  	"unsafe"
    11  )
    12  
    13  func SetUsesCgo(conf *types.Config) bool {
    14  	v := reflect.ValueOf(conf).Elem()
    15  
    16  	f := v.FieldByName("go115UsesCgo")
    17  	if !f.IsValid() {
    18  		f = v.FieldByName("UsesCgo")
    19  		if !f.IsValid() {
    20  			return false
    21  		}
    22  	}
    23  
    24  	addr := unsafe.Pointer(f.UnsafeAddr())
    25  	*(*bool)(addr) = true
    26  
    27  	return true
    28  }