bazel: can't use gcc-ar as Bazel's ar

gcc provides a wrapper, gcc-ar, over binutils ar that passes the proper --plugin option so that ar can understand LTO objects. gcc-ar does some dodgy munging of the command line, which causes it to fail if all arguments are passed via param file, which is precisely how Bazel likes to pass ar arguments. Would it be possible to work around this in Bazel by putting the ar mode argument on the command line rather than the param file?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

Wrapper script that I’m using:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import subprocess
import sys


def read_params_file(filename):
    params = []
    with open(filename) as f:
        for line in f.readlines():
            line = line.strip()
            if line:
                params.append(line)
    return params


def parse_args(argv):
    new_argv = []
    for arg in argv:
        if arg.startswith("@"):
            new_argv += read_params_file(arg[1:])
        else:
            new_argv.append(arg)
    return new_argv


def main(argv):
    new_args = parse_args(argv)
    subprocess.run(
        ["/usr/bin/gcc-ar-original"] + new_args,
    )


if __name__ == "__main__":
    main(sys.argv[1:])