1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-09-16 09:06:18 +02:00

Make meson the primary build system.

Meson has a lot of advantages over autoconf/make, primarily in ease-of-use and performance. Make meson the only build system used for testing and building the Debian documentation, but leave the RHEL documentation using autoconf/make for now so it gets some testing.
This commit is contained in:
David Steele
2024-03-10 10:53:31 +13:00
committed by GitHub
parent c64cd8e019
commit e3d9df3ae9
11 changed files with 78 additions and 135 deletions

View File

@@ -127,7 +127,7 @@ jobs:
- name: Build
run: |
meson setup --unity=on -Dforce-release=true -Dwerror=true build ${GITHUB_WORKSPACE?}/pgbackrest
meson setup --unity=on -Dwerror=true build ${GITHUB_WORKSPACE?}/pgbackrest
ninja -vC build
- name: Check

View File

@@ -1,10 +1,3 @@
####################################################################################################################################
# Error on release builds since we do not want anyone using meson for production yet
####################################################################################################################################
if not get_option('force-release') and get_option('buildtype') != 'debug' and get_option('buildtype') != 'debugoptimized'
error('meson is currently not supported for release builds')
endif
####################################################################################################################################
# Write configuration
####################################################################################################################################

View File

@@ -1,5 +1,9 @@
<release date="XXXX-XX-XX" version="2.51dev" title="UNDER DEVELOPMENT">
<release-core-list>
<text>
<p><b>NOTE TO PACKAGERS</b>: The build system for <backrest/> is now <proper>meson</proper>. The <proper>autoconf</proper>/<proper>make</proper> build will not receive any new features and will be removed after a few releases.</p>
</text>
<release-bug-list>
<release-item>
<github-issue id="2271"/>
@@ -30,6 +34,17 @@
</release-bug-list>
<release-improvement-list>
<release-item>
<github-pull-request id="2264"/>
<release-item-contributor-list>
<release-item-contributor id="david.steele"/>
<release-item-reviewer id="stephen.frost"/>
</release-item-contributor-list>
<p>Make meson the primary build system.</p>
</release-item>
<release-item>
<github-pull-request id="2257"/>

View File

