Load a target specification.
(options *Options)
| 190 | |
| 191 | // Load a target specification. |
| 192 | func 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 |