Skip to content

Commit

Permalink
[build] Add support for ASM files in Make + CMake
Browse files Browse the repository at this point in the history
* Extract out common portion of `lib/Makefile` into `lib/libzstd.mk`.
  Most relevantly, the way we find library files.
* Use `lib/libzstd.mk` in the other Makefiles instead of repeating the
  same code.
* Add a test `tests/test-variants.sh` that checks that the builds of
  `make -C programs allVariants` are correct, and run it in Actions.
* Adds support for ASM files in the CMake build.

The Meson build is not updated because it lists every file in zstd,
and supports ASM off the bat, so the Huffman ASM commit will just add
the ASM file to the list.

The Visual Studios build is not updated because I'm not adding ASM
support to Visual Studios yet.
  • Loading branch information
terrelln committed Sep 17, 2021
1 parent 9d2a45a commit 8bf699a
Show file tree
Hide file tree
Showing 16 changed files with 455 additions and 336 deletions.
13 changes: 7 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ jobs:
# preinstalled to reduce installation time.
docker:
- image: fbopensource/zstd-circleci-primary:0.0.1
# TODO: Re-enable aarch64 build:
# make aarch64build && make clean
steps:
- checkout
- run:
name: Test
command: |
./tests/test-license.py
cc -v; CFLAGS="-O0 -Werror -pedantic" make all && make clean
make c99build ; make clean
make c11build ; make clean
make aarch64build ; make clean
make -j regressiontest; make clean
make shortest ; make clean
make cxxtest ; make clean
make c99build && make clean
make c11build && make clean
make -j regressiontest&& make clean
make shortest && make clean
make cxxtest && make clean
# the second half of the jobs are in this test
short-tests-1:
docker:
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/dev-short-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ jobs:
make clean && make -j all MOREFLAGS="-Werror -DZSTD_NO_INLINE -DZSTD_STRIP_ERROR_STRINGS"
make clean && make check MOREFLAGS="-Werror -DZSTD_NO_INLINE -DZSTD_STRIP_ERROR_STRINGS"
test-variants:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: make all variants & validate
run: |
make -j -C programs allVariants MOREFLAGS=-O0
./tests/test-variants.sh
qemu-consistency:
name: QEMU ${{ matrix.name }}
Expand Down Expand Up @@ -263,7 +272,6 @@ jobs:
run: |
LDFLAGS="-static" CC=$XCC QEMU_SYS=$XEMU make clean check
# This test currently fails on Github Actions specifically.
# Possible reason : TTY emulation.
# Note that the same test works fine locally and on travisCI.
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ armbuild: clean
CC=arm-linux-gnueabi-gcc CFLAGS="-Werror" $(MAKE) allzstd

aarch64build: clean
CC=aarch64-linux-gnu-gcc CFLAGS="-Werror" $(MAKE) allzstd
CC=aarch64-linux-gnu-gcc CFLAGS="-Werror -O0" $(MAKE) allzstd

ppcbuild: clean
CC=powerpc-linux-gnu-gcc CFLAGS="-m32 -Wno-attributes -Werror" $(MAKE) -j allzstd
Expand Down Expand Up @@ -381,23 +381,23 @@ cmakebuild:

c89build: clean
$(CC) -v
CFLAGS="-std=c89 -Werror" $(MAKE) allmost # will fail, due to missing support for `long long`
CFLAGS="-std=c89 -Werror -O0" $(MAKE) allmost # will fail, due to missing support for `long long`

gnu90build: clean
$(CC) -v
CFLAGS="-std=gnu90 -Werror" $(MAKE) allmost
CFLAGS="-std=gnu90 -Werror -O0" $(MAKE) allmost

c99build: clean
$(CC) -v
CFLAGS="-std=c99 -Werror" $(MAKE) allmost
CFLAGS="-std=c99 -Werror -O0" $(MAKE) allmost

gnu99build: clean
$(CC) -v
CFLAGS="-std=gnu99 -Werror" $(MAKE) allmost
CFLAGS="-std=gnu99 -Werror -O0" $(MAKE) allmost

c11build: clean
$(CC) -v
CFLAGS="-std=c11 -Werror" $(MAKE) allmost
CFLAGS="-std=c11 -Werror -O0" $(MAKE) allmost

bmix64build: clean
$(CC) -v
Expand Down
4 changes: 2 additions & 2 deletions build/cmake/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# in the COPYING file in the root directory of this source tree).
# ################################################################

project(libzstd C)
project(libzstd C ASM)

set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
option(ZSTD_BUILD_STATIC "BUILD STATIC LIBRARIES" ON)
Expand All @@ -22,7 +22,7 @@ include_directories(${LIBRARY_DIR} ${LIBRARY_DIR}/common)

