GN: get Angle compiling on Windows.
authorMike Klein <mtklein@chromium.org>
Mon, 17 Oct 2016 15:51:11 +0000 (11:51 -0400)
committerMike Klein <mtklein@chromium.org>
Mon, 17 Oct 2016 16:16:16 +0000 (16:16 +0000)
Angle does not yet link, but it does compile.

I chickened out and wrote cp.py to be the copy tool on Windows.  I've got all platforms using it for consistency.

CQ_INCLUDE_TRYBOTS=master.client.skia.compile:Build-Ubuntu-GCC-x86_64-Release-ANGLE-Trybot

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3533

Change-Id: I15f4b63a47121528b2fd2672c26c62765966147c
Reviewed-on: https://skia-review.googlesource.com/3533
Reviewed-by: Mike Klein <mtklein@chromium.org>
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>

gn/BUILD.gn
gn/cp.py [new file with mode: 0644]
third_party/angle2/BUILD.gn

index df45ada..c972735 100644 (file)
@@ -399,6 +399,36 @@ toolchain("msvc") {
     description = "link {{output}}"
   }
 
+  tool("solink") {
+    dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}"
+    libname = "${dllname}.lib"
+    pdbname = "${dllname}.pdb"
+    rspfile = "${dllname}.rsp"
+
+    command = "$env_setup$bin/link.exe /nologo /IMPLIB:$libname /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
+    outputs = [
+      dllname,
+      libname,
+      pdbname,
+    ]
+    default_output_extension = ".dll"
+    default_output_dir = "{{root_out_dir}}"
+
+    link_output = libname
+    depend_output = libname
+    runtime_outputs = [
+      dllname,
+      pdbname,
+    ]
+
+    # I don't quite understand this.  Aping Chrome's toolchain/win/BUILD.gn.
+    restat = true
+
+    # inputs_newline works around a fixed per-line buffer size in the linker.
+    rspfile_content = "{{inputs_newline}} {{libs}} {{solibs}} {{ldflags}}"
+    description = "link {{output}}"
+  }
+
   tool("link") {
     exename = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
     pdbname = "$exename.pdb"
@@ -422,6 +452,12 @@ toolchain("msvc") {
     command = "cmd.exe /c echo > {{output}}"
     description = "stamp {{output}}"
   }
+
+  tool("copy") {
+    cp_py = rebase_path("cp.py")
+    command = "python.exe $cp_py {{source}} {{output}}"
+    description = "copy {{source}} {{output}}"
+  }
 }
 
 toolchain("gcc_like") {
@@ -499,7 +535,8 @@ toolchain("gcc_like") {
   }
 
   tool("copy") {
-    command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
+    cp_py = rebase_path("cp.py")
+    command = "python $cp_py {{source}} {{output}}"
     description = "copy {{source}} {{output}}"
   }
 }
diff --git a/gn/cp.py b/gn/cp.py
new file mode 100644 (file)
index 0000000..eedfcb2
--- /dev/null
+++ b/gn/cp.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+import shutil
+import sys
+
+src, dst = sys.argv[1:]
+
+if os.path.exists(dst):
+  if os.path.isdir(dst):
+    shutil.rmtree(dst)
+  else:
+    os.remove(dst)
+
+if os.path.isdir(src):
+  shutil.copytree(src, dst)
+else:
+  shutil.copy2(src, dst)
index 3ae0f8e..b3958ca 100644 (file)
@@ -33,24 +33,32 @@ config("common") {
   defines = [
     "ANGLE_ENABLE_ESSL",
     "ANGLE_ENABLE_GLSL",
-    "GL_GLEXT_PROTOTYPES",
+    "ANGLE_ENABLE_OPENGL",
     "EGL_EGLEXT_PROTOTYPES",
+    "GL_GLEXT_PROTOTYPES",
   ]
   include_dirs = [
     "$root_gen_dir/angle2",
     "$angle_root/include",
     "$angle_root/src",
     "$angle_root/src/common/third_party/numerics",
+    "$angle_root/src/third_party/khronos",
   ]
 
-  assert(is_linux)  # TODO: is_win, of course, maybe is_mac?
+  assert(is_linux || is_win)  # TODO: is_mac?
   if (is_linux) {
     defines += [
-      "ANGLE_ENABLE_OPENGL",
       "ANGLE_USE_X11",
       "GL_APICALL=__attribute__((visibility(\"default\")))",
       "EGLAPI=__attribute__((visibility(\"default\")))",
     ]
+  } else if (is_win) {
+    defines += [
+      "ANGLE_ENABLE_D3D11",
+      "ANGLE_ENABLE_D3D9",
+      "GL_APICALL=",
+      "EGLAPI=",
+    ]
   }
 }
 
