many small fixes to allow user-overridable defaults

This commit is contained in:
2025-08-17 18:25:06 -05:00
parent 4345ca5878
commit 65d8d24480
6 changed files with 119 additions and 90 deletions

40
Jenkinsfile vendored
View File

@@ -2,7 +2,7 @@ pipeline {
agent none agent none
environment { DEBUG = "1" } environment { DEBUG = "1" }
stages { stages {
stage('Build in Docker') { stage('Build Docker Image') {
matrix { matrix {
axes { axes {
axis { axis {
@@ -13,10 +13,6 @@ pipeline {
'debian-13', 'debian-13',
'archlinux-latest' 'archlinux-latest'
} }
axis {
name 'ARCH'
values 'arm64', 'amd64'
}
} }
stages { stages {
stage('Build Multiarch Image') { stage('Build Multiarch Image') {
@@ -33,6 +29,38 @@ pipeline {
} }
} }
} }
}
}
}
}
stages {
stage('Run Docker Image') {
matrix {
axes {
axis {
name 'DISTRO'
values 'ubuntu-24.04',
'fedora-42',
'fedora-41',
'debian-13',
'archlinux-latest'
}
axis {
name 'ARCH'
values 'arm64', 'amd64'
}
axis {
name 'STATIC'
values 'true', 'false'
}
axis {
name 'OPT_AND_LTO'
values 'OPT_LVL=0 LTO=false',
'OPT_LVL=2 LTO=false',
'OPT_LVL=3 LTO=true'
}
}
stages {
stage('Run Multiarch Image') { stage('Run Multiarch Image') {
agent { label "linux && ${ARCH}" } agent { label "linux && ${ARCH}" }
steps { steps {
@@ -43,7 +71,7 @@ pipeline {
passwordVariable: 'DOCKER_REGISTRY_PASS', passwordVariable: 'DOCKER_REGISTRY_PASS',
usernameVariable: 'DOCKER_REGISTRY_USER' usernameVariable: 'DOCKER_REGISTRY_USER'
)]) { )]) {
sh "./scripts/docker_run_image.sh ${DISTRO}" sh "STATIC=${STATIC} ${OPT_AND_LTO} ./scripts/docker_run_image.sh ${DISTRO}"
} }
} }
} }

View File

@@ -15,6 +15,8 @@ set_compile_opts() {
# set job count for all builds # set job count for all builds
JOBS="$(nproc)" JOBS="$(nproc)"
# local vs system prefix
test "${PREFIX}" == 'local' && PREFIX="${IGN_DIR}/$(print_os)_sysroot"
# set library/pkgconfig directory # set library/pkgconfig directory
LIBDIR="${PREFIX}/lib" LIBDIR="${PREFIX}/lib"
@@ -90,7 +92,7 @@ set_compile_opts() {
PKG_CFG_FLAGS='--static' PKG_CFG_FLAGS='--static'
LIB_SUFF='a' LIB_SUFF='a'
else else
LDFLAGS+=("-Wl,-rpath,${LIBDIR}") LDFLAGS+=("-Wl,-rpath,${LIBDIR}" "-Wl,-rpath-link,${LIBDIR}")
CONFIGURE_FLAGS+=('--enable-shared') CONFIGURE_FLAGS+=('--enable-shared')
CMAKE_FLAGS+=("-DBUILD_SHARED_LIBS=ON") CMAKE_FLAGS+=("-DBUILD_SHARED_LIBS=ON")
CMAKE_FLAGS+=("-DCMAKE_INSTALL_RPATH=${LIBDIR}") CMAKE_FLAGS+=("-DCMAKE_INSTALL_RPATH=${LIBDIR}")
@@ -321,11 +323,11 @@ FB_FUNC_NAMES+=('build')
# shellcheck disable=SC2034 # shellcheck disable=SC2034
FB_FUNC_DESCS['build']='build ffmpeg with desired configuration' FB_FUNC_DESCS['build']='build ffmpeg with desired configuration'
build() { build() {
test -d "${DL_DIR}" || mkdir -p "${DL_DIR}" test -d "${DL_DIR}" || { mkdir -p "${DL_DIR}" || return 1; }
test -d "${CCACHE_DIR}" || mkdir -p "${CCACHE_DIR}" test -d "${CCACHE_DIR}" || { mkdir -p "${CCACHE_DIR}" || return 1; }
test -d "${BUILD_DIR}" || mkdir -p "${BUILD_DIR}" test -d "${BUILD_DIR}" || { mkdir -p "${BUILD_DIR}" || return 1; }
test -d "${PREFIX}/bin/" || mkdir -p "${PREFIX}/bin/"
set_compile_opts || return 1
# check if we need to install with sudo # check if we need to install with sudo
unset SUDO_MODIFY unset SUDO_MODIFY
testfile="${PREFIX}/ffmpeg-build-testfile" testfile="${PREFIX}/ffmpeg-build-testfile"
@@ -333,14 +335,16 @@ build() {
SUDO_MODIFY='' SUDO_MODIFY=''
else else
SUDO_MODIFY="${SUDO}" SUDO_MODIFY="${SUDO}"
${SUDO_MODIFY} mkdir -p "${PREFIX}/bin/" ${SUDO_MODIFY} mkdir -p "${PREFIX}/bin/" || return 1
fi fi
test -f "${testfile}" && ${SUDO_MODIFY} rm "${testfile}" test -f "${testfile}" && ${SUDO_MODIFY} rm "${testfile}"
test -d "${PREFIX}" && ${SUDO_MODIFY} rm -rf "${PREFIX}"
test -d "${PREFIX}/bin/" || { ${SUDO_MODIFY} mkdir -p "${PREFIX}/bin/" || return 1; }
# embed this project's enables/versions # embed this project's enables/versions
# into ffmpeg with this variable # into ffmpeg with this variable
FFMPEG_BUILDER_INFO=("ffmpeg-builder=$(cd "${REPO_DIR}" && git rev-parse HEAD)") FFMPEG_BUILDER_INFO=("ffmpeg-builder=$(cd "${REPO_DIR}" && git rev-parse HEAD)")
for build in "${FFMPEG_ENABLES[@]}"; do for build in ${FFMPEG_ENABLES}; do
do_build "${build}" || return 1 do_build "${build}" || return 1
done done
do_build "ffmpeg" || return 1 do_build "ffmpeg" || return 1
@@ -423,8 +427,8 @@ build_libsvtav1() {
${SUDO_MODIFY} make -j"${JOBS}" install || return 1 ${SUDO_MODIFY} make -j"${JOBS}" install || return 1
} }
build_libsvtav1_psy() { build_libsvtav1_psy() {
local hdr10pluslib="$(find "${PREFIX}" -type f -name "libhdr10plus-rs.${LIB_SUFF}")" local hdr10pluslib="$(find -L "${PREFIX}" -type f -name "libhdr10plus-rs.${LIB_SUFF}")"
local dovilib="$(find "${PREFIX}" -type f -name "libdovi.${LIB_SUFF}")" local dovilib="$(find -L "${PREFIX}" -type f -name "libdovi.${LIB_SUFF}")"
cmake \ cmake \
"${CMAKE_FLAGS[@]}" \ "${CMAKE_FLAGS[@]}" \
-DSVT_AV1_LTO="${LTO_SWITCH}" \ -DSVT_AV1_LTO="${LTO_SWITCH}" \
@@ -448,6 +452,16 @@ build_libaom() {
ccache make -j"${JOBS}" || return 1 ccache make -j"${JOBS}" || return 1
${SUDO_MODIFY} make -j"${JOBS}" install || return 1 ${SUDO_MODIFY} make -j"${JOBS}" install || return 1
} }
build_libopus() {
# ./configure \
# "${CONFIGURE_FLAGS[@]}" \
# --disable-doc || return 1
cmake \
"${CMAKE_FLAGS[@]}" || return 1
ccache make -j"${JOBS}" || return 1
${SUDO_MODIFY} make -j"${JOBS}" install || return 1
return 0
}
### MESON ### ### MESON ###
build_libdav1d() { build_libdav1d() {
@@ -497,14 +511,6 @@ build_libvmaf() {
} }
### AUTOTOOLS ### ### AUTOTOOLS ###
build_libopus() {
./configure \
"${CONFIGURE_FLAGS[@]}" \
--disable-doc || return 1
ccache make -j"${JOBS}" || return 1
${SUDO_MODIFY} make -j"${JOBS}" install || return 1
return 0
}
# special function mainly for arm64 builds # special function mainly for arm64 builds
# since most distros do not compile libc # since most distros do not compile libc
# with -fPIC for some reason # with -fPIC for some reason
@@ -580,7 +586,7 @@ add_project_versioning_to_ffmpeg() {
return 0 return 0
} }
build_ffmpeg() { build_ffmpeg() {
for enable in "${FFMPEG_ENABLES[@]}"; do for enable in ${FFMPEG_ENABLES}; do
test "${enable}" == 'libsvtav1_psy' && enable='libsvtav1' test "${enable}" == 'libsvtav1_psy' && enable='libsvtav1'
CONFIGURE_FLAGS+=("--enable-${enable}") CONFIGURE_FLAGS+=("--enable-${enable}")
done done

View File

@@ -3,26 +3,49 @@
# variables used externally # variables used externally
# shellcheck disable=SC2034 # shellcheck disable=SC2034
# default compile options
# clean build directories before building # clean build directories before building
CLEAN=true DEFAULT_CLEAN=true
# enable link time optimization # enable link time optimization
LTO=false DEFAULT_LTO=true
# optimization level (0-3) # optimization level (0-3)
OPT_LVL=0 DEFAULT_OPT_LVL=3
# static or shared build # static or shared build
STATIC=true DEFAULT_STATIC=true
# CPU type (amd64/v{1,2,3}...) # CPU type (amd64/v{1,2,3}...)
CPU=native DEFAULT_CPU=native
# architecture type # architecture type
ARCH=native DEFAULT_ARCH=native
# prefix to install, leave empty for non-system install (local) # prefix to install to, default is local install
PREFIX='' DEFAULT_PREFIX='local'
# configure what ffmpeg enables # configure what ffmpeg enables
FFMPEG_ENABLES=( DEFAULT_FFMPEG_ENABLES="\
libopus libsvtav1_psy \
libdav1d libopus \
libsvtav1_psy libdav1d \
libaom libaom \
librav1e librav1e \
libvmaf libvmaf \
"
# user-overridable compile option variable names
FB_COMP_OPTS=(
CLEAN LTO OPT_LVL STATIC CPU ARCH PREFIX FFMPEG_ENABLES
) )
# sets FB_COMP_OPTS to allow for user-overriding
check_compile_opts_override() {
for opt in "${FB_COMP_OPTS[@]}"; do
declare -n defOptVal="DEFAULT_${opt}"
declare -n optVal="${opt}"
# use given value if not overridden
if [[ -n ${optVal} && ${optVal} != "${defOptVal}" ]]; then
echo_warn "setting given value for ${opt}=${optVal[*]}"
declare -g "${opt}=${optVal}"
else
echo_info "setting default value for ${opt}=${defOptVal[*]}"
declare -g "${opt}=${defOptVal}"
fi
done
}

View File

@@ -8,18 +8,29 @@ VALID_DOCKER_IMAGES=(
'archlinux-latest' 'archlinux-latest'
) )
DOCKER_WORKDIR='/workdir' DOCKER_WORKDIR='/workdir'
DOCKER_RUN_FLAGS=(
set_docker_run_flags() {
DOCKER_RUN_FLAGS=(
--rm --rm
-v "${REPO_DIR}:${DOCKER_WORKDIR}" -v "${REPO_DIR}:${REPO_DIR}"
-w "${DOCKER_WORKDIR}" -w "${REPO_DIR}"
-e "DEBUG=${DEBUG}" -e "DEBUG=${DEBUG}"
) )
for opt in "${FB_COMP_OPTS[@]}"; do
declare -n defOptVal="DEFAULT_${opt}"
declare -n optVal="${opt}"
if [[ -n ${optVal} && ${optVal} != "${defOptVal}" ]]; then
DOCKER_RUN_FLAGS+=("-e" "${opt}=${optVal}")
fi
done
}
check_docker() { check_docker() {
if missing_cmd docker; then if missing_cmd docker; then
echo_info "install docker" echo_info "install docker"
curl https://get.docker.com -sSf | bash curl https://get.docker.com -sSf | bash
fi fi
set_docker_run_flags || return 1
} }
# change dash to colon for docker and add namespace # change dash to colon for docker and add namespace
@@ -82,34 +93,20 @@ docker_build_image() {
echo_info "sourcing package manager for ${distro}" echo_info "sourcing package manager for ${distro}"
local dockerDistro="${distro}" local dockerDistro="${distro}"
# custom multi-arch image for archlinux # custom multi-arch image for archlinux
test "${distro}" == 'archlinux-latest' && \ test "${distro}" == 'archlinux-latest' &&
dockerDistro='ogarcia/archlinux-latest' dockerDistro='ogarcia/archlinux-latest'
# docker expects colon instead of dash # docker expects colon instead of dash
dockerDistro="${dockerDistro//-/:}" dockerDistro="${dockerDistro//-/:}"
# specific file for evaluated package manager info # specific file for evaluated package manager info
distroPkgMgr="${DOCKER_DIR}/$(bash_basename "${distro}")-pkg_mgr" distroPkgMgr="${DOCKER_DIR}/$(bash_basename "${distro}")-pkg_mgr"
# get package manager info # get package manager info
# TODO REMOVE
if is_root_owned "${IGN_DIR}"; then
docker run \
"${DOCKER_RUN_FLAGS[@]}" \
"${dockerDistro}" \
chown -R "$(id -u):$(id -g)" "${DOCKER_WORKDIR}"/gitignore
fi
if ! echo_if_fail ls; then
docker run \
"${DOCKER_RUN_FLAGS[@]}" \
"${dockerDistro}" \
chown -R "$(id -u):$(id -g)" "${DOCKER_WORKDIR}"/gitignore
fi
docker run \ docker run \
"${DOCKER_RUN_FLAGS[@]}" \ "${DOCKER_RUN_FLAGS[@]}" \
"${dockerDistro}" \ "${dockerDistro}" \
bash -c "./scripts/print_pkg_mgr.sh" | tr -d '\r' >"${distroPkgMgr}" bash -c "./scripts/print_pkg_mgr.sh" | tr -d '\r' >"${distroPkgMgr}"
# shellcheck disable=SC1090 # shellcheck disable=SC1090
cat "${distroPkgMgr}" cat "${distroPkgMgr}"
# shellcheck disable=SC1090
source "${distroPkgMgr}" source "${distroPkgMgr}"
dockerfile="${DOCKER_DIR}/Dockerfile_$(bash_basename "${distro}")" dockerfile="${DOCKER_DIR}/Dockerfile_$(bash_basename "${distro}")"
@@ -213,28 +210,6 @@ docker_run_image() {
for distro in "${DISTROS[@]}"; do for distro in "${DISTROS[@]}"; do
dockerDistro="${distro//-/:}" dockerDistro="${distro//-/:}"
# TODO REMOVE
if is_root_owned "${IGN_DIR}"; then
docker run \
"${DOCKER_RUN_FLAGS[@]}" \
"${dockerDistro}" \
chown -R "$(id -u):$(id -g)" "${DOCKER_WORKDIR}"/gitignore
fi
if ! echo_if_fail ls; then
docker run \
"${DOCKER_RUN_FLAGS[@]}" \
"${dockerDistro}" \
chown -R "$(id -u):$(id -g)" "${DOCKER_WORKDIR}"/gitignore
fi
testfile="${PREFIX}/ffmpeg-build-testfile"
if ! touch "${testfile}" 2>/dev/null; then
docker run \
"${DOCKER_RUN_FLAGS[@]}" \
"${dockerDistro}" \
chown -R "$(id -u):$(id -g)" "${DOCKER_WORKDIR}"/gitignore
fi
image_tag="$(set_distro_image_tag "${distro}")" image_tag="$(set_distro_image_tag "${distro}")"
# if a docker registry is defined, pull from it # if a docker registry is defined, pull from it
@@ -245,8 +220,7 @@ docker_run_image() {
docker tag "${DOCKER_REGISTRY}/${image_tag}" "${image_tag}" docker tag "${DOCKER_REGISTRY}/${image_tag}" "${image_tag}"
fi fi
echo_info "running ffmpeg build for ${image_tag}" echo_info "running ffmpeg build with ${image_tag}"
docker run \ docker run \
"${DOCKER_RUN_FLAGS[@]}" \ "${DOCKER_RUN_FLAGS[@]}" \
-u "$(id -u):$(id -g)" \ -u "$(id -u):$(id -g)" \

View File

@@ -38,7 +38,7 @@ src_scripts() {
echo '#!/usr/bin/env bash echo '#!/usr/bin/env bash
cd "$(dirname "$(readlink -f $0)")/.." cd "$(dirname "$(readlink -f $0)")/.."
export FB_RUNNING_AS_SCRIPT=1 export FB_RUNNING_AS_SCRIPT=1
. main.sh . main.sh || return 1
scr_name="$(bash_basename $0)" scr_name="$(bash_basename $0)"
cmd="${scr_name//.sh/}" cmd="${scr_name//.sh/}"
if [[ $DEBUG == 1 ]]; then set -x; fi if [[ $DEBUG == 1 ]]; then set -x; fi
@@ -75,9 +75,7 @@ set_completions() {
test -f "${HOME}/.bashrc" && source "${HOME}/.bashrc" test -f "${HOME}/.bashrc" && source "${HOME}/.bashrc"
src_scripts || return 1 src_scripts || return 1
determine_pkg_mgr || return 1 determine_pkg_mgr || return 1
check_compile_opts_override || return
# shellcheck disable=SC2154
test "${PREFIX}" == '' && PREFIX="${IGN_DIR}/$(print_os)_sysroot"
if [[ $FB_RUNNING_AS_SCRIPT -eq 0 ]]; then if [[ $FB_RUNNING_AS_SCRIPT -eq 0 ]]; then
print_cmds || return 1 print_cmds || return 1

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
cd "$(dirname "$(readlink -f $0)")/.." cd "$(dirname "$(readlink -f $0)")/.."
export FB_RUNNING_AS_SCRIPT=1 export FB_RUNNING_AS_SCRIPT=1
. main.sh . main.sh || return 1
scr_name="$(bash_basename $0)" scr_name="$(bash_basename $0)"
cmd="${scr_name//.sh/}" cmd="${scr_name//.sh/}"
if [[ $DEBUG == 1 ]]; then set -x; fi if [[ $DEBUG == 1 ]]; then set -x; fi