From c2a937f830674e70d079b3954b59bb98c3bfa67b Mon Sep 17 00:00:00 2001 From: Guillaume Quintard Date: Tue, 10 Feb 2026 08:42:30 -0800 Subject: [PATCH] Expose VARNISH_{STATE_DIR,DEFAULT_REL_NAME} in installed headers Varnish has a lot of runtime dependencies, mainly because of the C compiler, and this is an obstacle for VSM tools trying to reduce the size of their container images. Exposing `VARNISH_{STATE_DIR,DEFAULT_REL_NAME}` in a new header allows languages such has `go` and `rust` to discover the default workdir at compile-time, and skip the runtime dependency on `varnish` Co-authored-by: GitHub Copilot --- configure.ac | 5 ++++ include/Makefile.am | 1 + include/vapi/workdir.h.in | 49 +++++++++++++++++++++++++++++++++++ lib/libvarnish/Makefile.am | 1 - lib/libvarnish/vin.c | 2 +- lib/libvarnishapi/Makefile.am | 3 --- 6 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 include/vapi/workdir.h.in diff --git a/configure.ac b/configure.ac index 2483dfeac2b..c1b782470d0 100644 --- a/configure.ac +++ b/configure.ac @@ -647,6 +647,10 @@ else fi AC_SUBST(VARNISH_STATE_DIR) +# Default relative name for working directory +VARNISH_DEFAULT_REL_NAME='varnishd' +AC_SUBST(VARNISH_DEFAULT_REL_NAME) + # Default configuration directory. pkgsysconfdir='${sysconfdir}/varnish' AC_SUBST(pkgsysconfdir) @@ -931,6 +935,7 @@ AC_CONFIG_FILES([ doc/sphinx/conf.py etc/Makefile include/Makefile + include/vapi/workdir.h lib/Makefile lib/libvsc/Makefile lib/libvarnish/Makefile diff --git a/include/Makefile.am b/include/Makefile.am index ef4328f189d..2c0ee0c32e0 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -56,6 +56,7 @@ nobase_pkginclude_HEADERS = \ vapi/vsm.h \ vapi/voptget.h \ vapi/vapi_options.h \ + vapi/workdir.h \ vcli.h \ vut.h \ vut_options.h diff --git a/include/vapi/workdir.h.in b/include/vapi/workdir.h.in new file mode 100644 index 00000000000..3faf7c2439d --- /dev/null +++ b/include/vapi/workdir.h.in @@ -0,0 +1,49 @@ +/*- + * Copyright (c) 2026 Varnish Software AS + * All rights reserved. + * + * Author: Guillaume Quintard + * + * SPDX-License-Identifier: BSD-2-Clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Varnish working directory paths + */ + +/** + * VARNISH_STATE_DIR - Default state directory + * + * The default directory where Varnish stores runtime state files. + * This is configured at build time and typically points to /var/run + * or ${localstatedir}/varnish depending on the installation. + */ +#define VARNISH_STATE_DIR "@VARNISH_STATE_DIR@" + +/** + * VARNISH_DEFAULT_REL_NAME - Default relative name + * + * The default relative name used for Varnish instance directories. + * This is used as the default -n argument when constructing working + * directory paths. + */ +#define VARNISH_DEFAULT_REL_NAME "@VARNISH_DEFAULT_REL_NAME@" \ No newline at end of file diff --git a/lib/libvarnish/Makefile.am b/lib/libvarnish/Makefile.am index 22109111070..f26f0f1a4ac 100644 --- a/lib/libvarnish/Makefile.am +++ b/lib/libvarnish/Makefile.am @@ -11,7 +11,6 @@ AM_LDFLAGS = $(AM_LT_LDFLAGS) noinst_LTLIBRARIES = libvarnish.la libvarnish_la_CFLAGS = \ - -DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"' \ $(AM_CFLAGS) libvarnish_la_SOURCES = \ diff --git a/lib/libvarnish/vin.c b/lib/libvarnish/vin.c index 496684844dd..e607e203f8f 100644 --- a/lib/libvarnish/vin.c +++ b/lib/libvarnish/vin.c @@ -42,7 +42,7 @@ #include "vin.h" #include "vsb.h" -#define VARNISH_DEFAULT_REL_NAME "varnishd" +#include "vapi/workdir.h" char * VIN_n_Arg(const char *n_arg) diff --git a/lib/libvarnishapi/Makefile.am b/lib/libvarnishapi/Makefile.am index b278eb6d99f..9805167f770 100644 --- a/lib/libvarnishapi/Makefile.am +++ b/lib/libvarnishapi/Makefile.am @@ -34,9 +34,6 @@ if ! HAVE_DAEMON libvarnishapi_la_SOURCES += daemon.c endif -libvarnishapi_la_CFLAGS = \ - -DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"' - libvarnishapi_la_LIBADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ ${NET_LIBS} ${RT_LIBS} ${LIBM}