Most of the servers I manage are 64-bit. I have one linode box that is 32-bit. I chose 32-bit because it has better memory usage than 64-bit, which is possibly important with a 512MB instance. This was probably a mistake as the management overhead involved with maintaining a 32-bit infrastructure for just one 32-bit machine is silly. No matter – we are where we are…!
I use the fnv_64 user-defined function from maatkit with MySQL. So, I need to build a 32-bit version for use on the 32-bit server.
Here's how to use mock to create a 32-bit build environment (in this case, for CentOS 5) on a 64-bit machine (the host is actually a Fedora 15 server).
The basic strategy as as follows:
- Initialise the environment
- Install any dependencies
- Copy in the code you want to build
- chroot into the build shell
- Build the code
- Exit the build shell
- Copy out the results of the build process
Here's what that looks like with mock:
mock -r epel-5-i386 --init mock -r epel-5-i386 --install mysql-devel mock -r epel-5-i386 --copyin fnv_udf.cc /fnv_udf.cc mock -r epel-5-i386 shell gcc -fPIC -Wall -I/usr/include/mysql -shared -o fnv_udf.so fnv_udf.cc exit mock -r epel-5-i386 --copyout /fnv_udf.so .