@@ -62,6 +62,7 @@
<!-- Path where builds are performed -->
<variable key="build-path">/build</variable>
<variable key="build-br-path">{[build-path]}/pgbackrest-release-{[version]}</variable>
<variable key="build-meson-path">{[build-path]}/pgbackrest</variable>
<!-- PostreSQL versions to run documentation for and min/max versions represented -->
<variable key="pg-version" if="{[os-type-is-debian]}">{[os-debian-pg-version]}</variable>
@@ -581,7 +582,11 @@
<execute-list host="{[br-install-host]}">
<title>Copy <backrest/> binary from build host</title>
<execute user="root">
<execute if="{[os-type-is-debian]}" user="root">
<exe-cmd>scp {[host-build]}:{[build-meson-path]}/src/pgbackrest /usr/bin</exe-cmd>
<exe-cmd-extra>2>&amp;1</exe-cmd-extra>
</execute>
<execute if="{[os-type-is-rhel]}" user="root">
<exe-cmd>scp {[host-build]}:{[build-br-path]}/src/pgbackrest /usr/bin</exe-cmd>
<exe-cmd-extra>2>&amp;1</exe-cmd-extra>
</execute>
@@ -985,6 +990,10 @@
<p>When building from source it is best to use a build host rather than building on production. Many of the tools required for the build should generally not be installed in production. <backrest/> consists of a single executable so it is easy to copy to a new host once it is built.</p>
<p if="{[os-type-is-rhel]}">The preferred build method is <proper>meson</proper>/<proper>ninja</proper>, see <link url="user-guide.html#build">Build</link>. The <proper>autoconf</proper>/<proper>make</proper> method is shown here for legacy purposes.</p>
<p if="{[os-type-is-debian]}">The preferred build method is <proper>meson</proper>/<proper>ninja</proper> as shown below. The <proper>autoconf</proper>/<proper>make</proper> method is also provided for legacy purposes, see <link url="user-guide-rhel.html#build">Build</link>.</p>
<execute-list host="{[host-build]}">
<title>Download version <id>{[version]}</id> of <backrest/> to <path>{[build-path]}</path> path</title>
@@ -1006,10 +1015,10 @@
<exe-cmd>mkdir -p {[build-br-path]}</exe-cmd>
</execute>
<execute user="root" show="n">
<exe-cmd>cp -r {[pgbackrest-repo-path]}/src {[build-br-path]}</exe-cmd>
<exe-cmd>cp -r {[pgbackrest-repo-path]}/* {[build-br-path]}</exe-cmd>
</execute>
<execute user="root" show="n">
<exe-cmd>chown -R {[host-build-user]} {[build-br-path]}</exe-cmd>
<exe-cmd>chown -R {[host-build-user]} {[build-path]}</exe-cmd>
</execute>
</execute-list>
@@ -1022,7 +1031,7 @@
<execute if="{[os-type-is-debian]}" user="root" pre="y">
<exe-cmd>
apt-get install make gcc libpq-dev libssl-dev libxml2-dev pkg-config
apt-get install meson gcc libpq-dev libssl-dev libxml2-dev pkg-config
liblz4-dev libzstd-dev libbz2-dev libz-dev libyaml-dev libssh2-1-dev
</exe-cmd>
<exe-cmd-extra>-y 2>&amp;1</exe-cmd-extra>
@@ -1037,7 +1046,18 @@
</execute>
</execute-list>
<execute-list host="{[host-build]}">
<execute-list if="{[os-type-is-debian]}" host="{[host-build]}">
<title>Configure and compile <backrest/></title>
<execute>
<exe-cmd>meson setup {[build-meson-path]} {[build-br-path]}</exe-cmd>
</execute>
<execute>
<exe-cmd>ninja -C {[build-meson-path]}</exe-cmd>
</execute>
</execute-list>
<execute-list if="{[os-type-is-rhel]}" host="{[host-build]}">
<title>Configure and compile <backrest/></title>
<execute>
@@ -3746,9 +3766,11 @@
To initialize the build, run the following. This only needs to be done once per doc build or branch change, though running it more that once only costs additional time:
docker exec -it doc-build bash -c 'rm -rf /build/dev && mkdir -p /build/dev && cd /build/dev && /pgbackrest/src/configure -\-enable-test'
docker exec -it doc-build bash -c 'rm -rf /build/dev && meson setup -Dbuildtype=debug /build/dev /pgbackrest'
One each host where a new build is required, run the following. This will build pgbackrest, copy it to the host, and display the build time for sanity:
docker exec -it <container> bash -c 'ssh build make -C /build/dev -j 8 && scp build:/build/dev/pgbackrest /usr/bin && ls -lah /usr/bin/pgbackrest'
docker exec -it <container> bash -c 'ssh build ninja -C /build/dev && scp build:/build/dev/src/pgbackrest /usr/bin && ls -lah /usr/bin/pgbackrest'
============================================================================================================================ -->
<section id="stress" if="'{[stress]}' eq 'y'">
<title>Stress Testing</title>

View File

@@ -1,3 +1,2 @@
option('configdir', type: 'string', value: '/etc/pgbackrest', description: 'Configuration directory')
option('fatal-errors', type: 'boolean', value: false, description: 'Stop compilation on first error')
option('force-release', type: 'boolean', value: false, description: 'Force a release build (for testing only!)')

View File

@@ -182,8 +182,8 @@ eval
{
# Build list of packages that need to be installed
my $strPackage =
"make gcc ccache python3-pip git rsync zlib1g-dev libssl-dev libxml2-dev libpq-dev libyaml-dev pkg-config" .
" uncrustify libssh2-1-dev valgrind";
"gcc ccache python3-pip git rsync zlib1g-dev libssl-dev libxml2-dev libpq-dev libyaml-dev pkg-config uncrustify" .
" libssh2-1-dev valgrind";
# Add lcov when testing coverage
if (vmCoverageC($strVm))

View File

@@ -205,7 +205,6 @@ sub run
{
if ($self->{oTest}->{&TEST_VM} ne VM_NONE)
{
my $strBinPath = $self->{strTestPath} . '/bin/' . $self->{oTest}->{&TEST_VM} . '/' . PROJECT_EXE;
my $strBuildPath = $self->{strTestPath} . '/build/' . $self->{oTest}->{&TEST_VM};
executeTest(
@@ -215,7 +214,6 @@ sub run
($self->{oTest}->{&TEST_C} ? " -v $self->{strDataPath}:$self->{strDataPath}" : '') .
" -v $self->{strBackRestBase}:$self->{strBackRestBase}" .
" -v $self->{strRepoPath}:$self->{strRepoPath}" .
($self->{oTest}->{&TEST_BIN_REQ} ? " -v ${strBinPath}:${strBinPath}:ro" : '') .
($self->{oTest}->{&TEST_C} ? " -v ${strBuildPath}:${strBuildPath}:ro" : '') .
($self->{oTest}->{&TEST_C} ? " -v ${strCCachePath}:/home/${\TEST_USER}/.ccache" : '') .
' ' . containerRepo() . ':' . $self->{oTest}->{&TEST_VM} . '-test',

View File

@@ -647,12 +647,9 @@ testBldUnit(TestBuild *const this)
strReplace(testC, STRDEF("{[C_HRN_PATH_REPO]}"), pathRepo);
// Path to the project exe when it exists
const String *const pathProjectExe = storagePathP(
testBldStorageTest(this),
strNewFmt(
"%s/%s%s/" PROJECT_BIN, strEqZ(testBldVmInt(this), "none") ? "build" : "bin", strZ(testBldVmInt(this)),
strEqZ(testBldVmInt(this), "none") ? "/src" : ""));
strReplace(testC, STRDEF("{[C_TEST_PROJECT_EXE]}"), pathProjectExe);
strReplace(
testC, STRDEF("{[C_TEST_PROJECT_EXE]}"),
storagePathP(testBldStorageTest(this), strNewFmt("build/%s/src/" PROJECT_BIN, strZ(testBldVmInt(this)))));
// Path to source -- used to construct __FILENAME__ tests
strReplace(testC, STRDEF("{[C_TEST_PGB_PATH]}"), strNewFmt("../%s", strZ(pathRepoRel)));

View File

@@ -1,10 +1,3 @@
####################################################################################################################################
# Error on release builds since we do not want anyone using meson for production yet
####################################################################################################################################
if not get_option('force-release') and get_option('buildtype') != 'debug' and get_option('buildtype') != 'debugoptimized'
error('meson is currently not supported for release builds')
endif
####################################################################################################################################
# Write configuration
####################################################################################################################################

View File

@@ -682,7 +682,7 @@ testRun(void)
strReplace(testCDup, STRDEF("{[C_TEST_DEBUG_TEST_TRACE]}"), STRDEF("// Debug test trace not enabled"));
strReplace(testCDup, STRDEF("{[C_TEST_PATH_BUILD]}"), STRDEF(TEST_PATH "/test/unit-3/uXX/build"));
strReplace(testCDup, STRDEF("{[C_TEST_PROFILE]}"), STRDEF("true"));
strReplace(testCDup, STRDEF("{[C_TEST_PROJECT_EXE]}"), STRDEF(TEST_PATH "/test/bin/uXX/pgbackrest"));
strReplace(testCDup, STRDEF("{[C_TEST_PROJECT_EXE]}"), STRDEF(TEST_PATH "/test/build/uXX/src/pgbackrest"));
strReplace(testCDup, STRDEF("{[C_TEST_TZ]}"), STRDEF("// No timezone specified"));
strReplace(
@@ -847,7 +847,7 @@ testRun(void)
strReplace(testCDup, STRDEF("{[C_TEST_DEBUG_TEST_TRACE]}"), STRDEF("// Debug test trace not enabled"));
strReplace(testCDup, STRDEF("{[C_TEST_PATH_BUILD]}"), STRDEF(TEST_PATH "/test/unit-3/none/build"));
strReplace(testCDup, STRDEF("{[C_TEST_PROFILE]}"), STRDEF("true"));
strReplace(testCDup, STRDEF("{[C_TEST_PROJECT_EXE]}"), STRDEF(TEST_PATH "/test/bin/uXX/pgbackrest"));
strReplace(testCDup, STRDEF("{[C_TEST_PROJECT_EXE]}"), STRDEF(TEST_PATH "/test/build/uXX/src/pgbackrest"));
strReplace(testCDup, STRDEF("{[C_TEST_TZ]}"), STRDEF("setenv(\"TZ\", \"America/New_York\", true);"));
strReplace(testCDup, STRDEF("{[C_INCLUDE]}"), STRDEF(""));
@@ -1005,7 +1005,7 @@ testRun(void)
strReplace(testCDup, STRDEF("{[C_TEST_DEBUG_TEST_TRACE]}"), STRDEF("// Debug test trace not enabled"));
strReplace(testCDup, STRDEF("{[C_TEST_PATH_BUILD]}"), STRDEF(TEST_PATH "/test/unit-3/uXX/build"));
strReplace(testCDup, STRDEF("{[C_TEST_PROFILE]}"), STRDEF("true"));
strReplace(testCDup, STRDEF("{[C_TEST_PROJECT_EXE]}"), STRDEF(TEST_PATH "/test/bin/uXX/pgbackrest"));
strReplace(testCDup, STRDEF("{[C_TEST_PROJECT_EXE]}"), STRDEF(TEST_PATH "/test/build/uXX/src/pgbackrest"));
strReplace(testCDup, STRDEF("{[C_TEST_TZ]}"), STRDEF("setenv(\"TZ\", \"America/New_York\", true);"));
strReplace(testCDup, STRDEF("{[C_INCLUDE]}"), STRDEF(""));
@@ -1047,7 +1047,7 @@ testRun(void)
strReplace(testCDup, STRDEF("{[C_TEST_DEBUG_TEST_TRACE]}"), STRDEF("// Debug test trace not enabled"));
strReplace(testCDup, STRDEF("{[C_TEST_PATH_BUILD]}"), STRDEF(TEST_PATH "/test/unit-3/uXX/build"));
strReplace(testCDup, STRDEF("{[C_TEST_PROFILE]}"), STRDEF("false"));
strReplace(testCDup, STRDEF("{[C_TEST_PROJECT_EXE]}"), STRDEF(TEST_PATH "/test/bin/uXX/pgbackrest"));
strReplace(testCDup, STRDEF("{[C_TEST_PROJECT_EXE]}"), STRDEF(TEST_PATH "/test/build/uXX/src/pgbackrest"));
strReplace(testCDup, STRDEF("{[C_TEST_TZ]}"), STRDEF("setenv(\"TZ\", \"America/New_York\", true);"));
strReplace(testCDup, STRDEF("{[C_INCLUDE]}"), STRDEF(""));

View File

@@ -383,10 +383,6 @@ eval
################################################################################################################################
# Start VM and run
################################################################################################################################
# Clean any existing files in the src path that might interfere with the vpath build. This is kosher because the user should
# be expecting us to do builds in the src path during testing. Instead we clean the src path and do the builds elsewhere.
#-------------------------------------------------------------------------------------------------------------------------------
executeTest("make -C ${strBackRestBase}/src -f Makefile.in clean-all");
# Clean up
#-------------------------------------------------------------------------------------------------------------------------------
@@ -575,7 +571,7 @@ eval
# Auto-generate code files (if --min-gen specified then do minimum required)
#-------------------------------------------------------------------------------------------------------------------------------
my $strBuildPath = "${strTestPath}/build/${strVm}";
my $strBuildPath = "${strTestPath}/build/none";
my $strBuildNinja = "${strBuildPath}/build.ninja";
&log(INFO, (!-e $strBuildNinja ? 'clean ' : '') . 'autogenerate code');
@@ -596,9 +592,7 @@ eval
}
# Build code
executeTest(
($strVm ne VM_NONE ? "docker exec -i -u ${\TEST_USER} test-build bash -l -c ' \\\n" : '') .
$strGenerateCommand . ($strVm ne VM_NONE ? "'" : ''));
executeTest($strGenerateCommand);
if ($bGenOnly)
{
@@ -690,7 +684,7 @@ eval
#-------------------------------------------------------------------------------------------------------------------------------
my $oyTestRun;
my $bBinRequired = $bBuildOnly;
my $bIntegrationRequired = $bBuildOnly;
my $bUnitRequired = $bBuildOnly;
# Only get the test list when they can run
if (!$bBuildOnly)
@@ -700,82 +694,53 @@ eval
$strVm, \@stryModule, \@stryModuleTest, \@iyModuleTestRun, $strPgVersion, $bCoverageOnly, $bCOnly, $bContainerOnly,
$bNoPerformance);
# Determine if the C binary and test library need to be built
# Determine if the C binary needs to be built
foreach my $hTest (@{$oyTestRun})
{
# Bin build required for all Perl tests or if a C unit test calls Perl
# Unit build required for unit tests
if ($hTest->{&TEST_C})
{
$bUnitRequired = true;
}
# Bin build required for integration tests and when specified
if (!$hTest->{&TEST_C} || $hTest->{&TEST_BIN_REQ})
{
$bBinRequired = true;
}
# Host bin required if an integration test
if (!$hTest->{&TEST_C})
{
$bIntegrationRequired = true;
}
}
}
my $strBuildRequired;
if ($bBinRequired || $bIntegrationRequired)
{
if ($bBinRequired)
{
$strBuildRequired = "bin";
}
if ($bIntegrationRequired)
{
$strBuildRequired .= ", integration";
}
}
else
{
$strBuildRequired = "none";
}
&log(INFO, "builds required: ${strBuildRequired}");
# Build the binary and packages
#-------------------------------------------------------------------------------------------------------------------------------
if (!$bDryRun)
{
my $oVm = vmGet();
my $lTimestampLast;
my $rhBinBuild = {};
# Build the binary
#-----------------------------------------------------------------------------------------------------------------------
if ($bBinRequired)
#---------------------------------------------------------------------------------------------------------------------------
if ($bBinRequired || $bUnitRequired)
{
# Find the lastest modified time for dirs that affect the bin build
$lTimestampLast = buildLastModTime($oStorageBackRest, $strBackRestBase, ['src']);
# Loop through VMs to do the C bin builds
# Loop through VMs to do the C bin/integration builds
my $bLogDetail = $strLogLevel eq 'detail';
my @stryBuildVm = $strVm eq VM_ALL ? VM_LIST : ($strVm);
# Build binary for the host
if ($bIntegrationRequired)
{
push(@stryBuildVm, VM_NONE);
}
foreach my $strBuildVM (@stryBuildVm)
{
if ($strBuildVM eq VM_NONE)
my $strBuildPath = "${strTestPath}/build/${strBuildVM}";
my $strBuildNinja = "${strBuildPath}/build.ninja";
foreach my $strBuildVM (@stryBuildVm)
{
my $strBuildPath = "${strTestPath}/build/${strBuildVM}";
my $strBuildNinja = "${strBuildPath}/build.ninja";
&log(
INFO,
" " . (!-e $strBuildNinja ? 'clean ' : '') . "integration build for ${strBuildVM} (${strBuildPath})");
&log(INFO, (!-e $strBuildNinja ? 'clean ' : '') . "build for ${strBuildVM} (${strBuildPath})");
# Setup build if it does not exist
my $strBuildCommand = "ninja -C ${strBuildPath} test/src/test-pgbackrest src/pgbackrest";
my $strBuildCommand =
"ninja -C ${strBuildPath}" . ($bBinRequired ? ' src/pgbackrest' : '') .
($bUnitRequired ? ' test/src/test-pgbackrest' : '');
if (!-e $strBuildNinja)
{
@@ -786,62 +751,23 @@ eval
}
# Build code
executeTest($strBuildCommand);
}
else
{
my $strBinPath = "${strTestPath}/bin";
my $strBuildPath = "${strBinPath}/${strBuildVM}";
&log(INFO, " bin build for ${strBuildVM} (${strBuildPath})");
my $bRebuild = false;
$rhBinBuild->{$strBuildVM} = false;
# Build configure/compile options and see if they have changed from the previous build
my $strCFlags = ($bDebugTestTrace ? ' -DDEBUG_TEST_TRACE' : '');
my $strConfigOptions = (vmDebugIntegration($strBuildVM) ? ' --enable-test' : '');
my $strBuildFlags = "CFLAGS_EXTRA=${strCFlags}\nCONFIGURE=${strConfigOptions}";
my $strBuildFlagFile = "${strBinPath}/${strBuildVM}/build.flags";
my $bBuildOptionsDiffer = buildPutDiffers($oStorageBackRest, $strBuildFlagFile, $strBuildFlags);
if ($bBuildOptionsDiffer ||
!-e "${strBuildPath}/Makefile" ||
stat("${strBackRestBase}/src/Makefile.in")->mtime > stat("${strBuildPath}/Makefile")->mtime ||
stat("${strBackRestBase}/src/configure")->mtime > stat("${strBuildPath}/Makefile")->mtime ||
stat("${strBackRestBase}/src/build.auto.h.in")->mtime > stat("${strBuildPath}/Makefile")->mtime)
{
&log(INFO, ' bin dependencies have changed, rebuilding');
# Remove old path if it exists and save the build flags
executeTest("rm -rf ${strBuildPath}");
buildPutDiffers($oStorageBackRest, $strBuildFlagFile, $strBuildFlags);
executeTest(
'docker exec -i -u ' . TEST_USER . ' test-build ' .
"bash -c 'cd ${strBuildPath} && ${strBackRestBase}/src/configure -q${strConfigOptions}'",
{bShowOutputAsync => $bLogDetail});
}
executeTest(
'docker exec -i -u ' . TEST_USER . ' test-build ' .
"${strMakeCmd} -s -j ${iBuildMax}" . ($bLogDetail ? '' : ' --silent') .
" --directory ${strBuildPath} CFLAGS_EXTRA='${strCFlags}'",
($strBuildVM ne VM_NONE ? 'docker exec -i -u ' . TEST_USER . " test-build bash -c '" : '') .
$strBuildCommand . ($strBuildVM ne VM_NONE ? "'" : ''),
{bShowOutputAsync => $bLogDetail});
}
}
}
# Shut down the build vm
#-----------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------------------------------
if ($strVm ne VM_NONE)
{
executeTest("docker rm -f test-build");
}
# Build the package
#-----------------------------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------------------------------
if ($bBuildPackage && $strVm ne VM_NONE)
{
my $strPackagePath = "${strBackRestBase}/test/result/package";