Skip to content

Commit b73b43c

Browse files
committed
Add optional static fbclient build
1 parent 0f3c70f commit b73b43c

22 files changed

Lines changed: 1965 additions & 267 deletions

.github/workflows/static-build.yml

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
name: Static Client Build
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
8+
build-linux-static-client:
9+
name: build-linux-static-client-${{ matrix.arch }}
10+
runs-on: ${{ (matrix.arch == 'arm64' && 'ubuntu-24.04-arm') || 'ubuntu-24.04' }}
11+
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
arch: [x64, x86]
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 10
22+
23+
- name: Write build script
24+
run: |
25+
mkdir -p gen
26+
cat > /tmp/build-static-client.sh <<'EOF'
27+
#!/bin/sh
28+
set -e
29+
gcc -v
30+
ld -v
31+
make -v
32+
cd /home/ctng/firebird-build
33+
/firebird/autogen.sh \
34+
--host=$BUILD_ARCH \
35+
--prefix=/opt/firebird \
36+
--enable-binreloc \
37+
--with-builtin-tomcrypt \
38+
--with-termlib=:libncurses.a \
39+
--with-atomiclib=:libatomic.a \
40+
--enable-client-only
41+
make client_static -j$(nproc)
42+
# CXX lives in gen/make.defaults (substituted by configure). The
43+
# top-level Makefile only forwards targets to gen/ and has no CXX=.
44+
CXX=$(sed -n 's/^[[:space:]]*CXX[[:space:]]*=[[:space:]]*//p' gen/make.defaults | head -n 1)
45+
if test -z "$CXX"; then
46+
echo "error: could not determine CXX from gen/make.defaults" >&2
47+
exit 1
48+
fi
49+
echo "Linking example with CXX=$CXX"
50+
"$CXX" /firebird/examples/interfaces/01.create.cpp \
51+
-I/firebird/src/include \
52+
-I/home/ctng/firebird-build/gen/Release/firebird/include \
53+
-L/home/ctng/firebird-build/gen/Release/firebird/lib \
54+
-L/home/ctng/firebird-build/temp/Release \
55+
-lfbclient -ltommath -lz -ldl -pthread \
56+
-o /tmp/01.create
57+
EOF
58+
chmod +x /tmp/build-static-client.sh
59+
60+
- name: Build
61+
run: |
62+
docker run --platform ${{ (matrix.arch == 'x64' && 'amd64') || 'i386' }} --rm \
63+
-e CTNG_UID=$(id -u) -e CTNG_GID=$(id -g) \
64+
-v ${{ github.workspace }}:/firebird:ro \
65+
-v ${{ github.workspace }}/gen:/home/ctng/firebird-build/gen \
66+
-v /tmp/build-static-client.sh:/build.sh:ro \
67+
firebirdsql/firebird-builder-linux:fb6-${{ matrix.arch }}-ng-v2
68+
69+
- name: Upload static library
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: firebird-linux-${{ matrix.arch }}-static-client
73+
path: gen/Release/firebird/lib/libfbclient.a
74+
75+
build-linux-static-client-arm64:
76+
name: build-linux-static-client-arm64
77+
runs-on: ubuntu-24.04-arm
78+
79+
steps:
80+
- name: Checkout
81+
uses: actions/checkout@v4
82+
with:
83+
fetch-depth: 10
84+
85+
- name: Prepare
86+
run: |
87+
sudo apt-get update
88+
sudo apt-get install -y libtool-bin automake autoconf-archive libtool libicu-dev zlib1g-dev cmake
89+
90+
- name: Build
91+
run: |
92+
./autogen.sh \
93+
--with-builtin-tommath \
94+
--with-builtin-tomcrypt \
95+
--without-editline \
96+
--enable-binreloc \
97+
--prefix=/opt/firebird \
98+
--enable-client-only
99+
make client_static -j$(nproc)
100+
101+
- name: Compile and link interface example
102+
run: |
103+
g++ examples/interfaces/01.create.cpp \
104+
-Isrc/include \
105+
-Igen/Release/firebird/include \
106+
-Lgen/Release/firebird/lib \
107+
-Ltemp/Release \
108+
-lfbclient -ltommath -lz -ldl -pthread \
109+
-o /tmp/01.create
110+
111+
- name: Upload static library
112+
uses: actions/upload-artifact@v4
113+
with:
114+
name: firebird-linux-arm64-static-client
115+
path: gen/Release/firebird/lib/libfbclient.a
116+
117+
build-macos-static-client:
118+
name: build-macos-static-client-${{ matrix.arch }}
119+
runs-on: ${{ (matrix.arch == 'arm64' && 'macos-15') || 'macos-15-intel' }}
120+
121+
strategy:
122+
fail-fast: false
123+
matrix:
124+
arch: [x64, arm64]
125+
126+
steps:
127+
- name: Checkout
128+
uses: actions/checkout@v4
129+
with:
130+
fetch-depth: 10
131+
submodules: 'true'
132+
133+
- name: Prepare - Install tools
134+
run: |
135+
brew install --quiet automake autoconf-archive libtool ninja llvm
136+
echo "${{ (matrix.arch == 'arm64' && '/opt/homebrew/opt/llvm/bin') || '/usr/local/opt/llvm/bin' }}" >> $GITHUB_PATH
137+
138+
- name: Restore vcpkg cache
139+
uses: actions/cache/restore@v4
140+
id: restore-vcpkg-cache
141+
with:
142+
path: ~/.cache/vcpkg/archives
143+
key: vcpkg-cache-${{ runner.os }}-${{ matrix.arch }}-staticclient-${{ hashFiles('vcpkg-custom/**', 'vcpkg.json', 'vcpkg-configuration.json') }}
144+
restore-keys: |
145+
vcpkg-cache-${{ runner.os }}-${{ matrix.arch }}-staticclient-
146+
vcpkg-cache-${{ runner.os }}-${{ matrix.arch }}-
147+
148+
- name: Build
149+
run: |
150+
export LIBTOOLIZE=glibtoolize
151+
export LIBTOOL=glibtool
152+
./autogen.sh --with-builtin-tommath --with-builtin-tomcrypt --enable-client-only
153+
make client_static -j4
154+
155+
- name: Compile and link interface example
156+
run: |
157+
clang++ examples/interfaces/01.create.cpp \
158+
-Isrc/include \
159+
-Igen/Release/firebird/include \
160+
-Lgen/Release/firebird/lib \
161+
-Ltemp/Release \
162+
-lfbclient -ltommath -lz \
163+
-liconv -lobjc -framework CoreFoundation -framework Foundation -framework Security \
164+
-o /tmp/01.create
165+
166+
- name: Upload static library
167+
uses: actions/upload-artifact@v4
168+
with:
169+
name: firebird-macos-${{ matrix.arch }}-static-client
170+
path: gen/Release/firebird/lib/libfbclient.a
171+
172+
- name: Save vcpkg cache
173+
uses: actions/cache/save@v4
174+
if: steps.restore-vcpkg-cache.outputs.cache-hit != 'true'
175+
with:
176+
path: ~/.cache/vcpkg/archives
177+
key: ${{ steps.restore-vcpkg-cache.outputs.cache-primary-key }}
178+
179+
build-windows-static-client:
180+
name: build-windows-static-client-${{ matrix.platform }}
181+
runs-on: ${{ (matrix.platform == 'arm64' && 'windows-11-arm') || 'windows-2025' }}
182+
env:
183+
VS_VERSION: ${{ (matrix.platform == 'arm64' && '2022') || '2026' }}
184+
185+
strategy:
186+
fail-fast: false
187+
matrix:
188+
platform: [x64, x86, arm64]
189+
190+
steps:
191+
- name: Checkout
192+
uses: actions/checkout@v4
193+
with:
194+
fetch-depth: 10
195+
196+
- name: Prepare
197+
shell: cmd
198+
run: |
199+
for /r %%i in (*.bat) do unix2dos "%%i"
200+
201+
- name: Prepare envs
202+
shell: cmd
203+
env:
204+
PLATFORM: ${{ matrix.platform }}
205+
run: |
206+
if "%PLATFORM%" == "x64" set FB_VS_ARCH=amd64
207+
if "%PLATFORM%" == "x64" set FB_PROCESSOR_ARCHITECTURE=AMD64
208+
if "%PLATFORM%" == "x86" set FB_VS_ARCH=x86
209+
if "%PLATFORM%" == "x86" set FB_PROCESSOR_ARCHITECTURE=x86
210+
if "%PLATFORM%" == "x86" set FB_LIBRARY_PLATFORM=Win32
211+
if "%PLATFORM%" == "arm64" set FB_VS_ARCH=arm64
212+
if "%PLATFORM%" == "arm64" set FB_PROCESSOR_ARCHITECTURE=ARM64
213+
if not "%PLATFORM%" == "x86" set FB_LIBRARY_PLATFORM=%PLATFORM%
214+
echo FB_VS_ARCH=%FB_VS_ARCH%>>%GITHUB_ENV%
215+
echo FB_PROCESSOR_ARCHITECTURE=%FB_PROCESSOR_ARCHITECTURE%>>%GITHUB_ENV%
216+
echo FB_LIBRARY_PLATFORM=%FB_LIBRARY_PLATFORM%>>%GITHUB_ENV%
217+
218+
- name: Build
219+
shell: cmd
220+
env:
221+
PLATFORM: ${{ matrix.platform }}
222+
VS_SCRIPT: C:\Program Files\Microsoft Visual Studio\${{ (matrix.platform == 'arm64' && '2022') || '18' }}\Enterprise\Common7\Tools\VsDevCmd.bat
223+
run: |
224+
call "%VS_SCRIPT%" -arch=%FB_VS_ARCH%
225+
set "PATH=%VSINSTALLDIR%VC\Tools\Llvm\x64\bin;%PATH%"
226+
cd builds\win32
227+
call run_all.bat CLIENT_ONLY=STATIC JUSTBUILD NOCLEAN
228+
229+
- name: Compile and link interface example
230+
shell: cmd
231+
env:
232+
PLATFORM: ${{ matrix.platform }}
233+
VS_SCRIPT: C:\Program Files\Microsoft Visual Studio\${{ (matrix.platform == 'arm64' && '2022') || '18' }}\Enterprise\Common7\Tools\VsDevCmd.bat
234+
run: |
235+
call "%VS_SCRIPT%" -arch=%FB_VS_ARCH%
236+
cl /nologo /EHsc /MD /Isrc\include /Ioutput_%FB_LIBRARY_PLATFORM%_release\include examples\interfaces\01.create.cpp output_%FB_LIBRARY_PLATFORM%_release\lib\fbclient_static_ms.lib extern\libtommath\lib\%FB_LIBRARY_PLATFORM%\Release\tommath.lib advapi32.lib bcrypt.lib legacy_stdio_definitions.lib mpr.lib ole32.lib psapi.lib shell32.lib user32.lib ws2_32.lib /Fe:%TEMP%\01.create.exe
237+
238+
- name: Upload static library
239+
uses: actions/upload-artifact@v4
240+
with:
241+
name: firebird-windows-${{ matrix.platform }}-static-client
242+
path: output_${{ env.FB_LIBRARY_PLATFORM }}_release\lib\fbclient_static_ms.lib