@@ -65,25 +73,27 @@ copy("commit_id") {
 
 shared_library("libGLESv2") {
   configs += [ ":common" ]
+  configs -= [ "//gn:warnings" ]
   defines = [ "LIBGLESV2_IMPLEMENTATION" ]
   deps = [
     ":commit_id",
   ]
   libs = []
-  sources = rebase_path(compiler_gypi.angle_preprocessor_sources +
-                            compiler_gypi.angle_translator_lib_sources +
-                            compiler_gypi.angle_translator_lib_essl_sources +
-                            compiler_gypi.angle_translator_lib_glsl_sources +
-                            gles_gypi.libangle_sources +
-                            gles_gypi.libangle_common_sources +
-                            gles_gypi.libangle_image_util_sources +
-                            gles_gypi.libglesv2_sources,
-                        ".",
-                        "$angle_root/src") +
-            [
-              "$angle_root/src/compiler/translator/ShaderLang.cpp",
-              "$angle_root/src/compiler/translator/ShaderVars.cpp",
-            ]
+  sources =
+      rebase_path(
+          compiler_gypi.angle_preprocessor_sources +
+              compiler_gypi.angle_translator_lib_sources +
+              compiler_gypi.angle_translator_lib_essl_sources +
+              compiler_gypi.angle_translator_lib_glsl_sources +
+              gles_gypi.libangle_sources + gles_gypi.libangle_common_sources +
+              gles_gypi.libangle_image_util_sources +
+              gles_gypi.libglesv2_sources + gles_gypi.libangle_gl_sources,
+          ".",
+          "$angle_root/src") +
+      [
+        "$angle_root/src/compiler/translator/ShaderLang.cpp",
+        "$angle_root/src/compiler/translator/ShaderVars.cpp",
+      ]
   if (!is_win) {
     sources -= [ "$angle_root/src/libGLESv2/libGLESv2.def" ]
   }
@@ -94,16 +104,33 @@ shared_library("libGLESv2") {
       "Xi",
       "Xext",
     ]
-    sources += rebase_path(gles_gypi.libangle_gl_sources +
-                               gles_gypi.libangle_gl_glx_sources,
+    sources +=
+        rebase_path(gles_gypi.libangle_gl_glx_sources, ".", "$angle_root/src") +
+        [ "$angle_root/src/third_party/libXNVCtrl/NVCtrl.c" ]
+  } else if (is_win) {
+    defines += [
+      # TODO: ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES
+    ]
+    sources += rebase_path(gles_gypi.libangle_gl_wgl_sources +
+                               gles_gypi.libangle_d3d_shared_sources +
+                               gles_gypi.libangle_d3d9_sources +
+                               gles_gypi.libangle_d3d11_sources +
+                               gles_gypi.libangle_d3d11_win32_sources,
                            ".",
-                           "$angle_root/src") +
-               [ "$angle_root/src/third_party/libXNVCtrl/NVCtrl.c" ]
+                           "$angle_root/src")
+    libs += [
+      "d3d9.lib",
+      "dxguid.lib",
+    ]
+    deps += [
+      # TODO: copy_compiler_dll?
+    ]
   }
 }
 
 shared_library("libEGL") {
   configs += [ ":common" ]
+  configs -= [ "//gn:warnings" ]
   defines = [ "LIBEGL_IMPLEMENTATION" ]
   deps = [
     ":libGLESv2",