Skip to content
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

Windows static pr #454

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

rickwebiii
Copy link

This PR might be a bit controversial

This PR does the following:

  • Removes .NET SDK dependency by removing <CorError.h> dependency and just #defineing COR_E_IO, and COR_E_INVALIDOPERATION to whatever the values are on Linux. Philosophically, the C bindings shouldn't depend on .NET because you might not be building for C# (i.e. I'm building Rust bindings).
  • Enables building SEAL_C with static linking on Windows by removing dllimport/export when building with SEAL_BUILD_STATIC_SEAL_C=ON

@@ -540,6 +540,7 @@ if(SEAL_BUILD_SEAL_C)
seal_set_version(sealc)
if(SEAL_BUILD_STATIC_SEAL_C)
seal_set_version_filename(sealc)
add_compile_definitions(SEAL_BUILD_STATIC_SEAL_C)
Copy link
Contributor

Choose a reason for hiding this comment

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

@rickwebiii I'm not familiar with this command. What does it do?

Copy link
Author

@rickwebiii rickwebiii Mar 15, 2022

Choose a reason for hiding this comment

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

It tells the compiler to #define SEAL_BUILD_STATIC_SEAL_C. In gcc/clang, this passes -D SEAL_BUILD_STATIC_SEAL_C, in msvc it passes /D SEAL_BUILD_STATIC_SEAL_C.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does it work for a downstream app? It cannot see #define SEAL_BUILD_STATIC_SEAL_C. So when a downstream app includes seal/c/batchencoder.h that includes seal/c/defines.h, __declspec(dllimport) is always used, right?

Copy link
Author

Choose a reason for hiding this comment

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

Oh, good point. Users would have to add this line to their CMAKE file or some equivalent, which I agree isn't great. I'll do some investigation and try to find how to make libraries both statically and dynamically linkable in Windows.

Copy link
Contributor

Choose a reason for hiding this comment

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

I cannot approve this PR right now. It's really useful though. Shall we keep this PR open? We will release a new version of SEAL soon. We can always rebase this PR to a new version -- there shouldn't be hard conflicts.

Copy link
Author

@rickwebiii rickwebiii Mar 16, 2022

Choose a reason for hiding this comment

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

I need to test this, but it looks like you can always omit declspec(dllimport) and the headers would work for both static and dynamic linking.

The cost of doing so appears to be a single jmp instruction. I'd expect this cost to be a clock cycle, as unconditional branch prediction is trivial and I'd imagine most thunks are near each other in memory, so a bunch fit into an icache line. Since most interesting things you do in SEAL are O(us to ms), this tradeoff is probably fine. dllimport allows you to avoid a thunk in many cases. You only incur this cost with dynamic linking; calling a statically linked function doesn't require a thunk.

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.

2 participants