Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
add meson build files (#4094)
Browse files Browse the repository at this point in the history
Motivation:

• faster builds (on an Intel Core i9-9900K):
  ( ../configure --disable-sanitizers && make -j8; )
  19,47s user 2,78s system 395% cpu 5,632 total

  ( meson .. -Dmans=true -Ddocs=true -Dprefix=/usr && ninja; )
  38,67s user 3,73s system 1095% cpu 3,871 total

• more approachable build system configuration in the
  python-esque meson domain specific language instead of
  the autotools m4 macro language

• built-in language server support thanks to ninja:
  the required compile_commands.json is built automatically
  and only needs to be linked from the source dir, e.g.:
  ln -s build/compile_commands.json .

Changes:

• the embedded vcs version info format changed from e.g.
  4.18-282-gabe46f69 (2020-05-16, branch "next")
  to:
  4.18-282-gabe46f69
  I think it’s better to lose a little bit of detail for
  the gained cleanliness of using meson’s vcs_tag()

• Drop unused xcb-event dependency.

• We can no longer enable sanitizers and debug options
  based on whether we are in a release or non-release build,
  because our new version logic runs at ninja build time,
  not at meson configure time.

  The new behavior is probably for the better in terms of
  what people expect, and we can make the CI use address sanitizer
  explicitly to ensure it is still exercised.

• We lose the AX_EXTEND_SRCDIR behavior, i.e. including the
  path component of the parent of the source dir in all paths.
  This was a trick we used for easier debugging, so that stack
  traces would contain e.g. ../i3-4.18.1/src/main.c, instead of
  just src/main.c.

  The other mechanism (_i3_version symbol) that we have for including
  the version number in the “backtrace full” (but not merely
  “backtrace”) output of gdb still works.

• Release tarballs now use tar.xz. Why not.

Migration plan

This commit adds the meson build files to the tree, but does not remove
autotools yet. For the development phase, we will keep both build systems
functional (and built on travis).

Then, just before the i3 v4.19 release, we will remove autotools from the tree
and the release tarball will require meson to compile.

This way, we incentivize maintainers to change, while also offering them an easy
way out (if desired) by reverting the most recent commit. In practice, switching
a distribution package from autotools to meson should only be a few line change,
easier than applying the provided patch :). Take a look at the debian/ changes
in this commit for an example.

meson is broadly available everywhere that i3 is available: Both xorg-server and
systemd gained meson build files in 2017, so we can follow suit:
https://anholt.livejournal.com/52574.html
https://in.waw.pl/~zbyszek/blog/systemd-meson.html

How do I?

For producing a coverage report, enable the b_coverage meson base option
and run ninja coverage-html:
% cd build
% meson .. -Db_coverage=true
% ninja
% ninja test
% ninja coverage-html
See also https://mesonbuild.com/howtox.html#producing-a-coverage-report

For using the address sanitizer, memory sanitizer or undefined behavior
sanitizer, use the b_sanitize meson base option:
% cd build
% meson .. -Db_sanitize=address
% ninja
See also https://mesonbuild.com/Builtin-options.html#base-options

related to #4086
  • Loading branch information