file(GLOB CommonSources ${LIBRARY_DIR}/common/*.c)
file(GLOB CompressSources ${LIBRARY_DIR}/compress/*.c)
file(GLOB DecompressSources ${LIBRARY_DIR}/decompress/*.c)
file(GLOB DecompressSources ${LIBRARY_DIR}/decompress/*.c ${LIBRARY_DIR}/decompress/*.S)
file(GLOB DictBuilderSources ${LIBRARY_DIR}/dictBuilder/*.c)

set(Sources
Expand Down
3 changes: 2 additions & 1 deletion contrib/freestanding_lib/freestanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ def _log(self, *args, **kwargs):
print(*args, **kwargs)

def _copy_file(self, lib_path):
if not (lib_path.endswith(".c") or lib_path.endswith(".h")):
suffixes = [".c", ".h", ".S"]
if not any((lib_path.endswith(suffix) for suffix in suffixes)):
return
if lib_path in SKIPPED_FILES:
self._log(f"\tSkipping file: {lib_path}")
Expand Down
8 changes: 6 additions & 2 deletions contrib/linux-kernel/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ CPPFLAGS += -DZSTD_ASAN_DONT_POISON_WORKSPACE
LINUX_ZSTD_MODULE := $(wildcard $(LINUX_ZSTDLIB)/*.c)
LINUX_ZSTD_COMMON := $(wildcard $(LINUX_ZSTDLIB)/common/*.c)
LINUX_ZSTD_COMPRESS := $(wildcard $(LINUX_ZSTDLIB)/compress/*.c)
LINUX_ZSTD_DECOMPRESS := $(wildcard $(LINUX_ZSTDLIB)/decompress/*.c)
LINUX_ZSTD_DECOMPRESS := $(wildcard $(LINUX_ZSTDLIB)/decompress/*.c $(LINUX_ZSTDLIB)/decompress/*.S)
LINUX_ZSTD_FILES := $(LINUX_ZSTD_MODULE) $(LINUX_ZSTD_COMMON) $(LINUX_ZSTD_COMPRESS) $(LINUX_ZSTD_DECOMPRESS)
LINUX_ZSTD_OBJECTS := $(LINUX_ZSTD_FILES:.c=.o)
LINUX_ZSTD_OBJECTS0 := $(LINUX_ZSTD_FILES:.c=.o)
LINUX_ZSTD_OBJECTS := $(LINUX_ZSTD_OBJECTS0:.S=.o)

%.o: %.S
$(CC) -c $(CPPFLAGS) $(CFLAGS) $^ -o $@

liblinuxzstd.a: $(LINUX_ZSTD_OBJECTS)
$(AR) $(ARFLAGS) $@ $^
Expand Down
16 changes: 2 additions & 14 deletions contrib/pzstd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,6 @@ LD_COMMAND = $(CXX) $^ $(ALL_LDFLAGS) $(LIBS) -pthread -o $@
CC_COMMAND = $(CC) $(DEPFLAGS) $(ALL_CFLAGS) -c $< -o $@
CXX_COMMAND = $(CXX) $(DEPFLAGS) $(ALL_CXXFLAGS) -c $< -o $@

# Get a list of all zstd files so we rebuild the static library when we need to
ZSTDCOMMON_FILES := $(wildcard $(ZSTDDIR)/common/*.c) \
$(wildcard $(ZSTDDIR)/common/*.h)
ZSTDCOMP_FILES := $(wildcard $(ZSTDDIR)/compress/*.c) \
$(wildcard $(ZSTDDIR)/compress/*.h)
ZSTDDECOMP_FILES := $(wildcard $(ZSTDDIR)/decompress/*.c) \
$(wildcard $(ZSTDDIR)/decompress/*.h)
ZSTDPROG_FILES := $(wildcard $(PROGDIR)/*.c) \
$(wildcard $(PROGDIR)/*.h)
ZSTD_FILES := $(wildcard $(ZSTDDIR)/*.h) \
$(ZSTDDECOMP_FILES) $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES) \
$(ZSTDPROG_FILES)

# List all the pzstd source files so we can determine their dependencies
PZSTD_SRCS := $(wildcard *.cpp)
PZSTD_TESTS := $(wildcard test/*.cpp)
Expand Down Expand Up @@ -189,7 +176,8 @@ roundtrip: test/RoundTripTest$(EXT)

# Use the static library that zstd builds for simplicity and
# so we get the compiler options correct
$(ZSTDDIR)/libzstd.a: $(ZSTD_FILES)
.PHONY: $(ZSTDDIR)/libzstd.a
$(ZSTDDIR)/libzstd.a:
CFLAGS="$(ALL_CFLAGS)" LDFLAGS="$(ALL_LDFLAGS)" $(MAKE) -C $(ZSTDDIR) libzstd.a

# Rules to build the tests
Expand Down
Loading

0 comments on commit 8bf699a

Please sign in to comment.