blob: bbf0f0ecbc54eebcd16d1bd433e696793a0b9316 [file] [log] [blame]
Dale Curtis9596cc02018-10-31 14:25:55 -07001# 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
5import("//build/config/compiler/compiler.gni")
6import("nasm_sources.gni")
7
Dale Curtis4fa54ca2020-04-14 12:55:13 -07008configs_to_delete = [ "//build/config/compiler:chromium_code" ]
Dale Curtisc74336e2020-04-13 15:37:55 -07009
Takuto Ikutafc8e0bd2022-10-25 14:17:36 +090010should_remove_default_deps_for_performance = false
11
Dale Curtis4fa54ca2020-04-14 12:55:13 -070012# 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
14if (!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 Ikutafc8e0bd2022-10-25 14:17:36 +090019
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 Curtis4fa54ca2020-04-14 12:55:13 -070027}
Dale Curtisc74336e2020-04-13 15:37:55 -070028
Takuto Ikutaae8e4ca2019-02-19 13:59:42 +090029configs_to_add = [ "//build/config/compiler:no_chromium_code" ]
Dale Curtis9596cc02018-10-31 14:25:55 -070030if (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
54config("nasm_config") {
55 include_dirs = [
56 ".",
57 "asm",
Dale Curtis9596cc02018-10-31 14:25:55 -070058 "disasm",
59 "include",
60 "output",
61 "x86",
62 ]
63
Dale Curtis9596cc02018-10-31 14:25:55 -070064 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 Curtis20920a82018-11-01 17:26:45 -070076
77 # NASM sometimes compares enums to unsigned integers.
78 "-Wno-sign-compare",
Dale Curtise2938142020-06-29 15:29:48 -070079
80 # NASM sometimes return null from nonnull.
81 "-Wno-nonnull",
82
83 # NASM sometimes uses uninitialized values.
84 "-Wno-uninitialized",
Alan Screen2fda35e2021-06-14 13:46:57 -070085
86 # NASM sometimes set variables but doesn't use them.
87 "-Wno-unused-but-set-variable",
Dale Curtis9596cc02018-10-31 14:25:55 -070088 ]
Yves Gereye701d162018-11-09 18:44:47 +010089 } 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 Gereya0a69512018-11-09 19:35:11 +010098 # char VS const char mismatch.
99 "/wd4028", # formal parameter 1 different from declaration.
100
Yves Gereye701d162018-11-09 18:44:47 +0100101 # 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 Curtis9596cc02018-10-31 14:25:55 -0700108 }
109}
110
111if (current_toolchain == host_toolchain) {
112 executable("nasm") {
113 sources = nasmlib_sources + nasm_sources
Dale Curtis3dacc5e2018-11-01 10:48:41 -0700114 sources += [
Dale Curtis3dacc5e2018-11-01 10:48:41 -0700115 "config/config-linux.h",
Takuto Ikutaae8e4ca2019-02-19 13:59:42 +0900116 "config/config-mac.h",
117 "config/config.h",
Dale Curtis19f3fad2020-07-15 11:22:01 -0700118 "config/msvc.h",
119 "config/unconfig.h",
Dale Curtis3dacc5e2018-11-01 10:48:41 -0700120 ]
Dale Curtis9596cc02018-10-31 14:25:55 -0700121
122 configs -= configs_to_delete
123 configs += configs_to_add
124 configs += [ ":nasm_config" ]
125
Dale Curtis9596cc02018-10-31 14:25:55 -0700126 deps = [
127 # Default manifest on Windows (a no-op elsewhere).
128 "//build/win:default_exe_manifest",
129 ]
Takuto Ikuta2157ddf2022-10-17 13:18:17 +0900130
Takuto Ikutafc8e0bd2022-10-25 14:17:36 +0900131 no_default_deps = should_remove_default_deps_for_performance
Dale Curtis9596cc02018-10-31 14:25:55 -0700132 }
133}