summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/c.py
Commit message (Collapse)AuthorAgeFilesLines
...
* | Remove cross_info; cross file is parsed up front and discardedJohn Ericson2019-01-021-1/+1
|/
* Store the target architecture for CL-like compilersJon Turney2018-12-061-4/+5
| | | | | | | | | | | | | | | | | Store the MSVC compiler target architecture ('x86', 'x64' or 'ARM' (this is ARM64, I believe)), rather than just if it's x64 or not. The regex used for target architecture should be ok, based on this list of [1] version outputs, but we assume x86 if no match, for safety's sake. [1] https://stackoverflow.com/a/1233332/1951600 Also detect arch even if cl outputs version to stdout. Ditto for clang-cl Future work: is_64 is now only used in get_instruction_set_args()
* Remove linkerlike args from compile checks. Closes #4542.Jussi Pakkanen2018-11-271-1/+7
|
* Fix flake8 'imported but unused' reportsJon Turney2018-11-191-1/+0
| | | | | | | $ flake8 | grep F401 ./run_unittests.py:43:1: F401 'mesonbuild.mesonlib.is_linux' imported but unused ./mesonbuild/compilers/c.py:32:1: F401 '.compilers.CompilerType' imported but unused ./mesonbuild/compilers/cpp.py:23:1: F401 '.compilers.CompilerType' imported but unused
* Merge pull request #4359 from dcbaker/icc-fixesDylan Baker2018-11-171-25/+11
|\ | | | | ICC fixes for Linux and MacOS
| * compilers: quiet ICC messages about pchDylan Baker2018-11-151-1/+1
| | | | | | | | | | These are useful for debugging, but not interesting for end users, where it just adds lines between ninja jobs without adding value.
| * compilers: Move get_allow_undefined_link_args to CompilerDylan Baker2018-11-151-26/+6
| | | | | | | | | | | | | | This allows each implementation (gnu-like) and msvc to be implemented in their respective classes rather than through an if tree in the CCompiler class. This is cleaner abstraction and allows us to clean up the Fortran compiler, which was calling CCompiler bound methods without an instance.
| * compilers: Set the correct values for undefined modules on apple with iccDylan Baker2018-11-151-1/+5
| |
| * compilers: Add ICC setting for get_allow_undefined_link_argsDylan Baker2018-11-151-0/+2
| |
| * compilers: fix compiler.compile for Intel CompilersDylan Baker2018-11-151-4/+4
| | | | | | | | | | has_arguments is the wrong thing to fix, since all checks that require compiler options are based on compiles, it's the right thing to modify.
* | Guard against broken lib paths returned by gcc.Jussi Pakkanen2018-11-171-3/+6
|/
* Store unexpanded library directory paths. Closes #4392.Jussi Pakkanen2018-11-151-3/+16
|
* compilers: Use keyword only arguments for compiler interfacesDylan Baker2018-11-131-34/+53
| | | | | | | | | | | | | | | | | | | | | | | | Because we need to inherit them in some cases, and python's keyword-or-positional arguments make this really painful, especially with inheritance. They do this in two ways: 1) If you want to intercept the arguments you need to check for both a keyword and a positional argument, because you could get either. Then you need to make sure that you only pass one of those down to the next layer. 2) After you do that, if the layer below you decides to do the same thing, but uses the other form (you used keyword by the lower level uses positional or vice versa), then you'll get a TypeError since two layers down got the argument as both a positional and a keyword. All of this is bad. Fortunately python 3.x provides a mechanism to solve this, keyword only arguments. These arguments cannot be based positionally, the interpreter will give us an error in that case. I have made a best effort to do this correctly, and I've verified it with GCC, Clang, ICC, and MSVC, but there are other compilers like Arm and Elbrus that I don't have access to.
* Add support for Renesas CC-RX toolchainPhillip Cao2018-11-081-0/+43
|
* Use lld-link with clang-clJon Turney2018-11-041-1/+6
| | | | | Use lld-link dynamic linker with clang-cl Don't hardcode dynamic linker name in tests
* Qualify checks of self.version by self.id in VisualStudioC/CPPCompilerJon Turney2018-11-041-3/+7
|
* Teach VisualStudioCCompiler.get_pch_use_args() to handle clang-clJon Turney2018-11-041-0/+2
| | | | | | | | It seems that clang-cl isn't quite compatible with cl in the way it handles pch, and when the precompiled header is used, the pathname of the header is needed, not just its filename. This fixes test\common\13 pch with clang-cl
* Teach VisualStudioCCompiler.has_arguments() about clang-clJon Turney2018-11-041-0/+2
| | | | | | | | | When invoked as clang-cl to compile, it doesn't emit cl-compatible D9002 warnings about unknown options, but fortunately also supports -Werror-unknown-argument instead. When invoked to link, and using LINK, it does emit cl-compatible LNK4044 warnings about unknown options.
* Only add link arguments when needed in Compiler object methodsJon Turney2018-11-041-0/+2
| | | | | | | | | | | | | | | | | | | | | Currently, ComplierHolder.determine_args() unconditionally adds the link arguments to the commmand, even if we aren't linking, because it doesn't have access to the mode (preprocess, compile, link) that _get_compiler_check_args() will use. This leads to command lines like: 'cl testfile.c /nologo /showIncludes /c /Fooutput.obj /Od kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib' which clang-cl considers invalid; MSVS cl accepts this, ignoring the unneeded libraries Change from passing extra_args down to _get_compiler_check_args(), to passing down a callback to CompilerHolder.determine_args() (with a bound kwargs argument), so it can consult mode and kwargs to determine the args to use.
* Detect clang-cl as msvc-like, not clang-likeJon Turney2018-11-041-3/+7
| | | | | | | | | | | | | | | | | Handle clang's cl or clang-cl being in PATH, or set in CC/CXX Future work: checking the name of the executable here seems like a bad idea. These compilers will fail to be detected if they are renamed. v2: Update compiler.get_argument_type() test Fix comparisons of id inside CCompiler, backends and elsewhere v3: ClangClCPPCompiler should be a subclass of ClangClCCompier, as well Future work: mocking in test_find_library_patterns() is effected, as we now test for a subclass, rather than self.id in CCompiler.get_library_naming()
* Add new compiler.get_argument_syntax methodDylan Baker2018-11-031-0/+3
| | | | | | | | | | | Some compilers try very had to pretend they're another compiler (ICC pretends to be GCC and Linux and MacOS, and MSVC on windows), Clang behaves much like GCC, but now also has clang-cl, which behaves like MSVC. This method provides an easy way to determine whether testing for MSVC like arguments `/w1234` or gcc like arguments `-Wfoo` are likely to succeed, without having to check for dozens of compilers and the host operating system, (as you would otherwise have to do with ICC).
* Generalize gnulike-targeting-windows checks.Josh Gao2018-10-301-2/+2
| | | | | | | | | Replace several checks against GCC_MINGW or (GCC_MINGW, GCC_CYGWIN) with is_windows_compiler instead, so that clang and other gcc-like compilers using MinGW work appropriately with vs_module_defs, c_winlibs, and cpp_winlibs. Fixes #4434.
* compilers/c: Fix allow undefined link arg for PE/COFFMarvin Scholz2018-10-251-0/+3
| | | | | | | | | | For PE/COFF it is not possible to allow undefined symbols, so do not try to use the option to do so. While gcc ld silently ignores it, this is not the case for the llvm linker. Fix #4415
* Use relative build-tree RPATHs on macOSDavid Seifert2018-10-141-4/+1
| | | | | | | | | | | | * This helps with reproducibility on macOS in the same way `$ORIGIN` improves reproducibility on Linux-like systems. * This makes the build-tree more resilient to users injecting rpaths via `LDFLAGS`. Currently Meson on macOS crashes when a build-tree rpath and a user-provided `-Wl,-rpath` in LDFLAGS collide, leading to `install_name_tool` failures. While this still does not solve the root cause, it makes the occurrence much less likely, as users will generally pass absolute `-Wl,-rpath` arguments into Meson.
* Added .so to list possible darwin dynamic library suffixes (#4364)gsobala2018-10-131-1/+1
| | | | | | | | | | Occasionally Darwin libraries can be .so rather than .dylib e.g. tensorflow_cc.so tensorflow_cc is a c++ API for Tensorflow (https://github.com/FloopCZ/tensorflow_cc) which was primarily written for Linux but is also compilable on Darwin. Possibly through laziness, possibly just to have consistent filenames, the developers did not opt to change the suffix from the Linux default when this is compiled on Darwin. Also, the Darwin linker will find libraries with a .so suffix if they are in its path. find_library() needs to match the linker behaviour.
* Adding "compiler_type" flag to ARM compilers.Mohammed Amer Khalidi2018-10-071-4/+4
|
* Verify library directories as either 32-bit or 64-bitBruce Richardson2018-10-031-4/+47
| | | | | | | | | | | | | | In get_library_dirs() we are trusting the compiler to return a correct list of directories to search for libraries, based on whether or not we are compiling 64-bit or 32-bit. Unfortunately, this is often not the case, as 64-bit libraries often are returned when compiling with -m32 on a 64-bit OS. Since system directories do not contain a mix of libraries, the solution here is to check each directory, by picking a .so file in the directory and checking whether its 64-bit or 32-bit. If we can't determine if we want 32-bit or 64-bit, just skip the checks and assume the directory is good.
* compilers/c: don't return -pthread for MacOS with any compilerDylan Baker2018-10-011-12/+2
| | | | | | With GCC, Clang, or ICC, and for C++ Fixes #2628
* compilers: Do not use -pthread with clang for darwinMarvin Scholz2018-09-281-0/+10
| | | | | | | Using the -pthread argument is not needed with clang when compiling for darwin, and it results in the warning: warning: argument unused during compilation: '-pthread'
* Don't add rpath linker flags when building for MinGWMartin Storsjö2018-09-251-0/+2
| | | | | | | | | | | GNU binutils ld silently ignores -rpath flags when targeting windows (and it is already commented within ninjabackend.py that rpath as concept doesn't exist on windows), and build_rpath_args in VisualStudioCCompiler also returns an empty array. Therefore skip this flag altogether. This fixes linking with lld in MinGW mode, which doesn't support the rpath flag.
* Abstract shared GCC/Clang/ICC methods in GnuLikeCompilerDavid Seifert2018-09-171-15/+0
|
* Fix ICC on macOSDavid Seifert2018-09-161-2/+8
|
* Do not use relative RPATHs on macOS with ICC/GCCDavid Seifert2018-09-161-1/+2
| | | | | | * Currently, absolute rpaths on macOS are only used with Clang, which breaks Meson builds when using ICC or GCC from Homebrew or MacPorts.
* Use enum instead of `int` for compiler variantsDavid Seifert2018-09-161-23/+16
| | | | | | | | * Enums are strongly typed and make the whole `gcc_type`/`clang_type`/`icc_type` distinction redundant. * Enums also allow extending via member functions, which makes the code more generalisable.
* Sprinkle functools.lru_cache() in a few more placesNirbheek Chauhan2018-09-111-11/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | This improves the backend generation time for gst-build from 7.4s to 6.6s. This is probably all the low-hanging fruit we can get, further improvements will probably require refactoring, moving to pathlib.Path or reimplementing CompilerArgs: 222045 0.551 0.000 1.324 0.000 compilers.py:666(__iadd__) 3691 0.230 0.000 0.885 0.000 ninjabackend.py:99(write) 233560 0.441 0.000 0.701 0.000 posixpath.py:75(join) 882 0.141 0.000 0.636 0.001 backends.py:509(generate_basic_compiler_args) 256301 0.248 0.000 0.576 0.000 compilers.py:562(_can_dedup) 37369 0.035 0.000 0.466 0.000 compilers.py:652(extend_direct) 74650 0.067 0.000 0.431 0.000 compilers.py:641(append_direct) 158153 0.089 0.000 0.405 0.000 ninjabackend.py:129(<lambda>) 845 0.064 0.000 0.391 0.000 ninjabackend.py:279(get_target_generated_sources) 58161 0.070 0.000 0.317 0.000 backends.py:217(get_target_generated_dir) 216825 0.175 0.000 0.275 0.000 ninjabackend.py:48(ninja_quote) 845 0.058 0.000 0.255 0.000 ninjabackend.py:2289(guess_external_link_dependencies) 845 0.068 0.000 0.239 0.000 backends.py:793(get_custom_target_provided_libraries) 52101 0.030 0.000 0.237 0.000 compilers.py:716(append) 1319326 0.231 0.000 0.231 0.000 {built-in method builtins.isinstance} 1189117 0.229 0.000 0.229 0.000 {method 'startswith' of 'str' objects} 3235 0.102 0.000 0.228 0.000 compilers.py:614(to_native) Note: there are 845 build targets.
* Add method to check for C/C++ function attributesDylan Baker2018-09-071-1/+28
| | | | | | | | | | | | | | | It's fairly common on Linux and *BSD platforms to check for these attributes existence, so it makes sense to me to have this checking build into meson itself. Autotools also has a builtin for handling these, and by building them in we can short circuit cases that we know that these don't exist (MSVC). Additionally this adds support for two common MSVC __declspec attributes, dllimport and dllexport. This implements the declspec version (even though GCC has an __attribute__ version that both it and clang support), since GCC and Clang support the MSVC version as well. Thus it seems reasonable to assume that most projects will use the __declspec version over teh __attribute__ version.
* compilers: Reduce sizes of MSVC linked binariesOle André Vadla RavnÄs2018-08-221-1/+4
| | | | | | | | | | | - For optimization=s add /O1: Use Maximum Optimization (Favor Size), and remove /Os as it's implied by /O1. - Because we add /O1, this implies /Gy, i.e. Function-Level Linking, so unused code can be omitted. - Add /Gw: Optimize Global Data, so unused data can be omitted. With buildtype=minsize on x86 this reduces the size of a statically linked Vala compiler binary from 5 MB down to just 1.87 MB.
* find_library: Allow undefined symbols while linkingNirbheek Chauhan2018-08-221-1/+26
| | | | | Shared libraries may not always be linkable without the use of other libraries, so don't make it a linker error.
* find_library: Use _build_wrapper to get library dirsBruce Richardson2018-08-221-46/+38
| | | | | | | | | | This means that we will take into account all the flags set in the cross file when fetching the list of library dirs, which means we won't incorrectly look for 64-bit libraries when building for 32-bit. Signed-off-by: Nirbheek Chauhan <nirbheek@centricular.com> Closes https://github.com/mesonbuild/meson/issues/3881
* Convert buildtype to optimization and debug options (#3489)Jussi Pakkanen2018-08-181-5/+34
|
* Explicitly set the Windows subsystem for ninja/VisualCJon Turney2018-08-151-2/+7
|
* PkgConfigDependency: Don't try to resolve internal compiler libsNirbheek Chauhan2018-08-111-2/+9
| | | | | | | -lc -lm -ldl -lrt -lpthread are special linker arguments that should never be resolved to on-disk libraries. Closes https://github.com/mesonbuild/meson/issues/3879
* msvc: Don't add dynamic link args, they're ignoredNirbheek Chauhan2018-08-091-0/+3
| | | | And they print a linker warning about unknown args.
* PkgConfigDependency: Fix library path search orderNirbheek Chauhan2018-08-081-3/+4
| | | | | | | We were searching the library paths in the reverse order, which meant that we'd pick libraries from the wrong prefix. Closes https://github.com/mesonbuild/meson/issues/3951
* Merge pull request #3850 from mesonbuild/nirbheek/exe-wrapper-compiler-fallbacksJussi Pakkanen2018-07-311-3/+5
|\ | | | | Be more permissive about not-found exe_wrapper
| * cross: Be more permissive about not-found exe_wrappernirbheek/exe-wrapper-compiler-fallbacksNirbheek Chauhan2018-07-091-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We used to immediately try to use whatever exe_wrapper was defined in the cross file, but some people generate the cross file once and use it for several projects, most of which do not even need an exe wrapper to build. Now we're a bit more resilient. We quietly fall back to using non-exe-wrapper paths for compiler checks and skip the sanity check. However, if some code needs the exe wrapper, f.ex., if you run a built executable using custom_target() or run_target(), we will error out during setup. Tests will, of course, continue to error out when you run them if the exe wrapper was not found. We don't want people's tests to silently "pass" (aka skip) because of a bad CI setup. Closes https://github.com/mesonbuild/meson/issues/3562 This commit also adds a test for the behaviour of exe_wrapper in these cases, and refactors the unit tests a bit for it.
| * cross: Use ExternalProgram for cross-file exe_wrapperNirbheek Chauhan2018-07-091-5/+4
| | | | | | | | | | | | We already have code to fetch and find binaries specified in a cross file, so use the same code for exe_wrapper. This allows us to handle the same corner-cases that were fixed for other cross binaries.
* | find_library: Validate and sort globbed shared library filesNirbheek Chauhan2018-07-101-2/+19
| | | | | | | | | | | | | | We need to pick the library with the highest version, which is what the OpenBSD linker also does. https://github.com/mesonbuild/meson/issues/3570#issuecomment-403638752
* | Fix searching of shared libraries on OpenBSD (#3851)Nirbheek Chauhan2018-07-091-34/+74
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | * get_library_naming: Use templates instead of suffix/prefix pairs This commit does not change functionality, and merely sets the groundwork for a more flexibly naming implementation. * find_library: Fix manual searching on OpenBSD On OpenBSD, shared libraries are called libfoo.so.X.Y where X is the major version and Y is the minor version. We were assuming that it's libfoo.so and not finding shared libraries at all while doing manual searching, which meant we'd link statically instead. See: https://www.openbsd.org/faq/ports/specialtopics.html#SharedLibs Now we use file globbing to do searching, and pick the first one that's a real file. Closes https://github.com/mesonbuild/meson/issues/3844 * find_library: Fix priority of library search in OpenBSD Also add unit tests for the library naming function so that it's absolutely clear what the priority list of naming is. Testing is done with mocking on Linux to ensure that local testing is easy
* find_library: Only run link test on system dirsNirbheek Chauhan2018-07-041-11/+16
| | | | | | | Paths provided to us by the user or by pkg-config can be (and must be) assumed to be usable since they might not be usable standalone. Closes https://github.com/mesonbuild/meson/issues/3832