Browse Source

Merge pull request #835 from Faless/build/4.x_opt_debug

Rémi Verschelde 2 years ago
parent
commit
bef1fa091c
8 changed files with 71 additions and 28 deletions
  1. 2 2
      .github/workflows/ci.yml
  2. 5 0
      SConstruct
  3. 1 6
      tools/android.py
  4. 0 5
      tools/ios.py
  5. 0 5
      tools/linux.py
  6. 0 5
      tools/macos.py
  7. 57 0
      tools/targets.py
  8. 6 5
      tools/windows.py

+ 2 - 2
.github/workflows/ci.yml

@@ -90,10 +90,10 @@ jobs:
           cd test
           cd test
           scons platform=${{ matrix.platform }} target=debug ${{ matrix.flags }} build_library=no
           scons platform=${{ matrix.platform }} target=debug ${{ matrix.flags }} build_library=no
 
 
-      - name: Build test and godot-cpp (release)
+      - name: Build test and godot-cpp (release, with debug symbols)
         run: |
         run: |
           cd test
           cd test
-          scons platform=${{ matrix.platform }} target=release ${{ matrix.flags }}
+          scons platform=${{ matrix.platform }} target=release debug_symbols=yes ${{ matrix.flags }}
 
 
       - name: Upload artifact
       - name: Upload artifact
         uses: actions/upload-artifact@v3
         uses: actions/upload-artifact@v3

+ 5 - 0
SConstruct

@@ -102,6 +102,10 @@ architecture_aliases = {
 }
 }
 opts.Add(EnumVariable("arch", "CPU architecture", "", architecture_array, architecture_aliases))
 opts.Add(EnumVariable("arch", "CPU architecture", "", architecture_array, architecture_aliases))
 
 
+# Targets flags tool (optimizations, debug symbols)
+target_tool = Tool("targets", toolpath=["tools"])
+target_tool.options(opts)
+
 opts.Update(env)
 opts.Update(env)
 Help(opts.GenerateHelpText(env))
 Help(opts.GenerateHelpText(env))
 
 
@@ -135,6 +139,7 @@ if tool is None or not tool.exists(env):
     raise ValueError("Required toolchain not found for platform " + env["platform"])
     raise ValueError("Required toolchain not found for platform " + env["platform"])
 
 
 tool.generate(env)
 tool.generate(env)
+target_tool.generate(env)
 
 
 # Detect and print a warning listing unknown SCons variables to ease troubleshooting.
 # Detect and print a warning listing unknown SCons variables to ease troubleshooting.
 unknown = opts.UnknownVariables()
 unknown = opts.UnknownVariables()

+ 1 - 6
tools/android.py

@@ -96,11 +96,6 @@ def generate(env):
 
 
     env.Append(
     env.Append(
         CCFLAGS=["--target=" + arch_info["target"] + env["android_api_level"], "-march=" + arch_info["march"], "-fPIC"]
         CCFLAGS=["--target=" + arch_info["target"] + env["android_api_level"], "-march=" + arch_info["march"], "-fPIC"]
-    )  # , '-fPIE', '-fno-addrsig', '-Oz'])
+    )
     env.Append(CCFLAGS=arch_info["ccflags"])
     env.Append(CCFLAGS=arch_info["ccflags"])
     env.Append(LINKFLAGS=["--target=" + arch_info["target"] + env["android_api_level"], "-march=" + arch_info["march"]])
     env.Append(LINKFLAGS=["--target=" + arch_info["target"] + env["android_api_level"], "-march=" + arch_info["march"]])
-
-    if env["target"] == "debug":
-        env.Append(CCFLAGS=["-Og", "-g"])
-    elif env["target"] == "release":
-        env.Append(CCFLAGS=["-O3"])

+ 0 - 5
tools/ios.py

@@ -79,8 +79,3 @@ def generate(env):
 
 
     env.Append(CCFLAGS=["-isysroot", env["IOS_SDK_PATH"]])
     env.Append(CCFLAGS=["-isysroot", env["IOS_SDK_PATH"]])
     env.Append(LINKFLAGS=["-isysroot", env["IOS_SDK_PATH"], "-F" + env["IOS_SDK_PATH"]])
     env.Append(LINKFLAGS=["-isysroot", env["IOS_SDK_PATH"], "-F" + env["IOS_SDK_PATH"]])
-
-    if env["target"] == "debug":
-        env.Append(CCFLAGS=["-Og", "-g"])
-    elif env["target"] == "release":
-        env.Append(CCFLAGS=["-O3"])

+ 0 - 5
tools/linux.py

@@ -18,11 +18,6 @@ def generate(env):
     env.Append(CCFLAGS=["-fPIC", "-Wwrite-strings"])
     env.Append(CCFLAGS=["-fPIC", "-Wwrite-strings"])
     env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"])
     env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"])
 
 
