Skip to content

Commit

Permalink
Add OSX workflow (libjxl#2922)
Browse files Browse the repository at this point in the history
build_stats.py is somewhat fixed, but currently provieds no useful data.
  • Loading branch information
eustas authored Nov 1, 2023
1 parent 7f11af6 commit 70667c1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 15 deletions.
40 changes: 34 additions & 6 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ concurrency:

jobs:
ubuntu_build:
name: Ubuntu Build ${{ matrix.name }}
name: ${{ startsWith(matrix.os, 'macos-') && 'MacOS' || 'Ubuntu' }} Build ${{ matrix.name }}
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
strategy:
fail-fast: false
Expand All @@ -44,7 +44,7 @@ jobs:
env_stack_size: 1
max_stack: 2400
# Conformance tooling test requires numpy.
apt_pkgs: graphviz python3-numpy
apt_pkgs: doxygen graphviz python3-numpy
- name: lowprecision
mode: release
test_in_pr: true
Expand Down Expand Up @@ -108,6 +108,12 @@ jobs:
apt_pkgs: clang-7
cc: clang-7
cxx: clang++-7
- name: release:osx
os: macos-latest
mode: release
skip_install: true
cmake_args: >-
-DCMAKE_FIND_FRAMEWORK=NEVER
env:
CCACHE_DIR: ${{ github.workspace }}/.ccache
Expand All @@ -128,15 +134,15 @@ jobs:
with:
egress-policy: audit

- name: Install build deps
- name: Install build deps Ubuntu
if: startsWith(matrix.os, 'macos-') == false
run: |
sudo rm -f /var/lib/man-db/auto-update
sudo apt update
sudo apt install -y \
ccache \
clang \
cmake \
doxygen \
graphviz \
imagemagick \
libbenchmark-dev \
Expand All @@ -158,12 +164,32 @@ jobs:
#
echo "CC=${{ matrix.cc || 'clang' }}" >> $GITHUB_ENV
echo "CXX=${{ matrix.cxx || 'clang++' }}" >> $GITHUB_ENV
- name: Install build deps MacOS
if: startsWith(matrix.os, 'macos-')
run: |
# Should be already installed:
# brew install brotli giflib jpeg-turbo libpng zlib
# Not required, since we skip building documentation
# brew install doxygen
brew install binutils ccache coreutils googletest ninja sdl2
- name: Checkout the source
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: true
fetch-depth: 2

- name: Setup the Homebrew prefixes
if: startsWith(matrix.os, 'macos-')
run: |
CMAKE_PREFIX_PATH=`brew --prefix brotli`:`brew --prefix giflib`:`brew --prefix zlib`:`brew --prefix jpeg-turbo`:`brew --prefix libpng`:`brew --prefix sdl2`:`brew --prefix zlib`
echo "CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" >> $GITHUB_ENV
- name: Suppress doxygen target
if: matrix.name != 'release'
run: |
echo "TARGETS=all" >> $GITHUB_ENV
- name: Setup the LLVM source path
if: matrix.name == 'msan'
run: |
Expand Down Expand Up @@ -243,9 +269,11 @@ jobs:
- name: Build stats ${{ matrix.name }}
if: env.WILL_BUILD == 'true' && matrix.mode == 'release'
run: |
SHARED_LIB_EXT="${{ startsWith(matrix.os, 'macos-') && 'dylib' || 'so' }}"
SELECT_BINUTILS="${{ startsWith(matrix.os, 'macos-') && '--binutils `brew --prefix binutils`/bin/' || '' }}"
tools/scripts/build_stats.py --save build/stats.json \
--max-stack ${{ matrix.max_stack || '0' }} \
cjxl djxl libjxl.so libjxl_dec.so
--max-stack ${{ matrix.max_stack || '0' }} ${SELECT_BINUTILS} \
cjxl djxl libjxl.${SHARED_LIB_EXT} libjxl_dec.${SHARED_LIB_EXT}
# Check that we can build the example project against the installed libs.
- name: Install and build examples
Expand Down
31 changes: 22 additions & 9 deletions tools/scripts/build_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import itertools
import json
import os
import platform
import re
import struct
import subprocess
Expand All @@ -29,6 +30,7 @@
# Ignore functions with stack size smaller than this value.
MIN_STACK_SIZE = 32

IS_OSX = (platform.system() == 'Darwin')

Symbol = collections.namedtuple('Symbol', ['address', 'size', 'typ', 'name'])

Expand All @@ -55,7 +57,10 @@

# u - symbols imported from some other library
# a - absolute address symbols
IGNORE_SYMBOLS = 'ua'
# c - common symbol
# i - indirect symbol
# - - debugger symbol table entries
IGNORE_SYMBOLS = 'uaci-'

SIMD_NAMESPACES = [
'N_SCALAR', 'N_WASM', 'N_NEON', 'N_PPC8', 'N_SSE4', 'N_AVX2', 'N_AVX3']
Expand All @@ -65,15 +70,21 @@ def LoadSymbols(filename):
ret = []
nmout = subprocess.check_output(['nm', '--format=posix', filename])
for line in nmout.decode('utf-8').splitlines():
if line.rstrip().endswith(':'):
line = line.rstrip()
if len(line) == 0:
# OSX nm produces extra crlf at the end
continue
if line.endswith(':'):
# Ignore object names.
continue
line = re.sub(' +', ' ', line)
# symbol_name, symbol_type, (optional) address, (optional) size
symlist = line.rstrip().split(' ')
assert 2 <= len(symlist) <= 4
col_count = len(symlist)
assert 2 <= col_count <= 4
ret.append(Symbol(
int(symlist[2], 16) if len(symlist) > 2 else None,
int(symlist[3], 16) if len(symlist) > 3 else None,
int(symlist[2], 16) if col_count > 2 else None,
int(symlist[3], 16) if col_count > 3 else None,
symlist[1],
symlist[0]))
return ret
Expand Down Expand Up @@ -145,8 +156,9 @@ def LoadStackSizes(filename, binutils=''):
section, which can be done by compiling with -fstack-size-section in clang.
"""
with tempfile.NamedTemporaryFile() as stack_sizes_sec:
objcopy = ['objcopy', 'gobjcopy'][IS_OSX]
subprocess.check_call(
[binutils + 'objcopy', '-O', 'binary', '--only-section=.stack_sizes',
[binutils + objcopy, '-O', 'binary', '--only-section=.stack_sizes',
'--set-section-flags', '.stack_sizes=alloc', filename,
stack_sizes_sec.name])
stack_sizes = stack_sizes_sec.read()
Expand All @@ -157,10 +169,11 @@ def LoadStackSizes(filename, binutils=''):
# dynamic stack allocations are not included.

# Get the pointer format based on the ELF file.
objdump = ['objdump', 'gobjdump'][IS_OSX]
output = subprocess.check_output(
[binutils + 'objdump', '-a', filename]).decode('utf-8')
[binutils + objdump, '-a', filename]).decode('utf-8')
elf_format = re.search('file format (.*)$', output, re.MULTILINE).group(1)
if elf_format.startswith('elf64-little') or elf_format == 'elf64-x86-64':
if elf_format.startswith('elf64-little') or elf_format.endswith('-x86-64'):
pointer_fmt = '<Q'
elif elf_format.startswith('elf32-little') or elf_format == 'elf32-i386':
pointer_fmt = '<I'
Expand Down Expand Up @@ -234,7 +247,7 @@ def PrintStats(stats):
print('%-32s %17s %17s' % ('Object name', 'Binary size', 'Static RAM size'))
for name, bin_size, ram_size in table:
print('%-32s %8d (%5.1f%%) %8d (%5.1f%%)' % (
name, bin_size, 100. * bin_size / mx_bin_size,
name, bin_size, (100. * bin_size / mx_bin_size) if mx_bin_size else 0,
ram_size, (100. * ram_size / mx_ram_size) if mx_ram_size else 0))
print()

Expand Down

0 comments on commit 70667c1

Please sign in to comment.