Dale Curtis | 9596cc0 | 2018-10-31 14:25:55 -0700 | [diff] [blame] | 1 | # Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | import("//build/config/compiler/compiler.gni") |
| 6 | import("nasm_sources.gni") |
| 7 | |
Dale Curtis | 4fa54ca | 2020-04-14 12:55:13 -0700 | [diff] [blame] | 8 | configs_to_delete = [ "//build/config/compiler:chromium_code" ] |
Dale Curtis | c74336e | 2020-04-13 15:37:55 -0700 | [diff] [blame] | 9 | |
Takuto Ikuta | fc8e0bd | 2022-10-25 14:17:36 +0900 | [diff] [blame] | 10 | should_remove_default_deps_for_performance = false |
| 11 | |
Dale Curtis | 4fa54ca | 2020-04-14 12:55:13 -0700 | [diff] [blame] | 12 | # We'd like to disable sanitizers in all cases, but this is not possible with |
| 13 | # MSAN due to its linkage with instrumented libraries. https://crbug.com/928357 |
| 14 | if (!is_msan) { |
| 15 | configs_to_delete += [ |
| 16 | # Don't enable sanitizers for build tools. They slow down the overall build. |
| 17 | "//build/config/sanitizers:default_sanitizer_flags", |
| 18 | ] |
Takuto Ikuta | fc8e0bd | 2022-10-25 14:17:36 +0900 | [diff] [blame] | 19 | |
| 20 | # Without no_default_deps, an implicit dependency on libc++ is added. |
| 21 | # libc++ may have been built referencing the debug CRT, but since we're |
| 22 | # explicitly using the release CRT, this would result in undefined symbol |
| 23 | # errors when linking, so we need to remove the implicit libc++ dependency. |
| 24 | # This is also needed to remove some configurations which make nasm's |
| 25 | # performance slow. |
| 26 | should_remove_default_deps_for_performance = true |
Dale Curtis | 4fa54ca | 2020-04-14 12:55:13 -0700 | [diff] [blame] | 27 | } |
Dale Curtis | c74336e | 2020-04-13 15:37:55 -0700 | [diff] [blame] | 28 | |
Takuto Ikuta | ae8e4ca | 2019-02-19 13:59:42 +0900 | [diff] [blame] | 29 | configs_to_add = [ "//build/config/compiler:no_chromium_code" ] |
Dale Curtis | 9596cc0 | 2018-10-31 14:25:55 -0700 | [diff] [blame] | 30 | if (is_debug) { |
| 31 | configs_to_delete += [ |
| 32 | # Build with full optimizations even on debug configurations, because some |
| 33 | # yasm build steps (highbd_sad4d_sse2.asm) can take ~33 seconds or more in |
| 34 | # debug component builds on Windows. Enabling compiler optimizations saves |
| 35 | # ~5 seconds. |
| 36 | "//build/config/compiler:default_optimization", |
| 37 | |
| 38 | # Don't define _DEBUG. Modest savings, but good for consistency. |
| 39 | "//build/config:debug", |
| 40 | ] |
| 41 | |
| 42 | configs_to_add += [ |
| 43 | "//build/config:release", |
| 44 | "//build/config/compiler:optimize_max", |
| 45 | ] |
| 46 | if (is_win) { |
| 47 | # This switches to using the release CRT. For yasm debug component builds |
| 48 | # of highbd_sad4d_sse2.asm on Windows this saved about 15 s. |
| 49 | configs_to_delete += [ "//build/config/win:default_crt" ] |
| 50 | configs_to_add += [ "//build/config/win:release_crt" ] |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | config("nasm_config") { |
| 55 | include_dirs = [ |
| 56 | ".", |
| 57 | "asm", |
Dale Curtis | 9596cc0 | 2018-10-31 14:25:55 -0700 | [diff] [blame] | 58 | "disasm", |
| 59 | "include", |
| 60 | "output", |
| 61 | "x86", |
| 62 | ] |
| 63 | |
Dale Curtis | 9596cc0 | 2018-10-31 14:25:55 -0700 | [diff] [blame] | 64 | defines = [ "HAVE_CONFIG_H" ] |
| 65 | |
| 66 | if (is_clang) { |
| 67 | cflags = [ |
| 68 | # The inline functions in NASM's headers flag this. |
| 69 | "-Wno-unused-function", |
| 70 | |
| 71 | # NASM writes nasm_assert(!"some string literal"). |
| 72 | "-Wno-string-conversion", |
| 73 | |
| 74 | # NASM sometimes redefines macros from its config.h. |
| 75 | "-Wno-macro-redefined", |
Dale Curtis | 20920a8 | 2018-11-01 17:26:45 -0700 | [diff] [blame] | 76 | |
| 77 | # NASM sometimes compares enums to unsigned integers. |
| 78 | "-Wno-sign-compare", |
Dale Curtis | e293814 | 2020-06-29 15:29:48 -0700 | [diff] [blame] | 79 | |
| 80 | # NASM sometimes return null from nonnull. |
| 81 | "-Wno-nonnull", |
| 82 | |
| 83 | # NASM sometimes uses uninitialized values. |
| 84 | "-Wno-uninitialized", |
Alan Screen | 2fda35e | 2021-06-14 13:46:57 -0700 | [diff] [blame] | 85 | |
| 86 | # NASM sometimes set variables but doesn't use them. |
| 87 | "-Wno-unused-but-set-variable", |
Dale Curtis | 9596cc0 | 2018-10-31 14:25:55 -0700 | [diff] [blame] | 88 | ] |
Yves Gerey | e701d16 | 2018-11-09 18:44:47 +0100 | [diff] [blame] | 89 | } else if (is_win) { |
| 90 | # Please note that's a slightly different set of warnings. |
| 91 | cflags = [ |
| 92 | # NASM sometimes redefines macros from its config.h. |
| 93 | "/wd4005", # macro redefinition |
| 94 | |
| 95 | # NASM sometimes compares enums to unsigned integers. |
| 96 | "/wd4018", # sign compare |
| 97 | |
Yves Gerey | a0a6951 | 2018-11-09 19:35:11 +0100 | [diff] [blame] | 98 | # char VS const char mismatch. |
| 99 | "/wd4028", # formal parameter 1 different from declaration. |
| 100 | |
Yves Gerey | e701d16 | 2018-11-09 18:44:47 +0100 | [diff] [blame] | 101 | # NASM comment: Uninitialized -> all zero by C spec |
| 102 | # Or sometimes one const struct is forward declared for no reason. |
| 103 | "/wd4132", # const object should be initialized |
| 104 | |
| 105 | # NASM uses "(-x) & 0xFF" pattern to negate byte. |
| 106 | "/wd4146", # unary minus operator applied to unsigned type |
| 107 | ] |
Dale Curtis | 9596cc0 | 2018-10-31 14:25:55 -0700 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | |
| 111 | if (current_toolchain == host_toolchain) { |
| 112 | executable("nasm") { |
| 113 | sources = nasmlib_sources + nasm_sources |
Dale Curtis | 3dacc5e | 2018-11-01 10:48:41 -0700 | [diff] [blame] | 114 | sources += [ |
Dale Curtis | 3dacc5e | 2018-11-01 10:48:41 -0700 | [diff] [blame] | 115 | "config/config-linux.h", |
Takuto Ikuta | ae8e4ca | 2019-02-19 13:59:42 +0900 | [diff] [blame] | 116 | "config/config-mac.h", |
| 117 | "config/config.h", |
Dale Curtis | 19f3fad | 2020-07-15 11:22:01 -0700 | [diff] [blame] | 118 | "config/msvc.h", |
| 119 | "config/unconfig.h", |
Dale Curtis | 3dacc5e | 2018-11-01 10:48:41 -0700 | [diff] [blame] | 120 | ] |
Dale Curtis | 9596cc0 | 2018-10-31 14:25:55 -0700 | [diff] [blame] | 121 | |
| 122 | configs -= configs_to_delete |
| 123 | configs += configs_to_add |
| 124 | configs += [ ":nasm_config" ] |
| 125 | |
Dale Curtis | 9596cc0 | 2018-10-31 14:25:55 -0700 | [diff] [blame] | 126 | deps = [ |
| 127 | # Default manifest on Windows (a no-op elsewhere). |
| 128 | "//build/win:default_exe_manifest", |
| 129 | ] |
Takuto Ikuta | 2157ddf | 2022-10-17 13:18:17 +0900 | [diff] [blame] | 130 | |
Takuto Ikuta | fc8e0bd | 2022-10-25 14:17:36 +0900 | [diff] [blame] | 131 | no_default_deps = should_remove_default_deps_for_performance |
Dale Curtis | 9596cc0 | 2018-10-31 14:25:55 -0700 | [diff] [blame] | 132 | } |
| 133 | } |