-    if env["target"] == "debug":
-        env.Append(CCFLAGS=["-Og", "-g"])
-    elif env["target"] == "release":
-        env.Append(CCFLAGS=["-O3"])
-
     if env["arch"] == "x86_64":
     if env["arch"] == "x86_64":
         # -m64 and -m32 are x86-specific already, but it doesn't hurt to
         # -m64 and -m32 are x86-specific already, but it doesn't hurt to
         # be clear and also specify -march=x86-64. Similar with 32-bit.
         # be clear and also specify -march=x86-64. Similar with 32-bit.

+ 0 - 5
tools/macos.py

@@ -48,8 +48,3 @@ def generate(env):
             "-Wl,-undefined,dynamic_lookup",
             "-Wl,-undefined,dynamic_lookup",
         ]
         ]
     )
     )
-
-    if env["target"] == "debug":
-        env.Append(CCFLAGS=["-Og", "-g"])
-    elif env["target"] == "release":
-        env.Append(CCFLAGS=["-O3"])

+ 57 - 0
tools/targets.py

@@ -0,0 +1,57 @@
+import os
+import sys
+from SCons.Variables import *
+
+
+def options(opts):
+    opts.Add(
+        EnumVariable(
+            "optimize",
+            "The desired optimization flags",
+            "auto",
+            ("auto", "none", "debug", "speed", "size", "0", "1", "2", "3"),
+        )
+    )
+    opts.Add(BoolVariable("debug_symbols", "Add debugging symbols to release builds", False))
+
+
+def exists(env):
+    return True
+
+
+def generate(env):
+    if env["optimize"] == "auto":
+        env["optimize"] = "speed" if env["target"] == "release" else "debug"
+    env["debug_symbols"] = env["debug_symbols"] or env["target"] == "debug"
+
+    if "is_msvc" in env and env["is_msvc"]:
+        if env["debug_symbols"]:
+            env.Append(CCFLAGS=["/Z7", "/D_DEBUG"])
+            env.Append(LINKFLAGS=["/DEBUG:FULL"])
+        else:
+            env.Append(CCFLAGS=["/Z7", "/DNDEBUG"])
+
+        if env["optimize"] == "speed":
+            env.Append(CCFLAGS=["/O2"])
+        elif env["optimize"] == "size":
+            env.Append(CCFLAGS=["/Os"])
+        elif env["optimize"] == "debug":
+            env.Append(CCFLAGS=["/Od"])
+        elif env["optimize"] == "none":
+            env.Append(CCFLAGS=["/Od"])
+        else:
+            env.Append(CCFLAGS=["/O%s" % env["optimize"]])
+    else:
+        if env["debug_symbols"]:
+            env.Append(CCFLAGS=["-g"])
+
+        if env["optimize"] == "speed":
+            env.Append(CCFLAGS=["-O3"])
+        elif env["optimize"] == "size":
+            env.Append(CCFLAGS=["-Os"])
+        elif env["optimize"] == "debug":
+            env.Append(CCFLAGS=["-Og"])
+        elif env["optimize"] == "none":
+            env.Append(CCFLAGS=["-O0"])
+        else:
+            env.Append(CCFLAGS=["-O%s" % env["optimize"]])

+ 6 - 5
tools/windows.py

@@ -25,12 +25,13 @@ def generate(env):
         env["is_msvc"] = True
         env["is_msvc"] = True
         msvc.generate(env)
         msvc.generate(env)
         env.Append(CPPDEFINES=["TYPED_METHOD_BIND", "NOMINMAX"])
         env.Append(CPPDEFINES=["TYPED_METHOD_BIND", "NOMINMAX"])
+        env.Append(CCFLAGS=["/EHsc"])
         env.Append(LINKFLAGS=["/WX"])
         env.Append(LINKFLAGS=["/WX"])
-        if env["target"] == "debug":
-            env.Append(CCFLAGS=["/Z7", "/Od", "/EHsc", "/D_DEBUG", "/MDd"])
-            env.Append(LINKFLAGS=["/DEBUG:FULL"])
-        elif env["target"] == "release":
-            env.Append(CCFLAGS=["/O2", "/EHsc", "/DNDEBUG", "/MD"])
+        if env["debug_symbols"] or env["target"] == "debug":
+            env.Append(CCFLAGS=["/MDd"])
+        else:
+            env.Append(CCFLAGS=["/MD"])
+
         if env["use_clang_cl"]:
         if env["use_clang_cl"]:
             env["CC"] = "clang-cl"
             env["CC"] = "clang-cl"
             env["CXX"] = "clang-cl"
             env["CXX"] = "clang-cl"