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

Invalid numeric argument '/Wextra' with MSVC, how to build with Clang? #571

Open
theoparis opened this issue Oct 24, 2024 · 9 comments
Open

Comments

@theoparis
Copy link

Problem:

I am trying to build facebook's buck2 project with updated dependencies with Clang on Windows, and aws-lc-sys seems to be trying to use msvc cl.exe instead of clang.exe which causes errors.

While it would be great if this msvc issue can be fixed, is there any way to force aws-lc-sys to use clang.exe or clang-cl.exe directly from LLVM instead of msvc cl.exe?

Relevant details

AWS-LC for Rust versions or commit: 92ffba9c29a34b22

System information: for linux, below info can be collected by running uname -srvmp

  • CPU architecture: (x86, x86-64, ARMv7...) x86_64
  • CPU name: (Xeon Platinum 8000, AMD EPYC 7000...) Ryzen 5600X
  • OS: (Ubuntu 20.04, Windows Server 2019...) Windows 10

Build log:

  • The log tells compiler and version.
  CMake Error at C:/toolchain/share/cmake-3.31/Modules/CMakeTestCCompiler.cmake:67 (message):
    The C compiler

      "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe"

    is not able to compile a simple test program.

    It fails with the following output:

      Change Dir: 'C:/Users/theo/Documents/buck2/target/release/build/aws-lc-sys-92ffba9c29a34b22/out/build/CMakeFiles/CMakeScratch/TryCompile-ey9jyx'

      Run Build Command(s): "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/MSBuild/Current/Bin/amd64/MSBuild.exe" cmTC_04b65.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=17.0 /v:n
      MSBuild version 17.11.9+a69bbaaf5 for .NET Framework
      Build started 10/23/2024 11:03:23 PM.

      Project "C:\Users\theo\Documents\buck2\target\release\build\aws-lc-sys-92ffba9c29a34b22\out\build\CMakeFiles\CMakeScratch\TryCompile-ey9jyx\cmTC_04b65.vcxproj" on node 1 (default targets).
      PrepareForBuild:
        Creating directory "cmTC_04b65.dir\Debug\".
        Structured output is enabled. The formatting of compiler diagnostics will reflect the error hierarchy. See https://aka.ms/cpp/structured-output for more details.
        Creating directory "C:\Users\theo\Documents\buck2\target\release\build\aws-lc-sys-92ffba9c29a34b22\out\build\CMakeFiles\CMakeScratch\TryCompile-ey9jyx\Debug\".
        Creating directory "cmTC_04b65.dir\Debug\cmTC_04b65.tlog\".
      InitializeBuildStatus:
        Creating "cmTC_04b65.dir\Debug\cmTC_04b65.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
        Touching "cmTC_04b65.dir\Debug\cmTC_04b65.tlog\unsuccessfulbuild".
      ClCompile:
        C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.41.34120\bin\HostX64\x64\CL.exe /c /I"C:\Users\theo\.cargo\registry\src\index.crates.io-6f17d22bba15001f\aws-lc-sys-0.22.0\generated-include" /I"C:\Users\theo\.cargo\registry\src\index.crates.io-6f17d22bba15001f\aws-lc-sys-0.22.0\include" /I"C:\Users\theo\.cargo\registry\src\index.crates.io-6f17d22bba15001f\aws-lc-sys-0.22.0\aws-lc\include" /I"C:\Users\theo\.cargo\registry\src\index.crates.io-6f17d22bba15001f\aws-lc-sys-0.22.0\aws-lc\third_party\s2n-bignum\include" /Zi /Wall /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D BORINGSSL_IMPLEMENTATION=1 /D BORINGSSL_PREFIX=aws_lc_0_22_0 /D "CMAKE_INTDIR=\"Debug\"" /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_04b65.dir\Debug\\" /Fd"cmTC_04b65.dir\Debug\vc143.pdb" /external:W4 /Gd /TC /errorReport:queue  --target=x86_64-pc-windows-msvc -ffunction-sections -fdata-sections -m64 --target=x86_64-pc-windows-msvc --target=x86_64-pc-windows-msvc -ffunction-sections -fdata-sections -m64 --target=x86_64-pc-windows-msvc -std=c11 -Wextra -Wno-unused-parameter -ffile-prefix-map=C:\Users\theo\.cargo\registry\src\index.crates.io-6f17d22bba15001f\aws-lc-sys-0.22.0= "C:\Users\theo\Documents\buck2\target\release\build\aws-lc-sys-92ffba9c29a34b22\out\build\CMakeFiles\CMakeScratch\TryCompile-ey9jyx\testCCompiler.c"
        Microsoft (R) C/C++ Optimizing Compiler Version 19.41.34123 for x64
        Copyright (C) Microsoft Corporation.  All rights reserved.
        cl /c /I"C:\Users\theo\.cargo\registry\src\index.crates.io-6f17d22bba15001f\aws-lc-sys-0.22.0\generated-include" /I"C:\Users\theo\.cargo\registry\src\index.crates.io-6f17d22bba15001f\aws-lc-sys-0.22.0\include" /I"C:\Users\theo\.cargo\registry\src\index.crates.io-6f17d22bba15001f\aws-lc-sys-0.22.0\aws-lc\include" /I"C:\Users\theo\.cargo\registry\src\index.crates.io-6f17d22bba15001f\aws-lc-sys-0.22.0\aws-lc\third_party\s2n-bignum\include" /Zi /Wall /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D BORINGSSL_IMPLEMENTATION=1 /D BORINGSSL_PREFIX=aws_lc_0_22_0 /D "CMAKE_INTDIR=\"Debug\"" /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_04b65.dir\Debug\\" /Fd"cmTC_04b65.dir\Debug\vc143.pdb" /external:W4 /Gd /TC /errorReport:queue  --target=x86_64-pc-windows-msvc -ffunction-sections -fdata-sections -m64 --target=x86_64-pc-windows-msvc --target=x86_64-pc-windows-msvc -ffunction-sections -fdata-sections -m64 --target=x86_64-pc-windows-msvc -std=c11 -Wextra -Wno-unused-parameter -ffile-prefix-map=C:\Users\theo\.cargo\registry\src\index.crates.io-6f17d22bba15001f\aws-lc-sys-0.22.0= "C:\Users\theo\Documents\buck2\target\release\build\aws-lc-sys-92ffba9c29a34b22\out\build\CMakeFiles\CMakeScratch\TryCompile-ey9jyx\testCCompiler.c"
      cl : command line  error D8021: invalid numeric argument '/Wextra' [C:\Users\theo\Documents\buck2\target\release\build\aws-lc-sys-92ffba9c29a34b22\out\build\CMakeFiles\CMakeScratch\TryCompile-ey9jyx\cmTC_04b65.vcxproj]
      Done Building Project "C:\Users\theo\Documents\buck2\target\release\build\aws-lc-sys-92ffba9c29a34b22\out\build\CMakeFiles\CMakeScratch\TryCompile-ey9jyx\cmTC_04b65.vcxproj" (default targets) -- FAILED.

      Build FAILED.

      "C:\Users\theo\Documents\buck2\target\release\build\aws-lc-sys-92ffba9c29a34b22\out\build\CMakeFiles\CMakeScratch\TryCompile-ey9jyx\cmTC_04b65.vcxproj" (default target) (1) ->
      (ClCompile target) ->
        cl : command line  error D8021: invalid numeric argument '/Wextra' [C:\Users\theo\Documents\buck2\target\release\build\aws-lc-sys-92ffba9c29a34b22\out\build\CMakeFiles\CMakeScratch\TryCompile-ey9jyx\cmTC_04b65.vcxproj]

          0 Warning(s)
