Skip to content

[libclc] Ensure directory exists for libclc files #13529

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

Merged
merged 2 commits into from
Apr 23, 2024

Conversation

frasercrmck
Copy link
Contributor

Some generators like Unix Makefiles wouldn't automatically ensure that this directory exists, which can break the build.

Some generators like Unix Makefiles wouldn't automatically ensure that
this directory exists, which can break the build.
@frasercrmck frasercrmck requested a review from a team as a code owner April 23, 2024 09:18
@frasercrmck frasercrmck requested a review from ldrumm April 23, 2024 09:18
Copy link
Contributor

@hdelan hdelan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. How was this working before?

@jchlanda
Copy link
Contributor

LGTM. How was this working before?

I guess that could only be triggered if you manually remove the dir, if you go from the configure/compile scripts it would always be there.

@frasercrmck
Copy link
Contributor Author

LGTM. How was this working before?

I'm glad you asked. I don't think this fix is the best. Let me retry it and that should explain it better.

@frasercrmck
Copy link
Contributor Author

frasercrmck commented Apr 23, 2024

LGTM. How was this working before?

Aye okay so I found that despite my fix, there were "earlier" steps that also needed the same directory, but were expressed using a CMake variable (LIBCLC_LIBRARY_OUTPUT_INTDIR) so I missed them. Those targets also weren't getting their directories created. So it just so happened that when I built the remangled-* targets, it would try and fail to create the libclc dummy file before it had actually created the prepare-* targets, which also need the same directory. If I built the prepare-* targets they'd fail with the same issue.

I tried file(MAKE_DIRECTORY ${LIBCLC_LIBRARY_OUTPUT_INTDIR}) in the top-level CMakeLists.txt, but that only does it at configure time, and if that directory is deleted and another CMake file is touched then it doesn't reconfigure the top-level file and so the directory isn't recreated.

We could also use a custom command or target in the top-level CMakeLists but I found it wasn't running reliably. Perhaps the targets that need that directory would need that target/directory as a dependency.

In the end I decided to go with explicit COMMAND cmake -E make_directory ${LIBCLC_LIBRARY_OUTPUT_INTDIR} in every custom command that needs the directory. This is done elsewhere in LLVM and I think it's the most explicit (dependencies are harder to track, imo).

Basically I think this all worked before "the changes" was because we had set_output_directory(builtins.link... LIBRARY_DIR ${LIBCLC_LIBRARY_OUTPUT_INTDIR}) quite early on and that probably ensured that the directory was present in time for everything afterwards?

Please take another look!

@frasercrmck frasercrmck changed the title [libclc] Ensure directory exists for remangler input [libclc] Ensure directory exists for libclc files Apr 23, 2024
@hdelan
Copy link
Contributor

hdelan commented Apr 23, 2024

What is the dependency DAG like? I think it looks like

(Using -> for depends on)

dummy_target -> libclc_dummy_in.cc
remangled_target -> remangled.bc -> linked.bc -> opt.bc -> libspirv.bc

I might have got the order wrong but I think there are just two dependency chains. Correct me if I am wrong.

So using this DAG we should only need to create the dir if we are making the original libspirv.bc or the dummy.bc? The other targets in the second chain will automatically make libspirv.bc which will make the dir

@frasercrmck
Copy link
Contributor Author

What is the dependency DAG like? I think it looks like

(Using -> for depends on)

dummy_target -> libclc_dummy_in.cc
remangled_target -> remangled.bc -> linked.bc -> opt.bc -> libspirv.bc

I might have got the order wrong but I think there are just two dependency chains. Correct me if I am wrong.

So using this DAG we should only need to create the dir if we are making the original libspirv.bc or the dummy.bc? The other targets in the second chain will automatically make libspirv.bc which will make the dir

I think that's accurate, yep.

There's also the external-calls-${obj_suffix} target which looks broken to me - I'll need to fix that, but I'm not sure anyone's running it.

There's also the aliasing targets, which depend on prepare-${target} so presumably do inherit the directory. Despite that, I've added an explicit make_directory to those as they're in a separate macro, and I think this way it's still nice and self-contained - we don't implicitly get our directory from another target from another macro/function.

@frasercrmck
Copy link
Contributor Author

@intel/llvm-gatekeepers This looks good to merge, thank you.

@ldrumm ldrumm merged commit 5a6f34e into intel:sycl Apr 23, 2024
@frasercrmck frasercrmck deleted the libclc-remangler-build-fix branch April 23, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants