source another .gn files

39 views
Skip to first unread message

Clark Kent

unread,
Sep 11, 2022, 8:19:33 AM9/11/22
to gn-dev
how do i go about sourcing a .gn file from another BUILD.gn

for example, source skia's .gn file and inherit everything that it exposes so we can then depend on `:skia` as `libs [ ":skia" ]`



for example, so one does not need to do this



# manually copy parts on skia gn we require to build C bindings
# we have copied skia's gn directory to this $pwd

import("gn/shared_sources.gni")
import("gn/skia.gni")

if (defined(skia_settings)) {
  import(skia_settings)
}

# Skia public API, generally provided by :skia.
config("skia_public") {
  include_dirs = [ ".", "../externals/skia" ]

  defines = []
  cflags_objcc = []
  if (is_component_build) {
    defines += [ "SKIA_DLL" ]
  }
  if (is_fuchsia || is_linux) {
    defines += [ "SK_R32_SHIFT=16" ]
  }
  if (skia_enable_flutter_defines) {
    defines += flutter_defines
  }
  if (!skia_enable_gpu) {
    defines += [ "SK_SUPPORT_GPU=0" ]
  }
  if (skia_enable_sksl) {
    defines += [ "SK_ENABLE_SKSL" ]
  }
  if (skia_enable_precompile) {
    defines += [ "SK_ENABLE_PRECOMPILE" ]
  }
  if (is_fuchsia) {
    defines += fuchsia_defines
  }
  if (is_wasm) {
    defines += wasm_defines
  }
  if (skia_gl_standard == "gles") {
    defines += [ "SK_ASSUME_GL_ES=1" ]
  } else if (skia_gl_standard == "gl") {
    defines += [ "SK_ASSUME_GL=1" ]
  } else if (skia_gl_standard == "webgl") {
    defines += [
      "SK_ASSUME_WEBGL=1",
      "SK_USE_WEBGL",
    ]
  }
  if (!skia_enable_skgpu_v1) {
    defines += [ "SK_GPU_V1=0" ]
  }
  if (skia_use_perfetto) {
    defines += [ "SK_USE_PERFETTO" ]
  }

  # Temporary define for flutter to control in their GN build
  if (skia_use_legacy_layer_bounds) {
    defines += [ "SK_LEGACY_LAYER_BOUNDS_EXPANSION" ]
  }

  # Some older versions of the Clang toolchain change the visibility of
  # symbols decorated with API_AVAILABLE macro to be visible. Users of such
  # toolchains suppress the use of this macro till toolchain updates are made.
  if (is_mac || is_ios) {
    if (skia_enable_api_available_macro) {
      defines += [ "SK_ENABLE_API_AVAILABLE" ]
    } else {
      cflags_objcc += [ "-Wno-unguarded-availability" ]
    }
  }
}

# Skia internal APIs, used by Skia itself and a few test tools.
config("skia_private") {
  visibility = [ "./*", "../externals/skia/*" ]

  defines = [ "SK_GAMMA_APPLY_TO_A8" ]
  if (skia_use_fixed_gamma_text) {
    defines += [
      "SK_GAMMA_EXPONENT=1.4",
      "SK_GAMMA_CONTRAST=0.0",
    ]
  }
  if (is_skia_dev_build && !is_wasm) {
    defines += [
      "SK_ALLOW_STATIC_GLOBAL_INITIALIZERS=1",
      "GR_TEST_UTILS=1",
    ]
    if (skia_enable_graphite) {
      defines += [ "GRAPHITE_TEST_UTILS=1" ]
    }
  }
  if (skia_compare_vm_vs_rp) {
    defines += [ "SKIA_COMPARE_VM_VS_RP" ]
  }
  libs = []
  lib_dirs = []
  if (skia_use_gl && skia_use_angle) {
    defines += [ "SK_ANGLE" ]
  }
  if (skia_use_vma) {
    defines += [ "SK_USE_VMA" ]
  }
  if (skia_enable_winuwp) {
    defines += [ "SK_WINUWP" ]
  }
}

# Any code that's linked into Skia-the-library should use this config via += skia_library_configs.
config("skia_library") {
  visibility = [ "./*", "../externals/skia/*" ]
  defines = [ "SKIA_IMPLEMENTATION=1" ]
}

skia_library_configs = [
  ":skia_public",
  ":skia_private",
  ":skia_library",
]

# ALL OF THE ABOVE IS FROM SKIA BUILD.gn FILE

# SkiaSharp + HarfBuzzSharp

# SkiaSharp differs depending on the platform
template("skiasharp_build") {
  _skiasharp_mode = "shared_library"

  target(_skiasharp_mode, target_name) {
    forward_variables_from(invoker, "*")
  }
}

set_defaults("skiasharp_build") {
  configs = default_configs
}

declare_args() {
    # Skia output directory
    #   this is where we can find skia.lib and friends
    SKIA_C_PATH = ""
}

skiasharp_build("SkiaSharp") {

  # NOT GOOD ENOUGH
  # DIFFERENT PLATFORMS MAY REQUIRE DIFFERENT DEPS
  # AND DEPS MAY CHANGE BETWEEN SKIA VERSIONS/COMMITS
  #
  # additionally different OS's have different link extensions (.lib, .so, .dylib)

  libs = [
    "$SKIA_C_PATH/skia.lib",
    "$SKIA_C_PATH/skottie.lib"
  ]



and instead can just do this



# SkiaSharp + HarfBuzzSharp

# SkiaSharp differs depending on the platform
template("skiasharp_build") {
  _skiasharp_mode = "shared_library"

  target(_skiasharp_mode, target_name) {
    forward_variables_from(invoker, "*")
  }
}

set_defaults("skiasharp_build") {
  configs = default_configs
}

# SkiaSharp + HarfBuzzSharp

skiasharp_build("SkiaSharp") {
  public_configs = [ ":skia_public" ]
  configs += skia_library_configs

  defines = [ "SKIA_C_DLL" ]

  deps = [
    ":skia",
    ":modules/skottie"
  ]

  libs = []

Clark Kent

unread,
Sep 11, 2022, 9:03:22 AM9/11/22
to gn-dev, Clark Kent
for example the following is subject to change depending on platform, CPU capabilities, supported deps, build config, ect

  libs = [
    "$SKIA_C_PATH/dng_sdk.lib",
    "$SKIA_C_PATH/expat.lib",
    "$SKIA_C_PATH/libjpeg.lib",
    "$SKIA_C_PATH/libpng.lib",
    "$SKIA_C_PATH/libwebp.lib",
    "$SKIA_C_PATH/libwebp_sse41.lib",
    "$SKIA_C_PATH/piex.lib",
    "$SKIA_C_PATH/skcms.lib",
    "$SKIA_C_PATH/skia.lib",
    "$SKIA_C_PATH/skottie.lib",
    "$SKIA_C_PATH/skresources.lib",
    "$SKIA_C_PATH/sksg.lib",
    "$SKIA_C_PATH/skshaper.lib",
    "$SKIA_C_PATH/zlib.lib",
  ]

Brett Wilson

unread,
Sep 11, 2022, 12:12:39 PM9/11/22
to Clark Kent, gn-dev
Sorry, the only thing you can do from within GN is import *.gni files.

If you're willing to do some work you can ask "gn format" to output the AST and then get stuff out of there yourself, or from a real Skia checkout use "gn desc" or the JSON output switches to "gn gen" to see what Skia is using for the current platform. 

Brett

Clark Kent

unread,
Sep 11, 2022, 12:35:37 PM9/11/22
to gn-dev, Brett Wilson, gn-dev, Clark Kent
could it be possible to generate CMake build file and build skia from such cmake file?

as we could then submodule it to gain (hopefully) access to its configs and targets and then link against such with such configs
Reply all
Reply to author
Forward
0 new messages