Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

COMMON-5148 Added support for AARCH64 in Linux #42

Merged
merged 3 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions compress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
## About
util-compress is a library for compressing and uncompressing data. Includes snappy and gzip.

A binary is included for Linux-amd64. It will not work on 32-bit platforms. Other platforms will need to compile from source and may not compile or work as-is.
A binary is included for Linux-amd64 and Linux-aarch64. It will not work on 32-bit platforms. Other platforms will need to compile from source and may not compile or work as-is.
joeltucci marked this conversation as resolved.
Show resolved Hide resolved

## Compiling native code on 64-bit linux

**Requires libsnappy-dev**
**Requires libsnappy-dev and libz-dev**

You can build the native code for compress yourself by executing the `updateNative` task. It compiles the native code
using the provided Makefile, which depends on GCC. On Linux, a 64-bit environment with `gcc-multilib` installed is
required so both 64-bit and 32-bit versions will be installed. On macOS, a universal dylib for both `x86_64` and `arm64`
is built automatically. Binaries are installed to `compress/src/main/resources/`. for inclusion in the packaged jar.
using the provided Makefile, which depends on GCC.
For Linux if you are running on an x86 and you wish to build the ARM compatible library, you will need to install "aarch64-linux-gnu-gcc", if you are running on an AARCH64 and wish to build the x86 version of the library you will need to install "x86_64-linux-gnu-gcc". If you do not wish to cross-compile for local testing you can invoke the buildX86/buildAARCH64/installX86/installAARCH64 targets to build just for your current architecture. However we ask when comitting changes that modify the C code that you rebuild for all the supported architectures.

On macOS, a universal dylib for both `x86_64` and `arm64` is built automatically. Binaries are installed to `compress/src/main/resources/`. for inclusion in the packaged jar.

The makefile can also be invoked directly with:

```
$ ./gradlew :mmap:compileJava
$ ./gradlew :compress:compileJava
$ cd compress/src/main/c/
$ make clean install
```
43 changes: 24 additions & 19 deletions compress/src/main/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ all: build

OS := $(shell uname -s | tr A-Z a-z)
ARCH ?= $(shell uname -m)
CC := gcc
REALARCH := $(shell uname -m)

CC ?= gcc

#CFLAGS += -g -fPIC -O3 -Wall
CFLAGS += -fPIC -O3 -std=c99
Expand All @@ -23,13 +25,11 @@ ifeq ($(OS), darwin)
LD_FLAGS += -dynamiclib -arch arm64 -arch x86_64 -Wl,-rpath,/opt/homebrew/lib
DEST_DIR := "../resources/native/Mac OS X"
else
ifneq ($(ARCH), x86_64)
CFLAGS += -m32
LD_FLAGS += -m32
DEST_DIR := "../resources/native/Linux-i386"
else
DEST_DIR := "../resources/native/Linux-amd64"
endif
ifeq ($(ARCH), x86_64)
DEST_DIR := "../resources/native/Linux-amd64/"
else
DEST_DIR := "../resources/native/Linux-$(ARCH)/"
endif
LIBTYPE := so
LD_FLAGS += -shared
#LD_FLAGS += -shared -Wl,-soname,$(LIBSONAME)
Expand All @@ -56,22 +56,27 @@ OBJS = \
$(LIBNAME): $(OBJS)
$(CC) $(LD_FLAGS) -o $@ $(OBJS)

build: $(LIBNAME) $(if $(OS:linux=),,$(if $(ARCH:x86_64=),,build32))

build32:
$(MAKE) ARCH=i386 build
buildAARCH64OnX86:
$(MAKE) CC=aarch64-linux-gnu-gcc ARCH=aarch64 build
buildX86OnAARCH64:
$(MAKE) CC=x86_64-linux-gnu-gcc ARCH=x86_64 build
build: $(LIBNAME) $(if $(OS:linux=),,$(if $(ARCH:$(REALARCH)=),,$(if $(ARCH:x86_64=),buildX86OnAARCH64,buildAARCH64OnX86)))
joeltucci marked this conversation as resolved.
Show resolved Hide resolved

$(DEST_DIR):
mkdir -p $(DEST_DIR)

install: build $(DEST_DIR) $(if $(OS:linux=),,$(if $(ARCH:x86_64=),,install32))
install: build $(DEST_DIR) $(if $(OS:linux=),,$(if $(ARCH:$(REALARCH)=),,$(if $(ARCH:x86_64=),installX86,installAARCH64)))
cp $(LIBNAME) $(DEST_DIR)/$(subst -$(ARCH),,$(LIBNAME))

install32:
$(MAKE) ARCH=i386 install
installX86:
mkw marked this conversation as resolved.
Show resolved Hide resolved
$(MAKE) ARCH=x86_64 install

clean: $(if $(OS:linux=),,$(if $(ARCH:x86_64=),,clean32))
rm -rf $(OBJS) $(TARGET)
installAARCH64:
$(MAKE) ARCH=aarch64 install

