-
Notifications
You must be signed in to change notification settings - Fork 7
Add Support for -MD, -MMD, -gccdep #25
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
base: main
Are you sure you want to change the base?
Conversation
|
|
Drat. I ran black on the sources but didn't catch the mypi rules. Will fix. This is to support getting dependency files generated at build time. These can be used with a build system to rebuild objects when needed and avoid rebuilding them when not (related: Xeeynamo/sotn-decomp#2792) |
|
So the TL;DR is that mwccpsp will create dependency files as part of compilation, but because mwccgap only cares about the compiled object data (and writes the .c file to a temporary directory), the dependency files are discarded? And then in addition to that, you post process the dependency files to fixup the paths? |
Makes `Compiler` aware of any dependency file that `mwccpsp.exe` might emit and if run through `wibo`, it converts the paths from DOS to Unix paths. This allows tools like `make` or `ninja` to rebuild objects based on the source file's embedded dependencies ensuring that files get rebuilt when necessary and avoiding rebuilding files when not needed. `mwccpsp.exe` supports two modes when emitting dependency files in addition to a compiled output - gcc compatibility mode (specified by the `-gccdep` argument) where the file is placed next to the output object, and another where the file is placed in `$PWD`. Both modes are supported, but MetroWorks mode only works with a regular file input (and not stdin). In cases where the input C file is read from stdin, the source dependency for the make rule cannot be determined. Instead of using the ephemeral C file, the dependency is removed from the output rule. In all cases the include headers that are emitted are absoluate paths, unlike GCC. Additional post-processing could be done to determine if the absolute path matches one of the relative include paths, but that is not necessary for the current use case. `-M` and `-MM` options are not supported because they change the primary output of `mwccpsp.exe` and later logic assumes its processing an ELF file. This case could be detected as well, but is not currently needed.
|
|
||
|
|
||
| class Compiler: | ||
| obj_bytes: bytes | None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it simpler to make this b"" rather than None?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few cases that I didn't add support for yet, but was planning on coming back to for completeness. The -M, and -MM options as well as -make, -P, -S options don't emit object code and would not have obj_bytes. Some of those need similar post-processing. It would be fair to say mwccgap shouldn't be used for those cases, but I was considering it as a generalized mwcc wrapper rather than only for cases where ASM rewriting is necessary.
|
Not sure if it meets your requirements, but we have a battle-tested |
|
@mkst Yes, that's exactly the use case. I'm not sure how you want MWCC to be able to be overridden in the unit test, but I added an environment variable check. PATH=$PATH:../wibo MWCC=../sotn-decomp/bin/mwccpsp.exe python3 -m unittest@encounter the use case is similar, but minimally The other issue is that we pipe our sources into I tried to keep path translation as close to wibo as possible, but also have a separate PR for wibo to expose path translation as well. I would like to use the tool that translates the paths to translate the paths instead of having a duplicate implementation, if possible. We use wibo, but I hadn't considered the wine use case, but wouldn't |
|
I hadn't realised the hardcoding was in the unit tests (on holiday and on my phone), so ignore that comment. I think I'd prefer if there was an explicit flag to pass to mwccgap to enable this behaviour (off by default) rather than looking at the c_flags. Also feeling like the path manipulation stuff doesn't really belong in mwccgap but appreciate its possibly the easiest place to do it... |
I made the change and think making it configurable even for tests is reasonable. I didn't want to assume any version of mwcc was available for the tests to be runnable, so these are already disabled unless they can be found, but making them work with
I might be misinterpreting the request, but I wanted to avoid I also didn't want
As much as possible, I was trying to make the typical use case Just Work™. Having an external post processing step complicates build system logic. Just like |
|
I just ran into an issue this change would have addressed again and wanted to see if the issue is the feature or the implementation and how to get this merged in. Headers not being tracked nearly cost me a great deal of time this week (and certainly has I the past). I usually use this patch in my working branch, but had forgotten that it was stashed. I was working on a header file shared between PS and PSP versions of the game and rebuilding as I went. The PSP build continued to match successfully until a clean build much later. Then I remembered I had to manually touch any of the C files that include any of the headers were used by on the PSP side to get them to rebuild. In $> touch src/st/e_bat.h ; ninja | cat
[1/18] check config/check.hd.sha
[2/18] check config/check.pspeu.sha
[3/18] psx cc src/st/np3/e_bat.c
[4/18] psx cc src/st/dai/e_bat.c
[5/18] psx cc src/st/no3/e_bat.c
⋮
[12/18] check config/check.us.sha
⋮However, note that those 3 C files are also compiled for PSP via With the change in this PR the same files get recompiled for the PSP as well: The PS1 and PSP build graphs have around 2000 and 700 nodes, respectively. It's impractical to rebuild all files for any header change. On the GCC side the dependency output allows us to rebuild just what's necessary. On the PSP side we can't currently get those dependency files so we either selectively configure a hardcoded list of "hot" header files that will rebuild the world, or we don't track it at all. An alternative is to rebuild everything anytime anything in the source tree changes. On the PSP side, a build that just recompiles all C files, links them, and verifies the checksum takes 13s. It rebuilds 619 nodes in the build graph. With dependency tracking for the A different approach would be to manually track header files with each c file that uses them (recursively). I'd consider that unmaintainable, error prone, and difficult to verify for correctness. If you're |
Makes
Compileraware of any dependency file thatmwccpsp.exemight emit and if run throughwibo, it converts the paths from DOS to Unix paths. This allows tools likemakeorninjato rebuild objects based on the source file's embedded dependencies ensuring that files get rebuilt when necessary and avoiding rebuilding files when not needed.mwccpsp.exesupports two modes when emitting dependency files in addition to a compiled output - gcc compatibility mode (specified by the-gccdepargument) where the file is placed next to the output object, and another where the file is placed in$PWD. Both modes are supported, but MetroWorks mode only works with a regular file input (and not stdin).In cases where the input C file is read from stdin, the source dependency for the make rule cannot be determined. Instead of using the ephemeral C file, the dependency is removed from the output rule.
In all cases the include headers that are emitted are absoluate paths, unlike GCC. Additional post-processing could be done to determine if the absolute path matches one of the relative include paths, but that is not necessary for the current use case.
-Mand-MMoptions are not supported because they change the primary output ofmwccpsp.exeand later logic assumes its processing an ELF file. This case could be detected as well, but is not currently needed.