stapelberg committed May 19, 2020
1 parent ef8935b commit aba6ec3
Show file tree
Hide file tree
Showing 20 changed files with 734 additions and 38 deletions.
1 change: 1 addition & 0 deletions .dockerignore
@@ -0,0 +1 @@
.git
11 changes: 11 additions & 0 deletions .gitignore
Expand Up @@ -40,8 +40,19 @@ docs/*.html
i3-command-parser.stamp
i3-config-parser.stamp
.clang_complete
compile_commands.json
/.ccls-cache
/.clangd
LAST_VERSION

# We recommend building in a subdirectory called build.
# If you chose a different directory name,
# it is up to you to arrange for it to be ignored by git,
# e.g. by listing your directory in .git/info/exclude.
/build

# TODO(autotools-removal): remove autotools from .gitignore:

################################################################################
# https://raw.githubusercontent.com/github/gitignore/master/Autotools.gitignore
################################################################################
Expand Down
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -31,7 +31,10 @@ install:
script:
- docker run -v $PWD:/usr/src/i3/ -w /usr/src/i3 ${BASENAME} ./travis/check-safe-wrappers.sh
- docker run -v $PWD:/usr/src/i3/ -w /usr/src/i3 ${BASENAME} ./travis/check-formatting.sh
# # TODO(autotools-removal): autoconf build has to keep working until i3 4.19
# is released, so we keep building it in travis.
- docker run -v $PWD:/usr/src/i3/ -w /usr/src/i3 -e CC ${BASENAME} /bin/sh -c 'autoreconf -fi && mkdir -p build && cd build && (../configure || (cat config.log; false)) && make -j CFLAGS="-Wformat -Wformat-security -Wextra -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Werror -fno-common"'
- docker run -v $PWD:/usr/src/i3/ -w /usr/src/i3 -e CC ${BASENAME} /bin/sh -c 'rm -rf build; mkdir -p build && cd build && CFLAGS="-Wformat -Wformat-security -Wextra -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Werror -fno-common" meson .. -Ddocs=true -Dmans=true -Db_sanitize=address && ninja -v'
- docker run -v $PWD:/usr/src/i3/ -w /usr/src/i3 ${BASENAME} ./travis/check-spelling.pl
- docker run -v $PWD:/usr/src/i3/ -w /usr/src/i3 -e CC ${BASENAME} ./travis/run-tests.sh
- ./travis/skip-pkg.sh || docker run -v $PWD:/usr/src/i3/ -w /usr/src/i3 ${BASENAME} ./travis/debian-build.sh deb/debian-amd64/DIST
Expand Down
6 changes: 6 additions & 0 deletions RELEASE-NOTES-next
Expand Up @@ -6,6 +6,12 @@
This is i3 v4.19. This version is considered stable. All users of i3 are
strongly encouraged to upgrade.

In this release, we switched from the autotools build system to the meson build
system (https://mesonbuild.com/). Check https://github.com/i3/i3/issues/4086 for
details. If this causes problems for you, you can revert the commit which
removed autotools from the tree: we tried our best to keep both build systems
working. Please reach out to us in that case!

┌────────────────────────────┐
│ Changes in i3 v4.19 │
└────────────────────────────┘
Expand Down
2 changes: 1 addition & 1 deletion debian/compat
@@ -1 +1 @@
9
10
4 changes: 2 additions & 2 deletions debian/control
Expand Up @@ -2,8 +2,8 @@ Source: i3-wm
Section: x11
Priority: extra
Maintainer: Michael Stapelberg <stapelberg@debian.org>
Build-Depends: debhelper (>= 9),
dh-autoreconf,
Build-Depends: debhelper (>= 10),
meson,
libx11-dev,
libxcb-util0-dev (>= 0.3.8),
libxcb-keysyms1-dev,
Expand Down
2 changes: 1 addition & 1 deletion debian/rules
Expand Up @@ -22,4 +22,4 @@ override_dh_builddeb:
dh_builddeb -- -Zgzip

%:
dh $@ --parallel --builddirectory=build --with=autoreconf
dh $@ --buildsystem=meson+ninja
10 changes: 3 additions & 7 deletions docs/hacking-howto
Expand Up @@ -23,16 +23,12 @@ outdated information.

== Building i3

You can build i3 like you build any other software package which uses autotools.
You can build i3 like you build any other software package which uses meson.
Here’s a memory refresher:

$ autoreconf -fi
$ mkdir -p build && cd build
$ ../configure
$ make -j8

The autoreconf -fi step is unnecessary if you are building from a release
tarball, but shouldn’t hurt either.
$ meson ..
$ ninja

=== Build system features

Expand Down
2 changes: 1 addition & 1 deletion include/libi3.h
Expand Up @@ -101,7 +101,7 @@ void errorlog(char *fmt, ...)
#if !defined(DLOG)
void debuglog(char *fmt, ...)
__attribute__((format(printf, 1, 2)));
#define DLOG(fmt, ...) debuglog("%s:%s:%d - " fmt, STRIPPED__FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define DLOG(fmt, ...) debuglog("%s:%s:%d - " fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#endif

/**
Expand Down
2 changes: 1 addition & 1 deletion include/log.h
Expand Up @@ -26,7 +26,7 @@
is, delete the preceding comma */
#define LOG(fmt, ...) verboselog(fmt, ##__VA_ARGS__)
#define ELOG(fmt, ...) errorlog("ERROR: " fmt, ##__VA_ARGS__)
#define DLOG(fmt, ...) debuglog("%s:%s:%d - " fmt, STRIPPED__FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define DLOG(fmt, ...) debuglog("%s:%s:%d - " fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)

extern char *errorfilename;
extern char *shmlogname;
Expand Down
10 changes: 8 additions & 2 deletions libi3/is_debug_build.c
Expand Up @@ -16,10 +16,16 @@
*/
bool is_debug_build(void) {
/* i3_version contains either something like this:
* "4.0.2 (2011-11-11, branch "release")".
* or: "4.0.2-123-gCOFFEEBABE (2011-11-11, branch "next")".
* "4.0.2 (2011-11-11)" (release version)
* or: "4.0.2-123-gC0FFEE" (debug version)
*
* So we check for the offset of the first opening round bracket to
* determine whether this is a git version or a release version. */
if (strchr(I3_VERSION, '(') == NULL) {
return true; // e.g. 4.0.2-123-gC0FFEE
}
/* In practice, debug versions do not contain parentheses at all,
* but leave the logic as it was before so that we can re-add
* parentheses if we chose to. */
return ((strchr(I3_VERSION, '(') - I3_VERSION) > 10);
}

0 comments on commit aba6ec3

Please sign in to comment.