1# This file defines a template for using .export files. 2# 3# Parameters: 4# exports_file (required) 5# Path of the .exports file to use. 6# 7# Example use: 8# symbol_exports("my_exports") { 9# exports_file = "//foo/bar/my.exports" 10# } 11# ... 12# shared_library("my_target") { 13# deps = [ ":my_exports" ] # Adds correct ldflags. 14# ... 15# } 16 17# Corresponds to add_llvm_symbol_exports() in the CMake build. 18template("symbol_exports") { 19 # Create a platform-appropriate name for the temporary file. 20 linker_file = get_path_info(invoker.exports_file, "name") 21 if (current_os == "mac") { 22 linker_file = linker_file + "_symbols.txt" 23 } else if (current_os == "win") { 24 linker_file = linker_file + ".def" 25 } else { 26 linker_file = linker_file + ".script" 27 } 28 linker_file = "$target_gen_dir/$linker_file" 29 rebased_linker_file = rebase_path(linker_file, root_build_dir) 30 31 config_name = "${target_name}_config" 32 config(config_name) { 33 # FIXME: With this setup, targets are not relinked automatically 34 # when the input exports file is touched but nothing else changes. 35 # https://groups.google.com/a/chromium.org/g/gn-dev/c/sN09GYS1ufE 36 visibility = [ ":$target_name" ] 37 if (current_os == "mac") { 38 ldflags = [ "-Wl,-exported_symbols_list,$rebased_linker_file" ] 39 } else if (current_os == "win") { 40 ldflags = [ "/DEF:$rebased_linker_file" ] 41 } else { 42 ldflags = [ "-Wl,--version-script,$rebased_linker_file" ] 43 } 44 } 45 46 action(target_name) { 47 forward_variables_from(invoker, [ "deps" ]) 48 script = "//llvm/utils/gn/build/symbol_exports.py" 49 inputs = [ invoker.exports_file ] 50 outputs = [ linker_file ] 51 args = [ 52 "--format=" + current_os, 53 rebase_path(inputs[0], root_build_dir), 54 rebased_linker_file, 55 ] 56 57 # Let targets depending on this receive the right ldflags. 58 public_configs = [ ":$config_name" ] 59 } 60} 61