builds/posix/Makefile.in

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ endif
279279
#
280280

281281
%.vers: $(SRCDIR)/builds/posix/%.vers
282-
sh vers.sh $(firstword $@)
282+
cd $(dir $@) && sh vers.sh $(notdir $@)
283283

284284
export_lists: $(ALLVERS)
285285

@@ -501,6 +501,48 @@ $(LIBFIREBIRD_FULLNAME): $(YValve_Objects) $(Remote_Client_Objects) $(COMMON_LIB
501501
$(LINK_FIREBIRD) -o $@ $^ $(LINK_FIREBIRD_LIBS) $(call LIB_LINK_DARWIN_INSTALL_NAME,lib/libfbclient.$(SHRLIB_EXT))
502502

503503

504+
#___________________________________________________________________________
505+
# static client library (non-default, built on request with `make client_static`)
506+
# See doc/README.StaticClient.md for a detailed description of the static
507+
# client archive construction, symbol renaming, and archive slimming.
508+
#
509+
# client_static is meant to be usable as the very first target on a freshly
510+
# configured tree (i.e. without a prior full build), so - like
511+
# master_process above.
512+
#
513+
514+
.PHONY: client_static client_static_process
515+
516+
client_static:
517+
$(MAKE) TARGET?=$(DefaultTarget) client_static_process
518+
519+
client_static_process:
520+
mkdir -p $(ROOT)/src/include/gen
521+
ln -sf $(ROOT)/gen/autoconfig.auto $(ROOT)/src/include/gen/autoconfig.h
522+
$(MAKE) updateBuildNum
523+
$(MAKE) export_lists
524+
$(MAKE) external
525+
$(MAKE) updateCloopInterfaces
526+
$(MAKE) $(LIBFIREBIRD_STATIC)
527+
528+
STATIC_CLIENT_SLIM_STAGE = $(ROOT)/temp/static_client_stage
529+
STATIC_CLIENT_SLIM_CREF = $(ROOT)/temp/static_client_cref.txt
530+
STATIC_CLIENT_SLIM_PROBE = $(ROOT)/temp/static_client_probe.o
531+
532+
$(LIBFIREBIRD_STATIC): $(YValve_Objects) $(Remote_Client_Objects) $(Common_Objects) \
533+
| $(GEN_ROOT)/$(FIREBIRD_VERS)
534+
-$(RM) $@
535+
$(STATICLIB_LINK) $@ $^ $(ROOT)/temp/extern/decNumber/*.o
536+
$(SHELL) $(STATIC_CLIENT_SCRIPT) \
537+
--archive $(abspath $@) \
538+
--seeds-file $(GEN_ROOT)/$(FIREBIRD_VERS) \
539+
--stage $(STATIC_CLIENT_SLIM_STAGE) \
540+
--cref $(STATIC_CLIENT_SLIM_CREF) \
541+
--probe $(STATIC_CLIENT_SLIM_PROBE) \
542+
--objcopy $(OBJCOPY) \
543+
--slim-mode $(STATIC_CLIENT_SLIM_MODE)
544+
545+
504546
#___________________________________________________________________________
505547
# core part - jrd's engine
506548
#
@@ -963,6 +1005,7 @@ clean_makefiles:
9631005
$(RM) $(GEN_ROOT)/make*
9641006
-$(RM) $(GEN_ROOT)/darwin.defaults
9651007
-$(RM) $(GEN_ROOT)/vers.sh
1008+
-$(RM) $(GEN_ROOT)/static_client.sh
9661009
$(RM) `find $(GEN_ROOT)/install \( -type f -o -type l \) -print`
9671010
-$(RM) $(GEN_ROOT)/examples/Make*
9681011
$(RM) $(ROOT)/Makefile

builds/posix/darwin.defaults

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,15 @@ PLATFORM_FALLBACK=os/posix
3535
STATIC_CXX_SUPPORT = -lsupc++ $(GCCS) -lgcc_eh -lSystem
3636

3737
INLINE_EDIT_SED:= -i ""
38+
39+
# GNU objcopy cannot rewrite Mach-O object/archive files; llvm-objcopy can
40+
# (and supports --redefine-syms on Mach-O). Apple's own `nm` output is
41+
# compatible with the --defined-only/-g flags used by the comprehensive
42+
# symbol rename in the static client build.
43+
OBJCOPY = llvm-objcopy
44+
45+
# Mach-O slim step. vers.sh's platform_darwin output already emits symbols
46+
# with a leading underscore, and the seeds flow through the script's
47+
# symbol-token parser unchanged. The slim itself is driven by Apple ld64's
48+
# -Wl,-map output (parsed by the same sed regex as the GNU -Wl,--cref path).
49+
STATIC_CLIENT_SLIM_MODE = darwin

builds/posix/make.defaults

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,20 @@ CXX = @CXX@
196196
LD = @CXX@
197197
OBJCOPY = @OBJCOPY@
198198
READELF = @READELF@
199+
NM = nm
200+
201+
# Helper script that performs the archive slim step and the
202+
# objcopy symbol rename for the static client library
203+
# (see target client_static and $(LIBFIREBIRD_STATIC) in
204+
# builds/posix/Makefile.in). Generated by autoconf from
205+
# builds/posix/static_client.sh.in.
206+
STATIC_CLIENT_SCRIPT = $(GEN_ROOT)/static_client.sh
207+
208+
# Slim step variant passed to $(STATIC_CLIENT_SCRIPT). Default
209+
# "elf" uses GNU ld -Wl,--cref. Darwin overrides to "darwin"
210+
# in builds/posix/darwin.defaults, which routes through Apple
211+
# ld64's -Wl,-map output instead.
212+
STATIC_CLIENT_SLIM_MODE = elf
199213

200214
AC_CFLAGS = @CFLAGS@
201215
AC_CXXFLAGS = @CXXFLAGS@
@@ -256,6 +270,12 @@ LIBFIREBIRD_FULLNAME = $(LIB)/$(LibraryFullName)
256270
LIBFIREBIRD_SONAME = $(LIB)/$(LibraryBaseName)
257271
LIBFIREBIRD_BASENAME = $(LIB)/$(LibrarySoName)
258272

273+
# Optional, non-default static client library (see target client_static).
274+
# Global operator new/delete are renamed inside this archive, so linking it
275+
# does not override the host application's own global operators.
276+
LibraryStaticName=$(LibraryFileName).a
277+
LIBFIREBIRD_STATIC = $(LIB)/$(LibraryStaticName)
278+
259279
# The firebird engine library name
260280

261281
EngineFileName=libEngine${OdsVersion}

0 commit comments

Comments
 (0)