-
Notifications
You must be signed in to change notification settings - Fork 199
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
Adding rule to build Windows .rc files #581
Conversation
5fb3720
to
fa5563f
Compare
The rc.exe and cvtres.exe are, respectively, called "Windows Resource Compiler" and "Windows Resource to Object Converter". I made finding rc.exe in vswhere.py optional since it is part of the Windows SDK which is already being handled as optional in that script. Although I'm not sure the optional part is currently working.
…soft.com/en-us/windows/win32/menurc/about-resource-files The "Windows Resource Compiler" compiles .rc files into .res files which the "Windows Resource to Object Converter" then converts into .obj files, to be used by the linker. The .res files can also be passed directly to the linker which will call the "Windows Resource to Object Converter" in the same directory to convert the file. Since with Buck2 we want explicit dependencies as much as possible I opted to convert the resource file to an .obj file explicitly in the windows_resouce rule.
fa5563f
to
7f890f7
Compare
CC @lmvasquezg @KapJI as Windows experts |
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.
Overall looks good but please add a end to end test which uses windows_resource
.
prelude/toolchains/msvc/vswhere.py
Outdated
@@ -81,6 +86,9 @@ def find_with_vswhere_exe(): | |||
reverse=True, | |||
) | |||
|
|||
vc_exe_names = "cl.exe", "cvtres.exe", "lib.exe", "ml64.exe", "link.exe" |
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.
Semantically these are lists, not tuples.
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.
When I do:
vc_exe_names = "cl.exe", "cvtres.exe", "lib.exe", "ml64.exe", "link.exe"
type(vc_exe_names)
I get tuple.
Is it some obscure Python feature that it is actually a list? Unless I'm misunderstanding what you mean.
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.
I means it should be a list instead of tuple.
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.
Of course, you're right, semantically they are lists
It seems our test suite isn't open sourced, I can add test later myself. If you can, please post some basic example which I can turn into test. |
Co-authored-by: Ruslan Sayfutdinov <ruslan@sayfutdinov.com>
929f328
to
8f600bf
Compare
My sample test:
main.cpp:
message.h:
resources.rc:
Edit: Not sure if the "MESSAGE_TO_PRINT" in a separate header will work because I haven't implemented the include_directories and raw_headers logic, but it can be just copied into resources.rc. |
@KapJI has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Summary: Adds the ability to compile resource files: https://learn.microsoft.com/en-us/windows/win32/menurc/about-resource-files More details are in the commit messages. X-link: facebook/buck2#581 Reviewed By: JakobDegen Differential Revision: D54603649 Pulled By: KapJI fbshipit-source-id: fcf56a919b8b6245000e71565894dc7c5e1c0c3f
Summary: Like other cxx rules it supports specifying "headers" or "include_directories" and "raw_headers". As a test, I added a header dependency to the test I provided in the previous PR: facebook/buck2#581. The final result being the following files: BUCK: ``` # A rule that includes a single .rc file and compiles it into an object file. windows_resource( name = "resources", srcs = [ "resources.rc", ], header_namespace = "", headers = ["message.h"], ) # A rule that links against the above windows_resource rule. # A rule that includes a single .rc file and compiles it into an object file. windows_resource( name = "resources", srcs = [ "resources.rc", ], header_namespace = "", headers = ["message.h"], ) # A rule that links against the above windows_resource rule. cxx_binary( name = "app", srcs = [ "main.cpp", ], deps = [ ":resources" ], linker_flags = [ "User32.lib", ], ) ``` main.cpp: ``` #include <iostream> #include <Windows.h> int main(int argc, const char* argv[]) { std::string message; message.resize(50); int returnValue = LoadStringA(NULL, 4, message.data(), message.size()); if (returnValue == 0) { std::cout << "Failed to read resource"; return 1; } message.resize(returnValue); std::cout << message; return 0; } ``` message.h: ``` #define MESSAGE_TO_PRINT "Hello from header" ``` resources.rc: ``` #include <winresrc.h> #include "message.h" STRINGTABLE BEGIN 4 MESSAGE_TO_PRINT END ``` X-link: facebook/buck2#607 Reviewed By: JakobDegen Differential Revision: D55633608 Pulled By: KapJI fbshipit-source-id: 6d47acaaa0eb77a653b33d46c8c26088fbf8f0f8
Summary: Like other cxx rules it supports specifying "headers" or "include_directories" and "raw_headers". As a test, I added a header dependency to the test I provided in the previous PR: #581. The final result being the following files: BUCK: ``` # A rule that includes a single .rc file and compiles it into an object file. windows_resource( name = "resources", srcs = [ "resources.rc", ], header_namespace = "", headers = ["message.h"], ) # A rule that links against the above windows_resource rule. # A rule that includes a single .rc file and compiles it into an object file. windows_resource( name = "resources", srcs = [ "resources.rc", ], header_namespace = "", headers = ["message.h"], ) # A rule that links against the above windows_resource rule. cxx_binary( name = "app", srcs = [ "main.cpp", ], deps = [ ":resources" ], linker_flags = [ "User32.lib", ], ) ``` main.cpp: ``` #include <iostream> #include <Windows.h> int main(int argc, const char* argv[]) { std::string message; message.resize(50); int returnValue = LoadStringA(NULL, 4, message.data(), message.size()); if (returnValue == 0) { std::cout << "Failed to read resource"; return 1; } message.resize(returnValue); std::cout << message; return 0; } ``` message.h: ``` #define MESSAGE_TO_PRINT "Hello from header" ``` resources.rc: ``` #include <winresrc.h> #include "message.h" STRINGTABLE BEGIN 4 MESSAGE_TO_PRINT END ``` Pull Request resolved: #607 Reviewed By: JakobDegen Differential Revision: D55633608 Pulled By: KapJI fbshipit-source-id: 6d47acaaa0eb77a653b33d46c8c26088fbf8f0f8
Summary: Adds the ability to compile resource files: https://learn.microsoft.com/en-us/windows/win32/menurc/about-resource-files More details are in the commit messages. X-link: facebook/buck2#581 Reviewed By: JakobDegen Differential Revision: D54603649 Pulled By: KapJI fbshipit-source-id: fcf56a919b8b6245000e71565894dc7c5e1c0c3f
Summary: Like other cxx rules it supports specifying "headers" or "include_directories" and "raw_headers". As a test, I added a header dependency to the test I provided in the previous PR: facebook/buck2#581. The final result being the following files: BUCK: ``` # A rule that includes a single .rc file and compiles it into an object file. windows_resource( name = "resources", srcs = [ "resources.rc", ], header_namespace = "", headers = ["message.h"], ) # A rule that links against the above windows_resource rule. # A rule that includes a single .rc file and compiles it into an object file. windows_resource( name = "resources", srcs = [ "resources.rc", ], header_namespace = "", headers = ["message.h"], ) # A rule that links against the above windows_resource rule. cxx_binary( name = "app", srcs = [ "main.cpp", ], deps = [ ":resources" ], linker_flags = [ "User32.lib", ], ) ``` main.cpp: ``` #include <iostream> #include <Windows.h> int main(int argc, const char* argv[]) { std::string message; message.resize(50); int returnValue = LoadStringA(NULL, 4, message.data(), message.size()); if (returnValue == 0) { std::cout << "Failed to read resource"; return 1; } message.resize(returnValue); std::cout << message; return 0; } ``` message.h: ``` #define MESSAGE_TO_PRINT "Hello from header" ``` resources.rc: ``` #include <winresrc.h> #include "message.h" STRINGTABLE BEGIN 4 MESSAGE_TO_PRINT END ``` X-link: facebook/buck2#607 Reviewed By: JakobDegen Differential Revision: D55633608 Pulled By: KapJI fbshipit-source-id: 6d47acaaa0eb77a653b33d46c8c26088fbf8f0f8
Adds the ability to compile resource files: https://learn.microsoft.com/en-us/windows/win32/menurc/about-resource-files
More details are in the commit messages.