-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the Windows import library to the providers when building a cdylib (
#1044) Co-authored-by: UebelAndre <github@uebelandre.com>
- Loading branch information
1 parent
7ef755b
commit cbfffbc
Showing
6 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
load(":win_interface_library_analysis_test.bzl", "win_interface_library_analysis_test_suite") | ||
|
||
############################ UNIT TESTS ############################# | ||
win_interface_library_analysis_test_suite(name = "win_interface_library_analysis_test_suite") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
extern "C" void hello(void); | ||
|
||
int main(int argc, char **argv) { | ||
hello(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#[no_mangle] | ||
pub extern "C" fn hello() { | ||
println!("Hello"); | ||
} |
55 changes: 55 additions & 0 deletions
55
test/unit/win_interface_library/win_interface_library_analysis_test.bzl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Analysis tests for exporting the Windows interface library.""" | ||
|
||
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") | ||
load("@rules_cc//cc:defs.bzl", "cc_binary") | ||
load("//rust:defs.bzl", "rust_shared_library") | ||
|
||
def _win_interface_library_test_impl(ctx): | ||
env = analysistest.begin(ctx) | ||
target = analysistest.target_under_test(env) | ||
|
||
files = target[DefaultInfo].files.to_list() | ||
cc_library = target[CcInfo].linking_context.linker_inputs.to_list()[0].libraries[0] | ||
|
||
# Make sure that we have both the `.dll` and the `.dll.lib` file in the default info's files | ||
asserts.equals(env, len(files), 2) | ||
asserts.true(env, files[0].basename.endswith(".dll")) | ||
asserts.true(env, files[1].basename.endswith(".dll.lib")) | ||
|
||
# Make sure that the cc_library has both a dynamic and interface library | ||
asserts.true(env, cc_library.dynamic_library != None) | ||
asserts.true(env, cc_library.interface_library != None) | ||
|
||
return analysistest.end(env) | ||
|
||
win_interface_library_test = analysistest.make(_win_interface_library_test_impl) | ||
|
||
def win_interface_library_analysis_test_suite(name): | ||
"""Analysis tests for exporting the Windows interface library. | ||
Args: | ||
name: the test suite name | ||
""" | ||
rust_shared_library( | ||
name = "mylib", | ||
srcs = ["lib.rs"], | ||
target_compatible_with = ["@platforms//os:windows"], | ||
) | ||
|
||
cc_binary( | ||
name = "mybin", | ||
srcs = ["bin.cc"], | ||
deps = [":mylib"], | ||
target_compatible_with = ["@platforms//os:windows"], | ||
) | ||
|
||
win_interface_library_test( | ||
name = "win_interface_library_test", | ||
target_under_test = ":mylib", | ||
target_compatible_with = ["@platforms//os:windows"], | ||
) | ||
|
||
native.test_suite( | ||
name = name, | ||
tests = [":win_interface_library_test"], | ||
) |