1 # This file defines a template for using .export files.
4 # exports_file (required)
5 # Path of the .exports file to use.
8 # symbol_exports("my_exports") {
9 # exports_file = "//foo/bar/my.exports"
12 # shared_library("my_target") {
13 # deps = [ ":my_exports" ] # Adds correct ldflags.
17 # Corresponds to add_llvm_symbol_exports() in the CMake build.
18 template("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"
26 linker_file = linker_file + ".script"
28 linker_file = "$target_gen_dir/$linker_file"
29 rebased_linker_file = rebase_path(linker_file, root_build_dir)
31 config_name = "${target_name}_config"
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" ]
42 ldflags = [ "-Wl,--version-script,$rebased_linker_file" ]
47 forward_variables_from(invoker, [ "deps" ])
48 script = "//llvm/utils/gn/build/symbol_exports.py"
49 inputs = [ invoker.exports_file ]
50 outputs = [ linker_file ]
52 "--format=" + current_os,
53 rebase_path(inputs[0], root_build_dir),
57 # Let targets depending on this receive the right ldflags.
58 public_configs = [ ":$config_name" ]