code: def compile_metal(
      code, path_target=None, sdk="macosx", min_os_version=None
  ):
      """Compile metal with CLI tool from env.
  
      Parameters
      ----------
      code : str
          The cuda code.
  
      path_target : str, optional
          Output file.
  
      sdk : str, optional
          The target platform SDK.
  
      Return
      ------
      metallib : bytearray
          The bytearray of the metallib
      """
      temp = utils.tempdir()
      temp_code = temp.relpath("my_lib.metal")
      temp_ir = temp.relpath("my_lib.air")
      temp_target = temp.relpath("my_lib.metallib")
  
      with open(temp_code, "w") as out_file:
          out_file.write(code)
      file_target = path_target if path_target else temp_target
  
      # See:
      # - https://developer.apple.com/documentation/metal/gpu_functions_libraries/building_a_library_with_metal_s_command-line_tools#overview # pylint: disable=line-too-long
      #
      #   xcrun -sdk macosx metal -c MyLibrary.metal -o MyLibrary.air
      #   xcrun -sdk macosx metallib MyLibrary.air -o MyLibrary.metallib
      min_target = __get_min_os_version_cmd(sdk, min_os_version)
      if sdk == "macosx":
          language_version = "-std=macos-metal2.3"
      elif sdk in ("iphoneos", "iphonesimulator"):
          language_version = "-std=ios-metal2.3"
      else:
          raise RuntimeError(f"Unsupported sdk: {sdk}")
      cmd1 = [
          "xcrun",
          "-sdk",
          sdk,
          "metal",
          language_version,
          min_target,
          "-O3",
      ]
      cmd1 += ["-c", temp_code, "-o", temp_ir]
      cmd2 = ["xcrun", "-sdk", sdk, "metallib"]
      cmd2 += [temp_ir, "-o", file_target]
      proc = subprocess.Popen(
          " ".join(cmd1) + ";" + " ".join(cmd2),
          shell=True,
          stdout=subprocess.PIPE,
          stderr=subprocess.STDOUT,
      )
      (out, _) = proc.communicate()
      if proc.returncode != 0:
          sys.stderr.write("Compilation error:\n")
          sys.stderr.write(py_str(out))
          sys.stderr.flush()
          libbin = None
      else:
          libbin = bytearray(open(file_target, "rb").read())
      return libbin
  
file_path: tvm/python/tvm/contrib/xcode.py
imports: from __future__ import absolute_import
  import os
  import sys
  import subprocess
  import json
  from .._ffi.base import py_str
  from .None import utils
label_desc: Use image node_id 5 for calling a global function with example usage: compile_metal(code, path_target, sdk, min_os_version) and returns: libbin