Recently we have been exploring the use of the a1 instance type in AWS EC2 as the performance is favorable to our workloads the cost makes this instance type very appealing. This instance type uses an ARM processor and therefor has the architecture of aarch64
. More information about the instance class can be found here.
One of the many vendors we use at FormAssembly to help deliver our product is Datadog. Their product is used for both log aggregation and their application performance monitoring (APM). Because FormAssembly is written in PHP, we need to rely on an extension in order to facilitate their APM tracing (https://github.com/DataDog/dd-trace-php). Unfortunately, at the time of writing, this package is not published by Datadog for the aarch64 architecture.
The process I eventually used to create an aarch64 rpm package which we could distribute to our servers was a little bit hacky and quite a bit interesting. I have provided feedback to Datadog to publish their own package, or to at least include a source RPM - but for the time being, this process will have to work.
Before starting you will need to be running on an aarch64 system that is rhel based. I used an Amazon EC2 a1 instance running Amazon Linux 2 (amzn2).
Download and install the source tarball for the release (https://github.com/DataDog/dd-trace-php/releases/latest). Extract it, move into the directory and run the following:
You will likely need to install dependencies. I’m putting this together after the fact from a build attempt on a system with many build tools and libraries already installed so I will leave this as an exercise for the reader.
If everything was successful, you will be left with the php extension file ./modules/ddtrace.so
.
This can be found on the above github releases page. Rename it to reflect the aarch64 architecture, this is used later to help us trick rpmrebuild
into building us an aarch64 package. eg:
rpmrebuild
A simple yum install rpmrebuild
.
Once installed we will need to edit rpmrebuild
to further trick it into rebuilding an x86_64 rpm as an aarch64 rpm. Edit /usr/lib/rpmrebuild/rpmrebuild.sh
and find the function RpmArch
. This function finds out the architecture of the package we are rebuilding - add the following line before the return
to force the desired architecture:
This will open an editor and allow us to change the SPEC file of the package. We need to replace any instance of x86_64 with aarch64. This vim command will do it for you: :%s/x86.64/aarch64/
.
Next, still in the SPEC file, we need to remove all mentions of the existing php extensions, there are a bunch:
Delete all those and just insert this single line:
You can then write and quit editing the spec file (:wq
).
It will prompt you if you want to continue, you do.
This will drop you back into a shell, and give us a chance to load in our compiled extension from step one. You will find a temporary directory within /root/
that looks like /root/.tmp/rpmrebuild.23012
. That is where we can load our extension.
Next, we need to exit the shell and it is very important we return a 0 so that rpmrebuild is happy:
At this point, rpmrebuild will actually build the package and it should say something like this:
Test the package, make sure it works as expected.