def build_clang_plugin(args: str) -> None: """ run cmake as needed to generate ninja buildfiles. then run ninja. """ cargo = get_cmd_or_die("cargo") config_capi_src_dir = os.path.join(c.CROSS_CHECKS_DIR, "rust-checks", "config-capi") cargo_target_dir = os.path.join(c.CLANG_XCHECK_PLUGIN_BLD, "config-capi-target") config_lib_path = os.path.join(cargo_target_dir, "debug" if args.debug else "release", "libc2rust_xcheck_config_capi.a") with pb.local.cwd(config_capi_src_dir): cargo_args = ["build", "--package", "c2rust-xcheck-config-capi"] if not args.debug: cargo_args.append("--release") with pb.local.env(CARGO_TARGET_DIR=cargo_target_dir): invoke(cargo[cargo_args]) ninja = get_cmd_or_die("ninja") # Possible values are Release, Debug, RelWithDebInfo and MinSizeRel build_type = "Debug" if args.debug else "RelWithDebInfo" ninja_build_file = os.path.join(c.CLANG_XCHECK_PLUGIN_BLD, "build.ninja") with pb.local.cwd(c.CLANG_XCHECK_PLUGIN_BLD): if os.path.isfile(ninja_build_file): prev_build_type = get_ninja_build_type(ninja_build_file) run_cmake = prev_build_type != build_type else: run_cmake = True if run_cmake: cmake = get_cmd_or_die("cmake") max_link_jobs = est_parallel_link_jobs() cargs = [ "-G", "Ninja", c.CLANG_XCHECK_PLUGIN_SRC, "-DXCHECK_CONFIG_LIB={}".format(config_lib_path), "-DCMAKE_BUILD_TYPE=" + build_type, "-DBUILD_SHARED_LIBS=1", "-DLLVM_PARALLEL_LINK_JOBS={}".format(max_link_jobs) ] if args.with_c2rust_clang: cargs.extend([ "-DLLVM_DIR={}/lib/cmake/llvm".format(c.LLVM_BLD), "-DClang_DIR={}/lib/cmake/clang".format(c.LLVM_BLD), "-DLLVM_EXTERNAL_LIT={}/bin/llvm-lit".format(c.LLVM_BLD) ]) else: # Some distros, e.g., Arch, Ubuntu, ship llvm-lit as /usr/bin/lit cargs.append("-DLLVM_EXTERNAL_LIT={}".format(pb.local['lit'])) invoke(cmake[cargs]) else: logging.debug("found existing ninja.build, not running cmake") invoke(ninja)
def configure_and_build_llvm(args: str) -> None: """ run cmake as needed to generate ninja buildfiles. then run ninja. """ ninja = get_cmd_or_die("ninja") # Possible values are Release, Debug, RelWithDebInfo and MinSizeRel build_type = "Debug" if args.debug else "RelWithDebInfo" ninja_build_file = os.path.join(c.LLVM_BLD, "build.ninja") with pb.local.cwd(c.LLVM_BLD): if os.path.isfile(ninja_build_file): prev_build_type = get_ninja_build_type(ninja_build_file) run_cmake = prev_build_type != build_type else: run_cmake = True if run_cmake: cmake = get_cmd_or_die("cmake") max_link_jobs = est_parallel_link_jobs() assertions = "1" if args.assertions else "0" cargs = ["-G", "Ninja", c.LLVM_SRC, "-Wno-dev", "-DCMAKE_C_COMPILER=clang", "-DCMAKE_CXX_COMPILER=clang++", "-DCMAKE_BUILD_TYPE=" + build_type, "-DLLVM_ENABLE_ASSERTIONS=" + assertions, "-DCMAKE_EXPORT_COMPILE_COMMANDS=1", "-DLLVM_TARGETS_TO_BUILD=X86", "-DLLVM_INCLUDE_UTILS=1", "-DLLVM_BUILD_UTILS=1", "-DBUILD_SHARED_LIBS=1", "-DLLVM_PARALLEL_LINK_JOBS={}".format(max_link_jobs), "-DTINYCBOR_PREFIX={}".format(c.CBOR_PREFIX)] invoke(cmake[cargs]) else: logging.debug("found existing ninja.build, not running cmake") ninja_args = ['ast-exporter'] ninja_args += ['FileCheck', 'count', 'not'] if args.with_clang: ninja_args.append('clang') invoke(ninja, *ninja_args)
def configure_and_build_llvm(args) -> None: """ run cmake as needed to generate ninja buildfiles. then run ninja. """ # Possible values are Release, Debug, RelWithDebInfo and MinSizeRel build_type = "Debug" if args.debug else "RelWithDebInfo" ninja_build_file = os.path.join(c.LLVM_BLD, "build.ninja") with pb.local.cwd(c.LLVM_BLD): if os.path.isfile(ninja_build_file) and not args.xcode: prev_build_type = get_ninja_build_type(ninja_build_file) run_cmake = prev_build_type != build_type else: run_cmake = True if run_cmake: cmake = get_cmd_or_die("cmake") max_link_jobs = est_parallel_link_jobs() assertions = "1" if args.assertions else "0" cargs = ["-G", "Ninja", c.LLVM_SRC, "-Wno-dev", "-DCMAKE_INSTALL_PREFIX=" + c.LLVM_INSTALL, "-DCMAKE_BUILD_TYPE=" + build_type, "-DLLVM_PARALLEL_LINK_JOBS={}".format(max_link_jobs), "-DLLVM_ENABLE_ASSERTIONS=" + assertions, "-DCMAKE_EXPORT_COMPILE_COMMANDS=1", "-DLLVM_TARGETS_TO_BUILD=host"] invoke(cmake[cargs]) # NOTE: we only generate Xcode project files for IDE support # and don't build with them since the cargo build.rs files # rely on cmake to build native code. if args.xcode: cargs[1] = "Xcode" # output Xcode project files in a separate dir ensure_dir(c.AST_EXPO_PRJ_DIR) with pb.local.cwd(c.AST_EXPO_PRJ_DIR): invoke(cmake[cargs]) else: logging.debug("found existing ninja.build, not running cmake") # if args.xcode: # xcodebuild = get_cmd_or_die("xcodebuild") # xc_conf_args = ['-configuration', build_type] # xc_args = xc_conf_args + ['-target', 'llvm-config'] # invoke(xcodebuild, *xc_args) # xc_args = xc_conf_args + ['-target', 'c2rust-ast-exporter'] # invoke(xcodebuild, *xc_args) # We must install headers here so our clang tool can reference # compiler-internal headers such as stddef.h. This reference is # relative to LLVM_INSTALL/bin, which MUST exist for the relative # reference to be valid. To force this, we also install llvm-config, # since we are building and using it for other purposes. nice = get_cmd_or_die("nice") ninja = get_cmd_or_die("ninja") nice_args = [ '-n', '19', str(ninja), 'clangAST', 'clangFrontend', 'clangTooling', 'clangBasic', 'clangASTMatchers', 'clangParse', 'clangSerialization', 'clangSema', 'clangEdit', 'clangAnalysis', 'clangDriver', 'clangFormat', 'clangToolingCore', 'clangRewrite', 'clangLex', 'LLVMMC', 'LLVMMCParser', 'LLVMDemangle', 'LLVMSupport', 'LLVMOption', 'LLVMBinaryFormat', 'LLVMCore', 'LLVMBitReader', 'LLVMProfileData', 'llvm-config', 'install-clang-headers', 'install-compiler-rt-headers', 'FileCheck', 'count', 'not'] (major, _minor, _point) = c.LLVM_VER.split(".") major = int(major) if major >= 7 and major < 10: nice_args += [ 'LLVMDebugInfoMSF', 'LLVMDebugInfoCodeView'] if major > 8: nice_args.append("install-clang-resource-headers") if major == 9: nice_args += [ 'LLVMBitstreamReader', 'LLVMRemarks'] if major >= 10: nice_args.append("LLVMFrontendOpenMP") if args.with_clang: nice_args.append('clang') invoke(nice, *nice_args) # Make sure install/bin exists so that we can create a relative path # using it in AstExporter.cpp os.makedirs(os.path.join(c.LLVM_INSTALL, 'bin'), exist_ok=True)
def configure_and_build_llvm(args) -> None: """ run cmake as needed to generate ninja buildfiles. then run ninja. """ # Possible values are Release, Debug, RelWithDebInfo and MinSizeRel build_type = "Debug" if args.debug else "RelWithDebInfo" ninja_build_file = os.path.join(c.LLVM_BLD, "build.ninja") with pb.local.cwd(c.LLVM_BLD): if os.path.isfile(ninja_build_file) and not args.xcode: prev_build_type = get_ninja_build_type(ninja_build_file) run_cmake = prev_build_type != build_type else: run_cmake = True if run_cmake: cmake = get_cmd_or_die("cmake") clang = get_cmd_or_die("clang") clangpp = get_cmd_or_die("clang++") max_link_jobs = est_parallel_link_jobs() assertions = "1" if args.assertions else "0" ast_ext_dir = "-DLLVM_EXTERNAL_C2RUST_AST_EXPORTER_SOURCE_DIR={}" ast_ext_dir = ast_ext_dir.format(c.AST_EXPO_SRC_DIR) cargs = ["-G", "Ninja", c.LLVM_SRC, "-Wno-dev", "-DCMAKE_C_COMPILER={}".format(clang), "-DCMAKE_CXX_COMPILER={}".format(clangpp), "-DCMAKE_INSTALL_PREFIX=" + c.LLVM_INSTALL, "-DCMAKE_BUILD_TYPE=" + build_type, "-DLLVM_PARALLEL_LINK_JOBS={}".format(max_link_jobs), "-DLLVM_ENABLE_ASSERTIONS=" + assertions, "-DCMAKE_EXPORT_COMPILE_COMMANDS=1", # required to build LLVM 8 on Debian Jessie "-DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=1", ast_ext_dir] if on_x86(): # speed up builds on x86 hosts cargs.append("-DLLVM_TARGETS_TO_BUILD=X86") invoke(cmake[cargs]) # NOTE: we only generate Xcode project files for IDE support # and don't build with them since the cargo build.rs files # rely on cmake to build native code. if args.xcode: cargs[1] = "Xcode" # output Xcode project files in a separate dir ensure_dir(c.AST_EXPO_PRJ_DIR) with pb.local.cwd(c.AST_EXPO_PRJ_DIR): invoke(cmake[cargs]) else: logging.debug("found existing ninja.build, not running cmake") # if args.xcode: # xcodebuild = get_cmd_or_die("xcodebuild") # xc_conf_args = ['-configuration', build_type] # xc_args = xc_conf_args + ['-target', 'llvm-config'] # invoke(xcodebuild, *xc_args) # xc_args = xc_conf_args + ['-target', 'c2rust-ast-exporter'] # invoke(xcodebuild, *xc_args) # We must install headers here so our clang tool can reference # compiler-internal headers such as stddef.h. This reference is # relative to LLVM_INSTALL/bin, which MUST exist for the relative # reference to be valid. To force this, we also install llvm-config, # since we are building and using it for other purposes. ninja = get_cmd_or_die("ninja") ninja_args = ['c2rust-ast-exporter', 'clangAstExporter', 'llvm-config', 'install-clang-headers', 'FileCheck', 'count', 'not'] if args.with_clang: ninja_args.append('clang') invoke(ninja, *ninja_args) # Make sure install/bin exists so that we can create a relative path # using it in AstExporter.cpp os.makedirs(os.path.join(c.LLVM_INSTALL, 'bin'), exist_ok=True)