vcpkg/ports/tensorflow-common/generate_static_link_cmd_macos.py
Joachim Gehweiler 8ad33ead90
[tensorflow] update to 2.6 (#20015)
* Revert "incorporate changes from microsoft:master"

* Revert "Revert "incorporate changes from microsoft:master""

* WIP: update to tensorflow 2.6

* update patch

* update more patches

* fix patch again

* fix new Windows compile/linkage errors

* fix patch

* fix patch again

* temporarily revert Windows build option fix to test whether upstream fix doesn't work

* check if constexpr is sufficient (is_same_v requires C++17)

* try patch for build parameters

* remove fastbuild patch and improve constexpr patch (no C++17 requirement)
(fastbuild patch didn't work because bazel overrides it with /DEBUG:FULL)

* x-add-version

* add C++17 preprocessor switch for "if constexpr"

* x-add-version

* remove pre-processor switch (doesn't work without)

* x-add-version

* work-around toolchain issues on macOS

* x-add-version

* fix Windows build options (must be string, not list)

* x-add-version

* temporarily add code to debug CI

* temporarily add more debug output as build doesn't even start on macOS CI

* remove debug code, add switch for linker parameters on macOS and re-introduce old behaviour (some platforms still use old behaviour)

* x-add-version

* fix broken string termination

* x-add-version

* fix function name

* x-add-version

Co-authored-by: jgehw <Joachim_Gehweiler@McAfee.com>
Co-authored-by: Billy Robert O'Neal III <bion@microsoft.com>
2021-09-29 20:43:32 -07:00

71 lines
3.7 KiB
Python

import os.path
import re
import sys
version = sys.argv[2]
lib_suffix = "" if len(sys.argv) < 4 else sys.argv[3]
with open(sys.argv[1], "r") as f_in:
with open("static_link.sh", "w") as f_out:
if os.path.isfile(f"libtensorflow_framework.{version}.dylib-2.params"):
p_cd = re.compile(r"^\((cd .*) && \\$")
p_linker = re.compile(fr"^\s*.+cc_wrapper.sh.+(@bazel-out\S+libtensorflow{lib_suffix}\.\d\.\d\.\d\.dylib-2\.params).*")
f_out.write("#!/bin/bash\n# note: ar/binutils version 2.27 required to support output files > 4GB\n")
env = []
for line in f_in:
if line.startswith("(cd"):
# new command, reset
env = [line]
else:
m1 = p_linker.match(line)
if m1:
m2 = p_cd.match(env[0])
f_out.write(m2.group(1) + "\n")
line = f'"/usr/bin/libtool" -static -o {m1.group(1)[1:-9].replace(".dylib", ".a")} {m1.group(1).replace(".dylib", ".a")}\n'
f_out.write(line)
else:
env.append(line)
else:
# old behaviour (still on some platforms): inline all parameters instead of using -2.params file
p_cd = re.compile(r"^\((cd .*) && \\$")
p_linker1 = re.compile(fr"^.*cc_wrapper.sh.+-shared.+-o (bazel-out\S+libtensorflow{lib_suffix}\.\d\.\d\.\d\.dylib)")
p_linker2 = re.compile("^.*cc_wrapper.sh.+-shared.+-o (bazel-out\\S+libtensorflow_framework\\.\\d\\.\\d\\.\\d\\.dylib)")
f_out.write("#!/bin/bash\n# note: ar/binutils version 2.27 required to support output files > 4GB\n")
env = []
parts = None
for line in f_in:
if line.startswith("(cd"):
# new command, reset
env = [line]
else:
m1 = p_linker1.match(line)
m2 = p_linker2.match(line)
if m1:
tokens = line.split()
if parts is None:
parts = [t[16:] for t in tokens if t.startswith("-Wl,-force_load,")]
else:
m = p_cd.match(env[0])
f_out.write(m.group(1) + "\n")
tmp = [t[16:] for t in tokens if t.startswith("-Wl,-force_load,")]
old = set(parts)
parts += [t for t in tmp if t not in old]
line = f"libtool -static -o {m1.group(1).replace('.dylib', '.a')} {' '.join(parts)}\n"
f_out.write(line)
break
elif m2 and len(env) > 6:
tokens = line.split()
if parts is None:
parts = [t[16:] for t in tokens if t.startswith("-Wl,-force_load,")]
else:
m = p_cd.match(env[0])
f_out.write(m.group(1) + "\n")
tmp = [t[16:] for t in tokens if t.startswith("-Wl,-force_load,")]
old = set(parts)
parts += [t for t in tmp if t not in old]
line = f"libtool -static -o {m2.group(1).replace('_framework', lib_suffix).replace('.dylib', '.a')} {' '.join(parts)}\n"
f_out.write(line)
break
else:
env.append(line)