Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCH step doesn't depend on generated headers #2361

Closed
nicolas17 opened this issue Sep 22, 2017 · 3 comments
Closed

PCH step doesn't depend on generated headers #2361

nicolas17 opened this issue Sep 22, 2017 · 3 comments

Comments

@nicolas17
Copy link

If a header to be precompiled includes a header that is generated during the build, meson doesn't create a proper dependency between them. This leads to ninja trying to precompile the pch before the headers it includes are generated.

Full example:

main.c:

#include <stdio.h>
#include "bigheader.h"

int main() {
    printf("The answer is %d\n", x);
    return 0;
}

generator.sh:

#!/bin/sh
sleep 2
echo "#pragma once" > $1
echo "const int x = 42;" >> $1

pch/pch.h:

#include "bigheader.h"

meson.build:

project('bugtest', 'c')

# pretend this generates a giant file
gen = custom_target('header',
    output: ['bigheader.h'],
    command: ['sh', files('generator.sh'), '@OUTPUT@']
)

executable('bugtest', ['main.c', gen], c_pch: 'pch/pch.h')

The resulting build.ninja has an order-only dependency from main.c.o to pch.h.gch bigheader.h which ensures the compilation waits for bigheader.h to be generated, but there is nothing making bigheader.h a dependency of the PCH step.

On a ninja -j1 this might work, but in a parallel build this leads to pch.h being precompiled before bigheader.h is generated.

One way to solve this is to have meson put all the target's generated headers as order-only dependencies of the precompiled header. Although this might cause too-strict dependencies for the common case where the pch only includes external libraries, in which case I guess this needs an extra keyword argument to be explicit...

@nioncode
Copy link
Contributor

Another way would be to have PCH as a separate pseudo-target or just a method that can take source + header arguments, as well as a list of dependencies. Then, we could add arbitrary dependencies before generating the PCH without adding ALL generators as dependencies.

@jpakkane
Copy link
Member

The dependencies of pch compilation should be identical to regular compilation. It is not because of historical reasons.

@nioncode
Copy link
Contributor

nioncode commented Feb 9, 2019

Fixed by #4860, please close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants