blob: d68d83b25fb6d7d339c9bb85fcadf6a035204748 [file] [log] [blame]
# Copyright 2023 The Cobalt Authors. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("dav1d_generated.gni")
import("//build/config/compiler/compiler.gni")
import("//build/config/sanitizers/sanitizers.gni")
assert(use_cobalt_customizations)
if (is_starboard) {
import("//starboard/build/nasm_assemble.gni")
} else {
import("//third_party/nasm/nasm_assemble.gni")
}
# MemorySanitizer can't handle assembly, https://crbug.com/928357.
enable_nasm =
nasm_exists && (current_cpu == "x86" || current_cpu == "x64") && !is_msan
# Some older compilers can't handle AVX-512 instructions.
if (using_old_compiler) {
enable_nasm = false
}
if (is_win) {
platform_config_root = "config/win/$current_cpu"
} else if (is_msan) {
assert(current_cpu == "x64" && (is_linux || is_chromeos),
"Only Linux X64 MSAN is supported")
platform_config_root = "config/linux-noasm/$current_cpu"
} else if (current_cpu == "riscv64" || current_cpu == "loong64" ||
current_cpu == "mipsel" || current_cpu == "mips64el" ||
current_cpu == "ppc64") {
platform_config_root = "config/linux-noasm/generic"
} else {
# Linux configuration files seem to work on Mac, so just reuse them.
if (enable_nasm) {
platform_config_root = "config/linux/$current_cpu"
} else {
platform_config_root = "config/linux-noasm/$current_cpu"
}
}
# Clang LTO doesn't respect stack alignment and clang-cl doesn't support setting
# the stack alignment, so we must use the platform's default alignment in those
# cases; https://crbug.com/928743.
if (enable_nasm) {
if (use_thin_lto || is_win) {
needs_stack_alignment = false
# The defaults are stack_alignment=4 for x86 and stack_alignment=16 for x64.
} else {
# The compiler flags, as well as the stack alignment values, all mirror
# upstream's meson.build setup:
# https://chromium.googlesource.com/external/github.com/videolan/dav1d/+/master/meson.build
needs_stack_alignment = true
if (current_cpu == "x64" || (is_linux && !is_android) || is_apple) {
stack_alignment = 16
} else {
stack_alignment = 4
}
}
}
config("public_dav1d_config") {
include_dirs = [ "version" ]
# Disable internal dav1d logs in the official build to save storage.
if (is_official_build) {
defines = [ "CONFIG_LOG=0" ]
} else {
defines = [ "CONFIG_LOG=1" ]
}
if (!is_android && !is_win) {
defines += [
"HAVE_PTHREAD_GETAFFINITY_NP=1",
"HAVE_PTHREAD_SETAFFINITY_NP=1",
]
}
# Don't let dav1d export any symbols. Otherwise the verify_order step on macOS
# can fail since these exports end up in the final Chromium binary.
defines += [ "DAV1D_API=" ]
}
config("dav1d_config") {
configs = [ ":public_dav1d_config" ]
include_dirs = [
".",
"include",
"include/dav1d",
platform_config_root,
]
if (is_win && !is_clang) {
include_dirs += [ "include/compat/msvc" ]
}
}
dav1d_copts = [
"-D_FILE_OFFSET_BITS=64",
"-D_POSIX_C_SOURCE=200112L",
]
if (is_win) {
if (!is_clang) {
dav1d_copts += [ "/wd4028" ]
}
} else {
dav1d_copts += [ "-std=c99" ]
if (is_mac || is_ios) {
dav1d_copts += [ "-D_DARWIN_C_SOURCE" ]
}
if (is_linux || is_chromeos || is_android || current_os == "aix") {
if (!is_clang) {
dav1d_copts += [ "-D_GNU_SOURCE" ]
}
}
}
if (enable_nasm) {
nasm_assemble("dav1d_asm") {
sources = x86_asm_sources
inputs = [
"src/ext/x86/x86inc.asm",
"$platform_config_root/config.asm",
]
include_dirs = [
"src/",
platform_config_root,
]
nasm_flags = [
"-P",
rebase_path("$platform_config_root/config.asm", root_build_dir),
]
defines = []
if (needs_stack_alignment) {
defines += [ "STACK_ALIGNMENT=$stack_alignment" ]
}
# Necessary to ensure macOS symbols end up with a _ prefix.
if (is_mac || is_ios) {
defines += [ "PREFIX" ]
}
}
}
source_set("dav1d_headers") {
configs += [ ":dav1d_config" ]
sources = c_headers
}
static_library("dav1d_8bit") {
configs += [ ":dav1d_config" ]
sources = template_sources
if (current_cpu == "x86" || current_cpu == "x64") {
sources += x86_template_sources
} else if (current_cpu == "arm") {
sources += arm_template_sources
} else if (current_cpu == "arm64") {
sources += arm_template_sources
}
cflags = dav1d_copts
cflags += [ "-DBITDEPTH=8" ]
deps = [ ":dav1d_headers" ]
}
static_library("dav1d_10bit") {
configs -= [
# "//build/config/compiler:chromium_code",
# Disable coverage for the 10 bit version to avoid confusing the
# instrumentation about which version of the library is being run.
# dav1d_10 bit was selected for this, as it's less used than dav1d_8bit,
# which still has coverage enabled. See crbug.com/1030350.
"//build/config/coverage:default_coverage",
]
configs += [ ":dav1d_config" ]
sources = template_sources
if (current_cpu == "x86" || current_cpu == "x64") {
sources += x86_template_sources
} else if (current_cpu == "arm") {
sources += arm_template_sources
} else if (current_cpu == "arm64") {
sources += arm_template_sources
}
cflags = dav1d_copts
cflags += [ "-DBITDEPTH=16" ]
deps = [ ":dav1d_headers" ]
}
if (current_cpu == "x86" || current_cpu == "x64") {
static_library("dav1d_x86") {
sources = [
"src/x86/cpu.c",
"src/x86/cpu.h",
]
configs += [ ":dav1d_config" ]
cflags = dav1d_copts
deps = [ ":dav1d_headers" ]
allow_circular_includes_from = [ ":dav1d_headers" ]
}
} else if (current_cpu == "arm" || current_cpu == "arm64") {
static_library("dav1d_arm") {
sources = [
"src/arm/cpu.c",
"src/arm/cpu.h",
]
# These are not template based so should only be built once.
if (current_cpu == "arm") {
sources += arm32_asm_sources
} else if (current_cpu == "arm64") {
sources += arm64_asm_sources
}
configs += [ ":dav1d_config" ]
# Necessary to ensure macOS symbols end up with a _ prefix.
if (is_mac || is_ios) {
defines = [ "PREFIX" ]
}
cflags = dav1d_copts
deps = [ ":dav1d_headers" ]
allow_circular_includes_from = [ ":dav1d_headers" ]
}
}
static_library("dav1d") {
sources = c_sources
if (is_win) {
sources += [ "src/win32/thread.c" ]
}
configs += [ ":dav1d_config" ]
cflags = dav1d_copts
deps = [
":dav1d_10bit",
":dav1d_8bit",
":dav1d_headers",
]
public_configs = [ ":public_dav1d_config" ]
if (current_cpu == "x86" || current_cpu == "x64") {
deps += [ ":dav1d_x86" ]
if (enable_nasm) {
deps += [ ":dav1d_asm" ]
}
} else if (current_cpu == "arm" || current_cpu == "arm64") {
deps += [ ":dav1d_arm" ]
}
}