clean32:
$(MAKE) ARCH=i386 clean
clean: $(if $(OS:linux=),,$(if $(ARCH:$(REALARCH)=),,$(if $(ARCH:x86_64=),cleanX86,cleanAARCH64)))
rm -rf $(OBJS) $(TARGET)
cleanX86:
$(MAKE) ARCH=x86_64 clean
cleanAARCH64:
$(MAKE) ARCH=aarch64 clean
Binary file not shown.
Binary file not shown.
9 changes: 5 additions & 4 deletions mmap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ The latest util-mmap JAR file can be downloaded via Maven ([link](http://search.

The library depends on [Unix mmap](http://www.gnu.org/software/libc/manual/html_node/Memory_002dmapped-I_002fO.html)
for its underlying functionality, so it uses JNI. The published JAR file contains
native builds for Linux `i386`, Linux `amd64`, macOS `x86_64` and macOS `arm64`. The Java code in the library loads the
native builds for Linux `aarch64`, Linux `amd64`, macOS `x86_64` and macOS `arm64`. The Java code in the library loads the
correct Linux native shared object (.so, .dylib) file from the JAR file at runtime based
on `os.name` and `os.arch` system properties. If you need to run on an unsupported OS, you'll
need to rebuild the native code. See the instructions in [Building](#building).

## Usage

A good starting point for using util-mmap is the [MMapBuffer class](https://eng-git.ausoff.indeed.net/opensource/util/blob/master/mmap/src/main/java/com/indeed/util/mmap/MMapBuffer.java).
A good starting point for using util-mmap is the [MMapBuffer class](https://github.com/indeedeng/util/blob/main/mmap/src/main/java/com/indeed/util/mmap/MMapBuffer.java).
The following example maps in a large file containing an array of longs, written in little-endian order.

```
Expand All @@ -45,10 +45,11 @@ final long firstValue = longArray.get(0);
## Building

You can build the native code for util-mmap yourself by executing the `updateNative` task. It compiles the native code
using the provided Makefile, which depends on GCC. On Linux, a 64-bit environment with `gcc-multilib` installed is
required so both 64-bit and 32-bit versions will be installed. On macOS, a universal dylib for both `x86_64` and `arm64`
using the provided Makefile, which depends on GCC. On Linux you will need a 64 bit x86 or aarch64 environment, other architectures are not currently supported. On macOS, a universal dylib for both `x86_64` and `arm64`
is built automatically. Binaries are installed to `mmap/src/main/resources/`. for inclusion in the packaged jar.

For Linux if you are running on an x86 and you wish to build the ARM compatible library, you will need to install "aarch64-linux-gnu-gcc", if you are running on an AARCH64 and wish to build the x86 version of the library you will need to install "x86_64-linux-gnu-gcc". If you do not wish to cross-compile for local testing you can invoke the buildX86/buildAARCH64/installX86/installAARCH64 targets to build just for your current architecture. However we ask when comitting changes that modify the C code that you rebuild for all the supported architectures.

The makefile can also be invoked directly with:

```
Expand Down
39 changes: 24 additions & 15 deletions mmap/src/main/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ all: build

OS := $(shell uname -s | tr A-Z a-z)
ARCH ?= $(shell uname -m)
CC := gcc
REALARCH := $(shell uname -m)

CC ?= gcc

CFLAGS += -g -fPIC -O3 -Wall

Expand All @@ -23,12 +25,10 @@ ifeq ($(OS), darwin)
LD_FLAGS += -dynamiclib -arch arm64 -arch x86_64
DEST_DIR := "../resources/native/Mac OS X/"
else
ifneq ($(ARCH), x86_64)
CFLAGS += -m32
LD_FLAGS += -m32
DEST_DIR := "../resources/native/Linux-i386/"
else
ifeq ($(ARCH), x86_64)
DEST_DIR := "../resources/native/Linux-amd64/"
else
DEST_DIR := "../resources/native/Linux-$(ARCH)/"
endif
LIBTYPE := so
LD_FLAGS += -shared -Wl,-soname,$(LIBSONAME)
Expand All @@ -54,19 +54,28 @@ OBJS = \
$(REALLIBNAME): $(OBJS)
$(CC) $(LD_FLAGS) -o $@ $(OBJS)

build: $(REALLIBNAME) $(if $(OS:linux=),,$(if $(ARCH:x86_64=),,build32))
buildAARCH64OnX86:
$(MAKE) CC=aarch64-linux-gnu-gcc ARCH=aarch64 build

build32:
$(MAKE) ARCH=i386 build
buildX86OnAARCH64:
$(MAKE) CC=x86_64-linux-gnu-gcc ARCH=x86_64 build

install: build $(if $(OS:linux=),,$(if $(ARCH:x86_64=),,install32))
build: $(REALLIBNAME) $(if $(OS:linux=),,$(if $(ARCH:$(REALARCH)=),,$(if $(ARCH:x86_64=),buildX86OnAARCH64,buildAARCH64OnX86)))

install: build $(if $(OS:linux=),,$(if $(ARCH:$(REALARCH)=),,$(if $(ARCH:x86_64=),installX86,installAARCH64)))
cp $(REALLIBNAME) $(DEST_DIR)/$(subst -$(ARCH),,$(REALLIBNAME))

install32:
$(MAKE) ARCH=i386 install
installX86:
$(MAKE) ARCH=x86_64 install

installAARCH64:
$(MAKE) ARCH=aarch64 install

clean: $(if $(OS:linux=),,$(if $(ARCH:x86_64=),,clean32))
clean: $(if $(OS:linux=),,$(if $(ARCH:$(REALARCH)=),,$(if $(ARCH:x86_64=),cleanX86,cleanAARCH64)))
rm -rf $(OBJS) $(TARGET)

clean32:
$(MAKE) ARCH=i386 clean
cleanX86:
$(MAKE) ARCH=x86_64 clean
cleanAARCH64:
$(MAKE) ARCH=aarch64 clean

Binary file not shown.
Binary file modified mmap/src/main/resources/native/Linux-amd64/libindeedmmap.so.1.0.1
Binary file not shown.
Binary file not shown.