MCPcopy Index your code
hub / github.com/tinygo-org/tinygo / LoadTarget

Function LoadTarget

compileopts/target.go:192–231  ·  view source on GitHub ↗

Load a target specification.

(options *Options)

Source from the content-addressed store, hash-verified

190
191// Load a target specification.
192func LoadTarget(options *Options) (*TargetSpec, error) {
193 if options.Target == "" && options.GOARCH == "wasm" {
194 // Set a specific target if we're building from a known GOOS/GOARCH
195 // combination that is defined in a target JSON file.
196 switch options.GOOS {
197 case "js":
198 options.Target = "wasm"
199 case "wasip1":
200 options.Target = "wasip1"
201 case "wasip2":
202 options.Target = "wasip2"
203 default:
204 return nil, errors.New("GOARCH=wasm but GOOS is not set correctly. Please set GOOS to js, wasip1, or wasip2.")
205 }
206 }
207
208 if options.Target == "" {
209 return defaultTarget(options)
210 }
211
212 // See whether there is a target specification for this target (e.g.
213 // Arduino).
214 spec := &TargetSpec{}
215 err := spec.loadFromGivenStr(options.Target)
216 if err != nil {
217 return nil, err
218 }
219 // Successfully loaded this target from a built-in .json file. Make sure
220 // it includes all parents as specified in the "inherits" key.
221 err = spec.resolveInherits()
222 if err != nil {
223 return nil, fmt.Errorf("%s : %w", options.Target, err)
224 }
225
226 if spec.Scheduler == "asyncify" {
227 spec.ExtraFiles = append(spec.ExtraFiles, "src/internal/task/task_asyncify_wasm.S")
228 }
229
230 return spec, nil
231}
232
233// GetTargetSpecs retrieves target specifications from the TINYGOROOT targets
234// directory. Only valid target JSON files are considered, and the function

Callers 10

runPlatTestsFunction · 0.92
emuCheckFunction · 0.92
testCompilePackageFunction · 0.92
testClangAttributesFunction · 0.92
buildBinaryFunction · 0.92
NewConfigFunction · 0.92
compileGoFileForTestingFunction · 0.92
GetTargetSpecsFunction · 0.85
TestLoadTargetFunction · 0.85

Calls 4

loadFromGivenStrMethod · 0.95
resolveInheritsMethod · 0.95
defaultTargetFunction · 0.85
ErrorfMethod · 0.65

Tested by 8

runPlatTestsFunction · 0.74
emuCheckFunction · 0.74
testCompilePackageFunction · 0.74
testClangAttributesFunction · 0.74
buildBinaryFunction · 0.74
compileGoFileForTestingFunction · 0.74
TestLoadTargetFunction · 0.68