diff --git a/Jenkinsfile b/Jenkinsfile index 8fb39ac..8fc97a1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,7 +2,7 @@ pipeline { agent none environment { DEBUG = "1" } stages { - stage('Build in Docker') { + stage('Build Docker Image') { matrix { axes { axis { @@ -13,10 +13,6 @@ pipeline { 'debian-13', 'archlinux-latest' } - axis { - name 'ARCH' - values 'arm64', 'amd64' - } } stages { 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') { agent { label "linux && ${ARCH}" } steps { @@ -43,7 +71,7 @@ pipeline { passwordVariable: 'DOCKER_REGISTRY_PASS', usernameVariable: 'DOCKER_REGISTRY_USER' )]) { - sh "./scripts/docker_run_image.sh ${DISTRO}" + sh "STATIC=${STATIC} ${OPT_AND_LTO} ./scripts/docker_run_image.sh ${DISTRO}" } } } diff --git a/lib/build.sh b/lib/build.sh index 30e19d3..e5f92c8 100644 --- a/lib/build.sh +++ b/lib/build.sh @@ -15,6 +15,8 @@ set_compile_opts() { # set job count for all builds JOBS="$(nproc)" + # local vs system prefix + test "${PREFIX}" == 'local' && PREFIX="${IGN_DIR}/$(print_os)_sysroot" # set library/pkgconfig directory LIBDIR="${PREFIX}/lib" @@ -90,7 +92,7 @@ set_compile_opts() { PKG_CFG_FLAGS='--static' LIB_SUFF='a' else - LDFLAGS+=("-Wl,-rpath,${LIBDIR}") + LDFLAGS+=("-Wl,-rpath,${LIBDIR}" "-Wl,-rpath-link,${LIBDIR}") CONFIGURE_FLAGS+=('--enable-shared') CMAKE_FLAGS+=("-DBUILD_SHARED_LIBS=ON") CMAKE_FLAGS+=("-DCMAKE_INSTALL_RPATH=${LIBDIR}") @@ -321,11 +323,11 @@ FB_FUNC_NAMES+=('build') # shellcheck disable=SC2034 FB_FUNC_DESCS['build']='build ffmpeg with desired configuration' build() { - test -d "${DL_DIR}" || mkdir -p "${DL_DIR}" - test -d "${CCACHE_DIR}" || mkdir -p "${CCACHE_DIR}" - test -d "${BUILD_DIR}" || mkdir -p "${BUILD_DIR}" - test -d "${PREFIX}/bin/" || mkdir -p "${PREFIX}/bin/" + test -d "${DL_DIR}" || { mkdir -p "${DL_DIR}" || return 1; } + test -d "${CCACHE_DIR}" || { mkdir -p "${CCACHE_DIR}" || return 1; } + test -d "${BUILD_DIR}" || { mkdir -p "${BUILD_DIR}" || return 1; } + set_compile_opts || return 1 # check if we need to install with sudo unset SUDO_MODIFY testfile="${PREFIX}/ffmpeg-build-testfile" @@ -333,14 +335,16 @@ build() { SUDO_MODIFY='' else SUDO_MODIFY="${SUDO}" - ${SUDO_MODIFY} mkdir -p "${PREFIX}/bin/" + ${SUDO_MODIFY} mkdir -p "${PREFIX}/bin/" || return 1 fi 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 # into ffmpeg with this variable 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 done do_build "ffmpeg" || return 1 @@ -423,8 +427,8 @@ build_libsvtav1() { ${SUDO_MODIFY} make -j"${JOBS}" install || return 1 } build_libsvtav1_psy() { - local hdr10pluslib="$(find "${PREFIX}" -type f -name "libhdr10plus-rs.${LIB_SUFF}")" - local dovilib="$(find "${PREFIX}" -type f -name "libdovi.${LIB_SUFF}")" + local hdr10pluslib="$(find -L "${PREFIX}" -type f -name "libhdr10plus-rs.${LIB_SUFF}")" + local dovilib="$(find -L "${PREFIX}" -type f -name "libdovi.${LIB_SUFF}")" cmake \ "${CMAKE_FLAGS[@]}" \ -DSVT_AV1_LTO="${LTO_SWITCH}" \ @@ -448,6 +452,16 @@ build_libaom() { ccache make -j"${JOBS}" || 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 ### build_libdav1d() { @@ -497,14 +511,6 @@ build_libvmaf() { } ### 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 # since most distros do not compile libc # with -fPIC for some reason @@ -580,7 +586,7 @@ add_project_versioning_to_ffmpeg() { return 0 } build_ffmpeg() { - for enable in "${FFMPEG_ENABLES[@]}"; do + for enable in ${FFMPEG_ENABLES}; do test "${enable}" == 'libsvtav1_psy' && enable='libsvtav1' CONFIGURE_FLAGS+=("--enable-${enable}") done diff --git a/lib/compile_opts.sh b/lib/compile_opts.sh index fdf38af..27bd7c9 100644 --- a/lib/compile_opts.sh +++ b/lib/compile_opts.sh @@ -3,26 +3,49 @@ # variables used externally # shellcheck disable=SC2034 +# default compile options + # clean build directories before building -CLEAN=true +DEFAULT_CLEAN=true # enable link time optimization -LTO=false +DEFAULT_LTO=true # optimization level (0-3) -OPT_LVL=0 +DEFAULT_OPT_LVL=3 # static or shared build -STATIC=true +DEFAULT_STATIC=true # CPU type (amd64/v{1,2,3}...) -CPU=native +DEFAULT_CPU=native # architecture type -ARCH=native -# prefix to install, leave empty for non-system install (local) -PREFIX='' +DEFAULT_ARCH=native +# prefix to install to, default is local install +DEFAULT_PREFIX='local' # configure what ffmpeg enables -FFMPEG_ENABLES=( - libopus - libdav1d - libsvtav1_psy - libaom - librav1e - libvmaf +DEFAULT_FFMPEG_ENABLES="\ +libsvtav1_psy \ +libopus \ +libdav1d \ +libaom \ +librav1e \ +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 +} diff --git a/lib/docker.sh b/lib/docker.sh index b9ca1aa..1df24cc 100644 --- a/lib/docker.sh +++ b/lib/docker.sh @@ -8,18 +8,29 @@ VALID_DOCKER_IMAGES=( 'archlinux-latest' ) DOCKER_WORKDIR='/workdir' -DOCKER_RUN_FLAGS=( - --rm - -v "${REPO_DIR}:${DOCKER_WORKDIR}" - -w "${DOCKER_WORKDIR}" - -e "DEBUG=${DEBUG}" -) + +set_docker_run_flags() { + DOCKER_RUN_FLAGS=( + --rm + -v "${REPO_DIR}:${REPO_DIR}" + -w "${REPO_DIR}" + -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() { if missing_cmd docker; then echo_info "install docker" curl https://get.docker.com -sSf | bash fi + set_docker_run_flags || return 1 } # change dash to colon for docker and add namespace @@ -82,34 +93,20 @@ docker_build_image() { echo_info "sourcing package manager for ${distro}" local dockerDistro="${distro}" # custom multi-arch image for archlinux - test "${distro}" == 'archlinux-latest' && \ + test "${distro}" == 'archlinux-latest' && dockerDistro='ogarcia/archlinux-latest' # docker expects colon instead of dash dockerDistro="${dockerDistro//-/:}" # specific file for evaluated package manager info distroPkgMgr="${DOCKER_DIR}/$(bash_basename "${distro}")-pkg_mgr" # 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_FLAGS[@]}" \ "${dockerDistro}" \ bash -c "./scripts/print_pkg_mgr.sh" | tr -d '\r' >"${distroPkgMgr}" # shellcheck disable=SC1090 cat "${distroPkgMgr}" + # shellcheck disable=SC1090 source "${distroPkgMgr}" dockerfile="${DOCKER_DIR}/Dockerfile_$(bash_basename "${distro}")" @@ -213,28 +210,6 @@ docker_run_image() { for distro in "${DISTROS[@]}"; do 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}")" # if a docker registry is defined, pull from it @@ -245,8 +220,7 @@ docker_run_image() { docker tag "${DOCKER_REGISTRY}/${image_tag}" "${image_tag}" fi - echo_info "running ffmpeg build for ${image_tag}" - + echo_info "running ffmpeg build with ${image_tag}" docker run \ "${DOCKER_RUN_FLAGS[@]}" \ -u "$(id -u):$(id -g)" \ diff --git a/main.sh b/main.sh index 03d2d9e..793d04d 100755 --- a/main.sh +++ b/main.sh @@ -38,7 +38,7 @@ src_scripts() { echo '#!/usr/bin/env bash cd "$(dirname "$(readlink -f $0)")/.." export FB_RUNNING_AS_SCRIPT=1 -. main.sh +. main.sh || return 1 scr_name="$(bash_basename $0)" cmd="${scr_name//.sh/}" if [[ $DEBUG == 1 ]]; then set -x; fi @@ -75,9 +75,7 @@ set_completions() { test -f "${HOME}/.bashrc" && source "${HOME}/.bashrc" src_scripts || return 1 determine_pkg_mgr || return 1 - -# shellcheck disable=SC2154 -test "${PREFIX}" == '' && PREFIX="${IGN_DIR}/$(print_os)_sysroot" +check_compile_opts_override || return if [[ $FB_RUNNING_AS_SCRIPT -eq 0 ]]; then print_cmds || return 1 diff --git a/scripts/entry.sh b/scripts/entry.sh index 99e5072..19d4ced 100755 --- a/scripts/entry.sh +++ b/scripts/entry.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash cd "$(dirname "$(readlink -f $0)")/.." export FB_RUNNING_AS_SCRIPT=1 -. main.sh +. main.sh || return 1 scr_name="$(bash_basename $0)" cmd="${scr_name//.sh/}" if [[ $DEBUG == 1 ]]; then set -x; fi