5

How to Build Percona Server for MySQL From Sources

 3 years ago
source link: https://www.percona.com/blog/2021/03/10/how-to-build-percona-server-for-mysql-from-sources/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to Build Percona Server for MySQL From Sources

Build Percona Server for MySQL From SourcesLately, the number of questions about how to build Percona software has been increased. More and more people try to add their own patches, add some modifications, and build software by themselves. But this raises the question of how to do this in the same way as Percona does, as sometimes the compiler flag can make a drastic impact on the final binary.

First of all, let’s talk about the stages of compiling software.

I would say that at the beginning you need to prepare the build environment, install all the needed dependencies, and so on. For each version, the dependency list would be different. How do you get the correct dependency list? You can get all build requirements from the spec file (on rpm-based systems) or from the control file( on deb-based systems).

The next stage is to get the source code of Percona Server for MySQL. You can do it in different ways:

  • Get source tarball from the website

We publish source tarball for each release we issue and you can easily get it for any released version (this is the link for the latest 8.0.22 version).

  • Download tarball from GitHub

Here is the link: https://github.com/percona/percona-server/releases/tag/Percona-Server-8.0.22-13

Once you have prepared the build environment, you need to decide what result you should get: binary tarball, rpm, or deb package.

So everything looks easy. But what is the way we use, internally, to prepare our release packages? As I mentioned earlier, each compiler option can make a significant effect.

Everyone tries to make life easier and automate all tasks. It is great, as automation is one of the keys to success as you can work on other tasks once the release build is in progress. So we have created a builder script that is used for making builds. It can be found in the Percona Server GitHub repo and can be used by anyone to make his own builds.

Have open source expertise to share? Submit your talk for Percona Live ONLINE!

This script can install all needed dependencies for the build environment, create binary tarballs, source RPMs and debs, RPMs, debs itself, and the binary tarball. So it covers all build cycles. So how do you use it?

The script has various params:

Shell
        --builddir=DIR      Absolute path to the dir where all actions will be performed
        --get_sources       Source will be downloaded from github
        --build_src_rpm     If it is 1 src rpm will be built
        --build_source_deb  If it is 1 source deb package will be built
        --build_rpm         If it is 1 rpm will be built
        --build_deb         If it is 1 deb will be built
        --build_tarball     If it is 1 tarball will be built
        --install_deps      Install build dependencies(root privileges are required)
        --branch            Branch for build
        --repo              Repo for build
        --rpm_release       RPM version( default = 1)
        --deb_release       DEB version( default = 1)
        --debug             Build debug tarball

So let’s see how we can make the build process easier:

1. Download build script:

Shell
wget       https://raw.githubusercontent.com/percona/percona-server/8.0/build-ps/percona-server-8.0_builder.sh

2. Create a build directory where you are going to perform all build actions:

Shell
mkdir /tmp/BUILD_PS

3. Install dependencies(please note root permissions are required):

Shell
sudo ./percona-server-8.0_builder.sh --builddir=/tmp/BUILD_PS --install_deps=1

4. Download source code:

– From Percona repo (it is used by default):

Shell
./percona-server-8.0_builder.sh --builddir=/tmp/BUILD_PS --get_sources=1 --branch=Percona-Server-8.0.22-13

– From your own repo and branch:

Shell
./percona-server-8.0_builder.sh --builddir=/tmp/BUILD_PS --get_sources=1 --branch=<your_branch_name> --repo=<link_to_your_repo_on_github>

5. Prepare src rpm:

Shell
./percona-server-8.0_builder.sh --builddir=/tmp/BUILD_PS --build_src_rpm=1

Please note if you already have your source tarball, just create a directory named source_tarball in the build directory and put it into it.

6. Prepare source deb:

Shell
./percona-server-8.0_builder.sh --builddir=/tmp/BUILD_PS --build_source_deb=1

Please note if you already have your source tarball, just create a directory named source_tarball in the build directory and put it into it.

7. Prepare rpm:

Shell
./percona-server-8.0_builder.sh --builddir=/tmp/BUILD_PS --build_rpm=1

8. Prepare deb:

Shell
./percona-server-8.0_builder.sh --builddir=/tmp/BUILD_PS --build_deb=1

9. Prepare tarball:

Shell
./percona-server-8.0_builder.sh --builddir=/tmp/BUILD_PS --build_tarball=1

So as you can see, the build procedure becomes easier and you don’t need to think about what dependencies are needed, what cmake params should be used, etc. This build script will make everything for you and will use all build flags (if you didn’t change them in your sources) that we use for release builds.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK