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

meson: Deny shared build on MSVC compiler #2363

Closed
wants to merge 8 commits into from

Conversation

tesuji
Copy link
Contributor

@tesuji tesuji commented Oct 17, 2020

Apparently, zstd has never tested on MSVC 2019 and currently fall to build on that compiler.
It would make sense to gate Meson until there is proper support for that compiler.
cc #2358

This PR also fixes some minor correctness issues.

libzstd_sources += [
windows_mod.compile_resources(
join_paths(zstd_rootdir, 'build/VS2010/libzstd-dll/libzstd-dll.rc'),
include_directories: include_directories(join_paths(zstd_rootdir, 'lib')),
Copy link

Choose a reason for hiding this comment

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

Looking at the output from meson compile -v -C builddir, I am not sure include_directories are actually passed in to the resource compiler.

Anyone else observes this issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will, but I have MSVC compiler error about syntax: https://github.com/lzutao/zstd/runs/1264653094#step:8:130.

Copy link

@o-mdr o-mdr Oct 17, 2020

Choose a reason for hiding this comment

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

Interesting, I cannot get beyond compiling resources on my system, whereas in your build it goes passed it and compiles the resource just fine.

That error is not about syntax, it's a linker error, basically it's saying that there were a couple of symbols observed in functions (ZSTD_cycleLog, ZSTD_XXH64, ZDICT_trainFromBuffer_unsafe_legacy) that were not actually defined. Could it be a missing source/header file or compiler/linker flag?

It's probably ok to compile it with MSVC compiler, just needs to get all the files. It seems like this used to work with previous versions of the compiler, so should work with the newer (maybe just missing some flags)

Copy link
Contributor Author

@tesuji tesuji Oct 17, 2020

Choose a reason for hiding this comment

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

That was a shared build. All the missing symbols were in zstd.lib, which was included the the link command.

There was also a static build, which has syntax error: https://github.com/lzutao/zstd/runs/1267569335#step:8:124.

Copy link
Contributor Author

@tesuji tesuji Oct 17, 2020

Choose a reason for hiding this comment

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

I am sorry for giving the wrong link.

Copy link

Choose a reason for hiding this comment

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

Oh, so it is, not seen that one

@terrelln
Copy link
Contributor

@lzutao It looks like min is defined as a macro, which is messing with the calls to std::min(). I am fairly certain the definition is coming from one of the windows includes from platform.h. Defining NOMINMAX in programs/platform.h, before the windows includes, should probably fix the issue.

@tesuji
Copy link
Contributor Author

tesuji commented Oct 18, 2020

Thank you, @terrelln. Your way really fixes the static build.
The shared build still fall with unresolved symbols error. Hope you could take a look.

At worst case, I could disable shared build for msvc.

@tesuji tesuji changed the title meson: Deny msvc compiler meson: Deny shared build on MSVC compiler Oct 18, 2020
@ghost
Copy link

ghost commented Oct 18, 2020

Could you add /Ob3 c compile option to MSVC2019?

Visual Studio 2019 has a new optimization option /Ob3, which turns on aggressive inlining.
https://docs.microsoft.com/en-us/cpp/build/reference/ob-inline-function-expansion?view=vs-2019

In zstd v1.4.5, just turn on this option, no code changed, run a test code: 6.97s -> 4.77s.
See issue #2314 for more information.

In the upcoming zstd v1.4.6, commit cc88eb7 accelerates from 6.97s to 4.85s, still a bit slower than 4.77s.

This option was added in MSVC2019, if use this option in MSVC2017, it will emit a warning:
cl : Command line warning D9002 : ignoring unknown option '/Ob3'

@tesuji
Copy link
Contributor Author

tesuji commented Oct 18, 2020

@animalize I could. However is the same flag used anywhere else in the other build systems?
I don't want to use some custom optimization flags for meson only.
Also adding that flag would be better in another PR.

@ghost
Copy link

ghost commented Oct 18, 2020

@animalize I could. However does the same flag used anywhere else in the other build systems?
I don't want to use some custom optimization flags for meson only.
Also adding that flag would be better in another PR.

Thanks.

A separated PR sounds reasonable.
The flag should not be used in other build systems. This problem was discovered last month.

@terrelln
Copy link
Contributor

The shared build still fall with unresolved symbols error. Hope you could take a look.

Adding ZDICTLIB_VISIBILITY to this declaration should fix it.

size_t ZDICT_trainFromBuffer_unsafe_legacy(

Like

ZDICTLIB_VISIBILITY size_t ZDICT_trainFromBuffer_unsafe_legacy(
                            void* dictBuffer, size_t maxDictSize,
                            const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
                            ZDICT_legacy_params_t params);

@tesuji
Copy link
Contributor Author

tesuji commented Oct 27, 2020

@Cyan4973
Copy link
Contributor

Cyan4973 commented Dec 5, 2020

I initially thought that the topic was about the shared dynamic library,
but apparently, it's larger than that:
it also applies to a variant of zstd CLI which would be linked against the dynamic library.

The zstd CLI is not designed to be linked to the standard dynamic library libzstd.
That's because it relies on private symbols, which are not exposed by default in the library.

For the CLI to link against a shared library, the library would need to expose basically all symbols,
the same way a static library does (zstd CLI links correctly against the static library).

But there is a reason we only expose selected symbols by default : the rest is considered "internal stuff", and may change at any moment. So it's not good to let applications believe they can depend on these accidental features.

I would suggest to not attempt delivering this feature through meson.

@Cyan4973 Cyan4973 closed this Dec 17, 2020
@tesuji
Copy link
Contributor Author

tesuji commented Dec 18, 2020

Thanks for your explanation. I think Meson had a way to disable statically linking with the library. I've been away from my computer for a while. If anyone want to patch this issue, please don't hesitate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants