Skip to content

Commit

Permalink
Add documentation how the pre-build binaries for the native library a…
Browse files Browse the repository at this point in the history
…re build
  • Loading branch information
matthiasblaesing committed Mar 8, 2024
1 parent ac6d9a5 commit 16e036a
Show file tree
Hide file tree
Showing 2 changed files with 346 additions and 8 deletions.
228 changes: 228 additions & 0 deletions www/BuildingNativeLibraries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
# Building native libraries

The native library part of JNA needs to be rebuild when the embedded copy of
libffi is updated or the gluecode is updated/bugfixed.

## Supported build architectures and instructions

### Linux

The linux binaries are build in various debian and Ubuntu chroots. The setup
can be found her: https://github.com/matthiasblaesing/docker-jna-build

The build assumes, that the packages to be build are prepared using the
`prepare-build-libraries.sh` script, which exports zip files with the native
code for:

- Linux aarch64
- Linux arm hardfloat
- Linux arm softfloat
- Linux mips64el
- Linux ppc
- Linux ppc64le
- Linux riscv64
- Linux s390x
- Linux x86-64
- Linux x86

### AIX

The AIX binaries are build on cfarm (https://portal.cfarm.net/) for AIX ppc and
ppc64. Basis are the build packages generated by `prepare-build-libraries.sh`,
see the Linux section. The host is `cfarm111.cfarm.net`. The packages
autoconf (2.71), libtool (2.4.7) and m4 (1.4.19) are installed in the home
folder.

1. Copy the build packages for `aix-ppc` and `aix-ppc64` to the host using scp
`scp build-package-aix-ppc* user@cfarm111.cfarm.net:`
2. ssh to the host
3. Unzip the packages `for i in *.zip; do unzip $i; done`
4. Setup the environment:
```bash
# Ensure `gmake` is used
export MAKE=gmake
# Place local binaries on the path
export PATH=/home/$USER/local/bin:$PATH
# Ensure working ARFLAGS are used
export ARFLAGS='-X32_64 cru'
```
5. Build 32bit:
```bash
# Reference the 32bit JKD 6
export JAVA_HOME=/usr/java6
# Build
cd build-package-aix-ppc-7.0.1
bash build.sh
# Copy result
cp aix-ppc.jar ../
cd ..
```
6. Build 64bit:
```bash
# Reference the 64bit JKD 6
export JAVA_HOME=/usr/java7_64
# Build
cd build-package-aix-ppc64-7.0.1
bash build.sh
# Copy result
cp aix-ppc64.jar ../
cd ..
```
7. Cleanup: `rm -r build-package-aix-ppc-7.0.1 build-package-aix-ppc-7.0.1.zip build-package-aix-ppc64-7.0.1 build-package-aix-ppc64-7.0.1.zip`
8. Exit build system: `exit`
9. Copy binaries to local system `scp "user@cfarm111.cfarm.net:*.jar lib/native`

### Darwin / mac OS

Darwin binaries are build for x86-64bit and aarch64 on github using the
corresponding pipeline.

### Android

Android binaries are build using the Android NDK r12b for:

- Android aarch64
- Android armv7
- Android arm
- Android mips64
- Android mips
- Android x86-64
- Android x86

The documentation can be found in `AndroidDevelopmentEnvironment.md`.

### Solaris

Build on the opencsw buildfarm https://www.opencsw.org/.

1. Copy the build packages for `solaris` to the host using scp
`scp build-package-sunos-* user@login.opencsw.org:`
2. Login to the gateway system `ssh user@login.opencsw.org`
3. Unzip the packages `for i in *.zip; do unzip $i; done`
4. SSH to the sparc build system `ssh unstable11s`
5. Setup the environment:
```bash
# Ensure `gmake` is used
export MAKE=gmake
# Place local binaries on the path
export PATH=$HOME/local/bin:$PATH
6. Build 32bit:
```bash
# Reference the 32bit JKD 7
export JAVA_HOME=/opt/csw/java/jdk1.7.0_80
# Build
cd build-package-sunos-sparc-7.0.1/native/libffi
bash autogen.sh
./configure
cd ../..
bash build.sh
# Copy result
cp sunos-sparc.jar ../
cd ..
```
7. Build 64bit:
```bash
# Reference the 64bit JKD 7
export JAVA_HOME=/opt/csw/java/jdk1.8.0_201
# Build
cd build-package-sunos-sparcv9-7.0.1/native/libffi
bash autogen.sh
./configure
cd ../..
bash build.sh
# Copy result
cp sunos-sparcv9.jar ../
cd ..
```
8. Switch to the x86 build system:
```bash
logout
ssh unstable11x
```
9. Setup the environment:
```bash
# Ensure `gmake` is used
export MAKE=gmake
# Place local binaries on the path
export PATH=$HOME/local/bin:$PATH
10. Build 32bit:
```bash
# Reference the 32bit JKD 7
export JAVA_HOME=/opt/csw/java/jdk1.7.0_80
# Build
cd build-package-sunos-x86-7.0.1/native/libffi
bash autogen.sh
./configure
cd ../..
bash build.sh
# Copy result
cp sunos-x86.jar ../
cd ..
```
11. Build 64bit:
```bash
# Reference the 64bit JKD 7
export JAVA_HOME=/opt/csw/java/jdk1.8.0_201
# Build
cd build-package-sunos-x86-64-7.0.1/native/libffi
bash autogen.sh
./configure
cd ../..
bash build.sh
# Copy result
cp sunos-x86-64.jar ../
cd ..
```
12. Return to login system `logout`
13. Cleanup: `rm -r build-package-sunos-sparc-7.0.1 build-package-sunos-sparc-7.0.1.zip build-package-sunos-sparcv9-7.0.1 build-package-sunos-sparcv9-7.0.1.zip build-package-sunos-x86-64-7.0.1 build-package-sunos-x86-64-7.0.1.zip build-package-sunos-x86-7.0.1 build-package-sunos-x86-7.0.1.zip`
14. Exit build system: `exit`
14. Copy binaries to local system: `scp "user@login.opencsw.org:*.jar" lib/native/`

### Windows

Build on a native x86 64bit system. x86 32bit and x86 64bit are build natively,
windows aarch64 is crossbuild.

The documentation can be found in `WindowsDevelopmentEnvironment.md`.

### FreeBSD

Binaries are build natively in VM Images of FreeBSD 13.2 (see `FreeBSD.md`)

Builds are done for:

- aarch64
- x86
- x86-64

### Dragonfly BSD

Binaries are build natively in a 6.4.0 x86-64 VM installed from the ISO Image:

https://www.dragonflybsd.org/download/

```bash
rsync -av --exclude=.git USER@BUILD_HOST:src/jnalib/ jnalib/
chmod +x jnalib/native/libffi/configure jnalib/native/libffi/install-sh
cd jnalib
ant
```

### OpenBSD

Binaries are build in VMs for

- x86
- x86-64

They are build using the build-packages generated as part of the Linux build

```
scp user@BUILD_HOST:src/jnalib/build/build-package-openbsd-x86-7.0.1.zip .
unzip build-package-openbsd-x86-7.0.1.zip
cd build-package-openbsd-x86-7.0.1
export JAVA_HOME=/usr/local/jdk-1.8.0
export MAKE=gmake
sh build.sh
scp opensbd-x86.jar user@BUILD_HOST:src/jnalib/lib/native
```
126 changes: 118 additions & 8 deletions www/FreeBSD.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
Building JNA for FreeBSD
========================

aarch64
-------

This recipe was used to build the FreeBSD aarch64 native library on amd64:

```
# Fetch FreeBSD 13.2 image and extract it
wget https://download.freebsd.org/snapshots/VM-IMAGES/13.2-STABLE/aarch64/20231216/FreeBSD-13.2-STABLE-arm64-aarch64-20231216-9986fd59d855-256898.qcow2.xz
xz -d FreeBSD-13.2-STABLE-arm64-aarch64-20231216-9986fd59d855-256898.qcow2.xz
wget https://download.freebsd.org/releases/VM-IMAGES/13.2-RELEASE/aarch64/Latest/FreeBSD-13.2-RELEASE-arm64-aarch64.qcow2.xz
xz -d FreeBSD-13.2-RELEASE-arm64-aarch64.qcow2.xz
# Ensure there is enough space in the image
qemu-img resize FreeBSD-13.2-STABLE-arm64-aarch64-20231216-9986fd59d855-256898.qcow2 +5G
qemu-img resize -f qcow2 FreeBSD-13.2-RELEASE-arm64-aarch64.qcow2 +5G
# Launch aarch64 emulator with downloaded image
qemu-system-aarch64 -m 4096M -cpu cortex-a57 -M virt \
-bios /usr/lib/u-boot/qemu_arm64/u-boot.bin \
-serial telnet::4444,server -nographic \
-drive if=none,file=PATH_TO_IMAGE/FreeBSD-13.2-STABLE-arm64-aarch64-20231216-9986fd59d855-256898.qcow2,id=hd0 \
-drive if=none,file=FreeBSD-13.2-RELEASE-arm64-aarch64.qcow2,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-device virtio-net-device,netdev=net0 \
-netdev user,id=net0
Expand All @@ -35,26 +38,133 @@ exit
# Login as root
# Set current date and time (YYYYMMDDHHMM)
date 202403081928
# Install prerequisites - part 1 - java, build system, rsync
pkg install openjdk17 wget automake rsync gmake gcc
pkg install openjdk17 wget automake rsync gmake gcc bash texinfo
# Adjust fstab (optional, only needed if reboot is planned)
# fdesc /dev/fd fdescfs rw 0 0
# proc /proc procfs rw 0 0
# Install prerequisites - part 2 - ant
wget https://dlcdn.apache.org//ant/binaries/apache-ant-1.10.14-bin.zip
wget https://dlcdn.apache.org/ant/binaries/apache-ant-1.10.14-bin.zip
unzip apache-ant-1.10.14-bin.zip
# Transfer JNA source code to build environment
rsync -a --exclude=.git USER@BUILD_HOST:src/jnalib/ jnalib/
rsync -av --exclude=.git USER@BUILD_HOST:src/jnalib/ jnalib/
chmod +x native/libffi/configure native/libffi/install-sh
# Build JNA and run unittests
cd jnalib
/root/apache-ant-1.10.14/bin/ant
# Copy jna native library back to host system
```

x86
---

```
# Fetch image
wget https://download.freebsd.org/releases/VM-IMAGES/13.2-RELEASE/i386/Latest/FreeBSD-13.2-RELEASE-i386.qcow2.xz
xz -d FreeBSD-13.2-RELEASE-i386.qcow2.xz
# Ensure there is enough space in the image
qemu-img resize -f qcow2 FreeBSD-13.2-RELEASE-i386.qcow2 +5G
# Launch image
qemu-system-i386 -m 3096M -drive file=FreeBSD-13.2-RELEASE-i386.qcow2
gpart show /dev/ada0
gpart recover /dev/ada0
gpart show /dev/ada0
gpart resize -i 4 /dev/ada0
growfs /
# Exit single user mode (BSD boots to multi-user)
exit
# Login as root
# Set keyboard configuration
kbdmap
# Set current date and time (YYYYMMDDHHMM)
date 202312231627
date 202403081928
# Install prerequisites - part 1 - java, build system, rsync
pkg install openjdk17 wget automake rsync gmake gcc bash texinfo
# Adjust fstab (optional, only needed if reboot is planned)
# fdesc /dev/fd fdescfs rw 0 0
# proc /proc procfs rw 0 0
# Install prerequisites - part 2 - ant
wget https://dlcdn.apache.org/ant/binaries/apache-ant-1.10.14-bin.zip
unzip apache-ant-1.10.14-bin.zip
# Transfer JNA source code to build environment
rsync -av --exclude=.git USER@BUILD_HOST:src/jnalib/ jnalib/
chmod +x jnalib/native/libffi/configure jnalib/native/libffi/install-sh
# Build JNA and run unittests
cd jnalib
/root/apache-ant-1.10.14/bin/ant
# Copy jna native library back to host system
```

x86-64
------

```
# Fetch image
wget https://download.freebsd.org/releases/VM-IMAGES/13.2-RELEASE/amd64/Latest/FreeBSD-13.2-RELEASE-amd64.qcow2.xz
xz -d FreeBSD-13.2-RELEASE-amd64.qcow2.xz
# Ensure there is enough space in the image
qemu-img resize -f qcow2 FreeBSD-13.2-RELEASE-amd64.qcow2 +5G
# Launch image
qemu-system-amd64 -m 4096M -drive file=FreeBSD-13.2-RELEASE-amd64.qcow2
gpart show /dev/ada0
gpart recover /dev/ada0
gpart show /dev/ada0
gpart resize -i 4 /dev/ada0
growfs /
# Exit single user mode (BSD boots to multi-user)
exit
# Login as root
# Set keyboard configuration
kbdmap
# Set current date and time (YYYYMMDDHHMM)
date 202403081928
# Install prerequisites - part 1 - java, build system, rsync
pkg install openjdk17 wget automake rsync gmake gcc bash texinfo
# Adjust fstab (optional, only needed if reboot is planned)
# fdesc /dev/fd fdescfs rw 0 0
# proc /proc procfs rw 0 0
# Install prerequisites - part 2 - ant
wget https://dlcdn.apache.org/ant/binaries/apache-ant-1.10.14-bin.zip
unzip apache-ant-1.10.14-bin.zip
# Transfer JNA source code to build environment
rsync -av --exclude=.git USER@BUILD_HOST:src/jnalib/ jnalib/
chmod +x jnalib/native/libffi/configure jnalib/native/libffi/install-sh
# Build JNA and run unittests
cd jnalib
/root/apache-ant-1.10.14/bin/ant
# Copy jna native library back to host system
```

0 comments on commit 16e036a

Please sign in to comment.