{"action":"opened","issue":{"url":"https://api.github.com/repos/mesonbuild/meson/issues/4682","repository_url":"https://api.github.com/repos/mesonbuild/meson","labels_url":"https://api.github.com/repos/mesonbuild/meson/issues/4682/labels{/name}","comments_url":"https://api.github.com/repos/mesonbuild/meson/issues/4682/comments","events_url":"https://api.github.com/repos/mesonbuild/meson/issues/4682/events","html_url":"https://github.com/mesonbuild/meson/issues/4682","id":394646758,"node_id":"MDU6SXNzdWUzOTQ2NDY3NTg=","number":4682,"title":"Various PCH inconsistencies","user":{"login":"nioncode","id":3159451,"node_id":"MDQ6VXNlcjMxNTk0NTE=","avatar_url":"https://avatars0.githubusercontent.com/u/3159451?v=4","gravatar_id":"","url":"https://api.github.com/users/nioncode","html_url":"https://github.com/nioncode","followers_url":"https://api.github.com/users/nioncode/followers","following_url":"https://api.github.com/users/nioncode/following{/other_user}","gists_url":"https://api.github.com/users/nioncode/gists{/gist_id}","starred_url":"https://api.github.com/users/nioncode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nioncode/subscriptions","organizations_url":"https://api.github.com/users/nioncode/orgs","repos_url":"https://api.github.com/users/nioncode/repos","events_url":"https://api.github.com/users/nioncode/events{/privacy}","received_events_url":"https://api.github.com/users/nioncode/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-12-28T14:18:36Z","updated_at":"2018-12-28T14:18:36Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"While fixing a msvc PCH issue, I found a few inconsistencies in the handling of PCH between Ninja and VS backends and wanted to reach out to discuss these before I work on fixing this.\r\n\r\nFor GCC, I think everything is well understood and should work correctly.\r\nFor MSVC, however, there are a few requirements to be met in order to have correct PCH support:\r\n1. Source files must include the pch header as very first include. This is handled by adding ForceIncludes to the compiler invocation. No problems at all. Note: the path to the pch header does not have to be correct and does not have to be in the include directories of the target, since msvc simply does a string comparison on the include file and does not look up the file in the include directories at all.\r\n2. There has to be an implementation file that includes the pch header and thus creates the pch file. The include directive in this file must use the exact same path as the pch header file that gets included in 1), no matter in which directory the pch header actually lives. This creates a problem if the pch header is in a different directory than the implementation, because unlike to 1), msvc actually DOES look up the header in the target's include directories in order to successfully parse and compile it.\r\n\r\nA few questions that arise from this:\r\n- Do we want to support having pch headers in a different folder than their implementation?\r\n  - If yes, then we should add a test case that enforces that this works (it currently breaks for Ninja + msvc).\r\n  - If not, then we should enforce that both files are in the same directory when generating the build files and not wait for the compiler to decide if it works or not.\r\n- Why don't we create the implementation file for msvc automatically? This would remove the requirement for the user to have the correct pch include path in their pch.c, which might be different from the relative path from pch.c to pch.h. We would then simply create a dummy pch.c for msvc targets that includes the correct pch header. A user thus only has to provide a pch.h just like for GCC and we will create the correct implementation automatically if needed.\r\n\r\n/cc @john-preston who reached out to me via email to tell me about the original issue of the VS backend failing to compile a project that uses pch headers with include guards."}}
{"actor":{"display_login":"nioncode"}}