Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
name: linux

# FIXME
on:
push:
branches:
- master
- 'releases/**'
pull_request:
branches:
- master
- 'releases/**'
workflow_dispatch:
# on:
# push:
# branches:
# - master
# - 'releases/**'
# pull_request:
# branches:
# - master
# - 'releases/**'

# Set permissions at the job level.
permissions: {}
Expand Down Expand Up @@ -71,15 +74,25 @@ jobs:
run: |
# -gdwarf-4 - see https://github.com/llvm/llvm-project/issues/56550.
CFLAGS="-gdwarf-4 -fno-omit-frame-pointer $CFLAGS_EXTRA" \
meson setup -Dbuildtype=debugoptimized -Denable-docs=true -Denable-cool-uris=true \
$MESON_EXTRA_FLAGS \
meson setup -Dbuildtype=debugoptimized \
-Denable-docs=true \
-Denable-cool-uris=true \
-Denable-parser-generation=$MESON_PARSER_GENERATION \
$MESON_SANITIZE_FLAGS \
build
env:
CC: ${{ matrix.compiler }}
# Use _FORTIFY_SOURCE only if not using sanitizers
CFLAGS_EXTRA: ${{ matrix.sanitizers != 'sanitizers' && '-Wp,-D_FORTIFY_SOURCE=3' || '' }}
# Use sanitizers only if not using Valgrind
MESON_EXTRA_FLAGS: ${{ matrix.sanitizers == 'sanitizers' && '-Db_sanitize=address,undefined,leak' || '' }}
MESON_SANITIZE_FLAGS: ${{ matrix.sanitizers == 'sanitizers' && '-Db_sanitize=address,undefined,leak' || '' }}
# Ensure some setups use the pre-generated files
MESON_PARSER_GENERATION: ${{ matrix.sanitizers == 'sanitizers' && 'false' || 'true' }}
- name: Regenerate parser files
# Ensure some setups update the pre-generated files
if: matrix.sanitizers == 'sanitizers'
run: |
meson compile -C build src/xkbcomp/update-parser
- name: Build
run: |
meson compile -C build
Expand All @@ -93,7 +106,8 @@ jobs:
if: matrix.sanitizers != 'sanitizers'
# Use a specific non-US locale
run: |
LC_ALL=fr_FR.UTF-8 meson test -C build --print-errorlogs --setup=valgrind \
LC_ALL=fr_FR.UTF-8 meson test -C build --print-errorlogs \
--setup=valgrind \
--no-suite python-tests
- name: Upload test logs
uses: actions/upload-artifact@v7
Expand Down
40 changes: 21 additions & 19 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
name: macos

# FIXME
on:
push:
branches:
- master
- 'releases/**'
pull_request:
branches:
- master
- 'releases/**'
workflow_dispatch:
# on:
# push:
# branches:
# - master
# - 'releases/**'
# pull_request:
# branches:
# - master
# - 'releases/**'

# Set permissions at the job level.
permissions: {}
Expand Down Expand Up @@ -37,8 +40,7 @@ jobs:
run: |
sudo mkdir -p /tmp/.X11-unix
sudo chmod 1777 /tmp/.X11-unix
brew install bison libxml2 meson ninja xkeyboard-config xorg-server
brew link bison --force
brew install libxml2 meson ninja xkeyboard-config xorg-server
brew link libxml2 --force