@theoparis
Copy link
Author

theoparis commented Oct 25, 2024

Hm, setting the CMAKE_GENERATOR environment variable to Ninja fixes it. However I got this error:

o aws-lc/crypto/CMakeFiles/crypto_objects.dir/rand_extra/windows.c.obj -c C:/Users/theo/Documents/aws-lc-rs/aws-lc-sys/aws-lc/crypto/rand_extra/windows.c
  C:/Users/theo/Documents/aws-lc-rs/aws-lc-sys/aws-lc/crypto/rand_extra/windows.c:68:22: error: cast from 'FARPROC' (aka 'long long (*)()') to 'ProcessPrngFunction' (aka 'int (*)(unsigned char *, unsigned long long)') converts to incompatible function type [-Werror,-Wcast-function-type-mismatch]
     68 |   g_processprng_fn = (ProcessPrngFunction)GetProcAddress(hmod, "ProcessPrng");

Fixing that temporarily causes

error: could not find native static library `aws_lc_0_22_0_crypto`, perhaps an -L flag is missing?

and then I got this by appending lib to OutputLib::libname

          libaws_lc_sys-89975381c2bcfdcc.rlib(err.c.obj) : error LNK2019: unresolved external symbol __imp_strdup referenced in function aws_lc_0_22_0_ERR_set_error_data␍

