golang.org/x/build@v0.0.0-20240506185731-218518f32b70/env/corellium/ios/files/arwrap.go (about)

     1  // Copyright 2019 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  //go:build ignore
     6  
     7  // The arhost binary is a wrapper for llvm-ar, designed to be called by
     8  // cmd/link. The -extar flag is not enough because llvm-ar and ar don't
     9  // use the same flags.
    10  //
    11  // It is useful when the standard ar is broken, such as on self-hosted
    12  // iOS.
    13  package main
    14  
    15  import (
    16  	"os"
    17  	"os/exec"
    18  )
    19  
    20  func main() {
    21  	args := os.Args[1:]
    22  	// cmd/link invokes ar with -q -c -s. Replace with
    23  	// just q.
    24  	for i := len(args) - 1; i >= 0; i-- {
    25  		switch args[i] {
    26  		case "-q":
    27  			args[i] = "q"
    28  		case "-c", "-s":
    29  			args = append(args[:i], args[i+1:]...)
    30  		}
    31  	}
    32  	cmd := exec.Command("llvm-ar", args...)
    33  	cmd.Stdout = os.Stdout
    34  	cmd.Stderr = os.Stderr
    35  	if err := cmd.Run(); err != nil {
    36  		if err, ok := err.(*exec.ExitError); ok {
    37  			os.Exit(err.ExitCode())
    38  		}
    39  		os.Exit(1)
    40  	}
    41  	os.Exit(0)
    42  }