# TODO: fix installing setxkbmap
Expand All @@ -55,18 +57,18 @@ jobs:
- name: Setup
run: |
source venv/bin/activate
PATH="/usr/local/opt/bison/bin:${PATH}" \
meson setup \
-Dbuildtype=debugoptimized \
-Denable-wayland=false \
-Denable-x11=true \
-Dxkb-config-root="$(brew --prefix xkeyboard-config)/share/X11/xkb" \
-Dx-locale-root="$(brew --prefix xorg-server)/share/X11/locale" \
build
meson setup \
-Dbuildtype=debugoptimized \
-Denable-parser-generation=false \
-Denable-wayland=false \
-Denable-x11=true \
-Dxkb-config-root="$(brew --prefix xkeyboard-config)/share/X11/xkb" \
-Dx-locale-root="$(brew --prefix xorg-server)/share/X11/locale" \
build
- name: Build
run: |
source venv/bin/activate
PATH="/usr/local/opt/bison/bin:${PATH}" meson compile -C build
meson compile -C build
- name: Test
run: |
source venv/bin/activate
Expand Down
27 changes: 25 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
permissions:
contents: read
strategy:
fail-fast: false
matrix:
cc: ['cl', 'clang-cl']
env:
Expand All @@ -34,13 +35,35 @@ jobs:
shell: cmd
run: |
:: Jinja2 is needed for merge-modes tests
python -m pip install --upgrade meson Jinja2
python -m pip install --upgrade "%MESON_VERSION%" Jinja2
choco install -y winflexbison3
env:
MESON_VERSION:
${{ matrix.cc == 'cl' && 'meson<1.11' || 'git+https://github.com/mesonbuild/meson.git@master' }}
- name: Setup
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
meson setup --backend=vs -Denable-wayland=false -Denable-x11=false -Denable-docs=false -Denable-xkbregistry=false build
meson setup --backend=vs -Denable-wayland=false ^
-Denable-x11=false ^
-Denable-docs=false ^
-Denable-xkbregistry=false ^
-Denable-parser-generation=%MESON_PARSER_GENERATION% ^
build
env:
# Ensure some setups use the pre-generated files
MESON_PARSER_GENERATION:
${{ matrix.cc == 'cl' && 'false' || 'true' }}
- name: Regenerate parser files
# Ensure some setups update the pre-generated files
if: matrix.cc == 'cl'
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64

:: meson compile -C build debug-update-parser

meson compile -C build src/xkbcomp/update-parser
- name: Build
shell: cmd
run: |
Expand Down
4 changes: 3 additions & 1 deletion PACKAGING
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ libxkbregistry can be disabled with -Denable-xkbregistry=false (see
Dependencies for libxkbcommon:
- C compiler, meson, pkg-config, libc.

- (build) bison (preferred) or win_bison
- (build optional) bison (preferred) or win_bison
To disable, use -Denable-parser-generation=false. In this case, build
will use the pre-generated parser files includes in git and tarball.

- (build optional, runtime required) xkeyboard-config.
During build, for automatically detecting the value of
Expand Down
6 changes: 6 additions & 0 deletions changes/build/997.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- Added pre-generated parser files.
- Added the option `enable-parser-generation`, enabled by default:
- When *enabled*, `bison` is *required* and the build generates automatically
the parser files. This is the behavior of the previous versions.
- When *disabled*, `bison` is *optional* and the build uses the pre-generated
parser files.
67 changes: 53 additions & 14 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -364,21 +364,57 @@ have_version_script = cc.links(

map_to_def = find_program('scripts/map-to-def')

# libxkbcommon.
bison = find_program('bison', 'win_bison', required: true, version: '>= 3.6')
# Parser utils
enable_parser_generation = get_option('enable-parser-generation')
bison = find_program(
'bison',
'win_bison',
required: enable_parser_generation,
version: '>= 3.6',
)
yacc = bison
yacc_gen = generator(
bison,
output: ['@BASENAME@.c', '@BASENAME@.h'],
arguments: [
'--defines=@OUTPUT1@',
'-o',
'@OUTPUT0@',
'-p',
'_xkbcommon_',
'@INPUT@',
subdir('src/xkbcomp')

#####################################
# DEBUG

fs = import('fs')
yacc_wrapper = host_machine.system() == 'windows' ? 'yacc-wrapper.bat' : 'yacc-wrapper'
yacc_wrapper = find_program(
meson.project_source_root() / 'scripts' / yacc_wrapper,
)

# Paths relative to the project root so that the #line references are relative.
parser_source = fs.relative_to(
files('src/xkbcomp/parser.y'),
meson.project_source_root(),
)
parser_implementation = fs.replace_suffix(parser_source, '.c')
parser_header = fs.replace_suffix(parser_implementation, '.h')

custom_target(
'debug-update-parser',
input: parser_source,
output: [
fs.name(parser_implementation),
fs.name(parser_header),
],
depend_files: parser_source,
command: [
yacc_wrapper,
yacc,
parser_source,
parser_implementation,
parser_header,
meson.project_source_root(),
],
build_by_default: false,
install: false,
)

#####################################

# libxkbcommon.
libxkbcommon_sources = [
'src/compose/parser.c',
'src/compose/paths.c',
Expand All @@ -393,7 +429,10 @@ libxkbcommon_sources = [
'src/xkbcomp/keymap.c',
'src/xkbcomp/keymap-dump.c',
'src/xkbcomp/keywords.c',
yacc_gen.process('src/xkbcomp/parser.y'),
# - If enable-parser-regeneration=false, then use the pre-generated parser files.
# These files may be regenerated manually using the target: src/xkbcomp/update-parser.
# - Otherwise regenerate the parser files automatically in the *build* directory.
parser_files,
'src/xkbcomp/rules.c',
'src/xkbcomp/scanner.c',
'src/xkbcomp/symbols.c',
Expand Down Expand Up @@ -703,7 +742,7 @@ summary(
'id': cc.get_id(),
'c_args': get_option('c_args'),
'c_link_args': get_option('c_link_args'),
'yacc': yacc.full_path() + ' ' + yacc.version(),
'yacc': yacc.found() ? yacc.full_path() + ' ' + yacc.version() : '(not found)',
'glibc': has_glibc,
},
section: 'Compiler',
Expand Down
8 changes: 8 additions & 0 deletions meson.options
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ option(
value: '',
description: 'Default XKB options',
)
option(
'enable-parser-generation',
type: 'boolean',
value: true,
description:
'Generate parser files from grammar files (requires bison); ' +
'if false, use pregenerated files shipped in the source tree',
)
option(
'enable-tools',
type: 'boolean',
Expand Down
35 changes: 35 additions & 0 deletions scripts/yacc-wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh
# Run yacc such that the working directory is the source root.
# This is needed for various reasons (e.g. #line references).
# Do not use directly.

set -eu

YACC="$1"
PARSER="$2"
IMPLEMENTATION="$3"
HEADER="$4"
ABS_TOP_SRCDIR="$5"

[ $# -eq 5 ] || {
echo "Usage: $0 YACC PARSER IMPLEMENTATION HEADER ABS_TOP_SRCDIR" >&2;
exit 1;
}

cd "$ABS_TOP_SRCDIR" || exit 1

# Generate the parser
"$YACC" --defines="$HEADER" \
--output="$IMPLEMENTATION" \
--name-prefix=_xkbcommon_ \
"$PARSER"

# Add the license of the .y file
PARSER_HEADER=$(awk '/^\/\*/{found=1} found{print} /\*\//{if(found) exit}' "$PARSER")
DO_NOT_EDIT="/* DO NOT EDIT DIRECTLY: This file is generated from $PARSER. */"
for f in "$IMPLEMENTATION" "$HEADER"; do
[ -f "$f" ] || continue
content=$(cat "$f"; echo x)
content=${content%x}
printf '%s\n\n%s\n\n%s' "$PARSER_HEADER" "$DO_NOT_EDIT" "$content" > "$f"
done
27 changes: 27 additions & 0 deletions scripts/yacc-wrapper.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@echo on
rem Run yacc such that the working directory is the source root.
rem This is needed for various reasons (e.g. #line references).
rem Do not use directly.

setlocal

rem Use %%~ to strip existing quotes so we can re-quote them safely later.
set "YACC=%~1"
set "PARSER=%~2"
set "IMPLEMENTATION=%~3"
set "HEADER=%~4"
set "ABS_TOP_SRCDIR=%~5"

rem Check for exactly 5 arguments.
if "%~5"=="" (
echo Usage: %~0 YACC PARSER IMPLEMENTATION HEADER ABS_TOP_SRCDIR 1>&2
exit /b 1
)

cd /d "%ABS_TOP_SRCDIR%" || exit /b 1

rem Generate the parser
%YACC% --defines="%HEADER%" ^
--output="%IMPLEMENTATION%" ^
--name-prefix=_xkbcommon_ ^
"%PARSER%"
Loading
Loading