@justsmth justsmth self-assigned this Oct 25, 2024
@justsmth justsmth added the build problem Build failure label Oct 25, 2024
@justsmth
Copy link
Contributor

Hello -- sorry for the delayed response.

Building for Windows x86-64 using clang (or clang-cl) is not something that we've done much testing for. This might require changes upstream in AWS-LC before this build setup would work for aws-lc-sys.

Thanks for letting us know about this. We'll keep this issue open until we've had a chance to investigate the issue. (Hopefully, soon!)

@justsmth
Copy link
Contributor

Looking quickly at this error -- I think this is due to an assumption that windows.c would only be built using an MSVC compiler.

...\windows.c:68:22: error: cast from 'FARPROC' (aka 'long long (*)()') to 'ProcessPrngFunction' (aka 'int (*)(unsigned char *, unsigned long long)') converts to incompatible function type [-Werror,-Wcast-function-type-mismatch]

We might need to change the preprocessor condition so it picks up this alternative: https://github.com/aws/aws-lc/blob/925f64262365f4e7f2169e265d1de1423329fe2a/crypto/rand_extra/windows.c#L36-L56

@leontoeides
Copy link

leontoeides commented Nov 3, 2024

Somewhat related, it looks like compilation could be failing on my Windows machine due to a space in the path. i.e. the path to cargo is "C:\Users\User Name\.cargo\registry..." where the build script is apparently trying to access "/Name/.cargo/registry/..."

@justsmth
Copy link
Contributor

justsmth commented Nov 4, 2024

Somewhat related, it looks like compilation could be failing on my Windows machine due to a space in the path.

Thanks for mentioning this. This should be tested. There are also problems when the path name generated by cargo gets too long. I found a meta-issue relating to Cargo's handling of Windows paths here: rust-lang/cargo#9770

@leontoeides
Copy link

leontoeides commented Nov 4, 2024

I could be wrong but I think the issue is with the aws-lc-sys build script and not with cargo ?

I did confirm this is an issue on my machine. If I change users so that the home directory has a path of "C:\Users\Username\.cargo.." (instead of "C:\Users\User Name\.cargo..") that this crate will build properly.

I also tried setting the environment variables to "%USERPROFILE%\.cargo" and "C:\Users\UserNa~1\.cargo" to workaround the apparent space problem, but it looks like both workarounds end up getting expanded to "C:\Users\User Name\.cargo" at some point and the built script fails anyway

@justsmth
Copy link
Contributor

This PR appears to address one of the issues reported above: aws/aws-lc#1972

@justsmth
Copy link
Contributor

Somewhat related, it looks like compilation could be failing on my Windows machine due to a space in the path. i.e. the path to cargo is "C:\Users\User Name.cargo\registry..." where the build script is apparently trying to access "/Name/.cargo/registry/..."

Hello @leontoeides -- The problem related to build failing when the path contains spaces should now be resolved with the release of aws-lc-rs v1.11.1. Please let us know if you continue to have problems with this after upgrading.

@justsmth
Copy link
Contributor

Hm, setting the CMAKE_GENERATOR environment variable to Ninja fixes it. However I got this error:

o aws-lc/crypto/CMakeFiles/crypto_objects.dir/rand_extra/windows.c.obj -c C:/Users/theo/Documents/aws-lc-rs/aws-lc-sys/aws-lc/crypto/rand_extra/windows.c
 C:/Users/theo/Documents/aws-lc-rs/aws-lc-sys/aws-lc/crypto/rand_extra/windows.c:68:22: error: cast from 'FARPROC' (aka 'long long (*)()') to 'ProcessPrngFunction' (aka 'int (*)(unsigned char *, unsigned long long)') converts to incompatible function type [-Werror,-Wcast-function-type-mismatch]
    68 |   g_processprng_fn = (ProcessPrngFunction)GetProcAddress(hmod, "ProcessPrng");

Hello @theoparis -- the compiler error related to ProcessPrngFunction should be resolved with aws-lc-rs v1.11.0. However, we've not had a chance to look into the subsequent linking errors that you had. We'll keep you updated! 😊

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

No branches or pull requests

3 participants