Crate rustls with CMake

Cargo.toml

[package]
name = "tls_client_01"
version = "0.1.0"
edition = "2024"

[dependencies]
rustls = "0.23.26"

... \tls_client_01\src\main.rs
use std::error::Error;
use std::io::{Read, Write};
use std::net::TcpStream;
use std::sync::Arc;

use rustls::client::{ClientConnectionData, EarlyDataError, UnbufferedClientConnection};
use rustls::unbuffered::{
    AppDataRecord, ConnectionState, EncodeError, EncryptError, InsufficientSizeError,
    UnbufferedStatus, WriteTraffic,
};
use rustls::version::TLS13;
use rustls::{ClientConfig, RootCertStore};

fn main() -> Result<(), Box<dyn Error>> {
    let root_store = RootCertStore {
        roots: webpki_roots::TLS_SERVER_ROOTS.into(),
    };

    let mut config = ClientConfig::builder_with_protocol_versions(&[&TLS13])
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
// full example, link:
// https://github.com/rustls/rustls/blob/main/examples/src/bin/unbuffered-client.rs

os win10_x64, cpu amd ryzen 5, rustc 1.86.0 (05f9846f8 2025-03-31)
on recommendation
download windows CMake & NASM installer

from cmd.exe

C:\Windows\system32>llvm-cov --version
LLVM (http://llvm.org/):
LLVM version 15.0.6
Optimized build.
Default target: x86_64-pc-windows-msvc
Host CPU: znver1

C:\Windows\system32>clang --version
clang version 15.0.6
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

from vs code

... \tls_client_01>$env:PATH
C:\Program Files\CMake\bin;
C:\Program Files\NASM;
C:\Program Files\LLVM\bin;;

... \tls_client_01>cmake --version
cmake version 4.0.1
CMake suite maintained and supported by Kitware.

... \tls_client_01>nasm --version
NASM version 2.16.03 compiled on Apr 17 2024

cargo run

... \tls_client_01> cargo run
Compiling aws-lc-sys v0.28.2
warning: aws-lc-sys@0.28.2: Building with: CMake
warning: aws-lc-sys@0.28.2: Symbol Prefix: Some("aws_lc_0_28_2")
warning: aws-lc-sys@0.28.2: Environment Variable found 'CMAKE': 'cmake'
warning: aws-lc-sys@0.28.2: CMAKE environment variable set: cmake
warning: aws-lc-sys@0.28.2: Compilation of 'c11.c' failed - Err(Error { kind: ToolExecError, message: "command did not execute successf
ully (status code exit code: 2): "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.35.
32215\\bin\\HostX64\\x64\\cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-WX" "-W4" "-FoC:\\my_all_folders\\tls_client_01\\target\\debug\\
build\\aws-lc-sys-3a085190e471557f\\out\\out-c11\\e1bacabfea35bee3-c11.o" "-c" "C:\\Users\\mgm\\.cargo\\registry\
\src\\index.crates.io-1949cf8c6b5b557f\\aws-lc-sys-0.28.2\\aws-lc\\tests\\compiler_features_tests\\c11.c"" }).
error: failed to run custom build command for aws-lc-sys v0.28.2

Caused by:
process didn't exit successfully: C:\my_all_folders\tls_client_01\target\debug\build\aws-lc-sys-850851bb3dd990bf\build-script-main (exit code: 101)
--- stdout
cargo:rerun-if-env-changed=AWS_LC_SYS_NO_PREFIX_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=AWS_LC_SYS_NO_PREFIX
...
...
cargo:rerun-if-env-changed=CMAKE_TOOLCHAIN_FILE
OPT_LEVEL = Some(0)
OUT_DIR = Some(C:\my_all_folders\tls_client_01\t
arget\debug\build\aws-lc-sys-3a085190e471557f\out)
TARGET = Some(x86_64-pc-windows-msvc)
cargo:rerun-if-env-changed=VCINSTALLDIR
VCINSTALLDIR = None
cargo:rerun-if-env-changed=VSTEL_MSBuildProjectFullPath
VSTEL_MSBuildProjectFullPath = None
cargo:rerun-if-env-changed=VSCMD_ARG_VCVARS_SPECTRE
VSCMD_ARG_VCVARS_SPECTRE = None
cargo:rerun-if-env-changed=WindowsSdkDir
WindowsSdkDir = None
cargo:rerun-if-env-changed=WindowsSDKVersion
WindowsSDKVersion = None
cargo:rerun-if-env-changed=LIB
LIB = None
PATH = Some(... ...;
C:\Program Files\CMake\bin;
C:\Program Files\NASM;... ...)
...
...
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\include\vcruntime_c11_stdatomic.h(122): error C2059
: syntax error: '}'
...
...
HOST_CMAKE = None
CMAKE = Some("cmake")
running: "cmake" "C:\Users\mgm\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\aws-lc-sys-0.28.2" "-G" "Visual Studio 17
2022" "-Thost=x64" "-Ax64" "-DBUILD_SHARED_LIBS=0" "-DBORINGSSL_PREFIX=aws_lc_0_28_2_" "-DBORINGSSL_PREFIX_HEADERS=C:\Users\mgm\.c
argo\registry\src\index.crates.io-1949cf8c6b5b557f\aws-lc-sys-0.28.2\generated-include" "-DBUILD_TESTING=OFF" "-DBUILD_TOOL=OFF" "
-DBUILD_LIBSSL=OFF" "-DDISABLE_PERL=ON" "-DDISABLE_GO=ON" "-DCMAKE_C_STANDARD=99" "-DCMAKE_INSTALL_PREFIX=C:\my_all_folders\tls_client_01\target\debug\build\aws-lc-sys-3a08
5190e471557f\out" "-DCMAKE_C_FLAGS= -nologo -MD -Brepro" "-DCMAKE_C_FLAGS_DEBUG= -nologo -MD -Brepro" "-DCMAKE_CXX_FLAGS= -nologo -MD
-Brepro" "-DCMAKE_CXX_FLAGS_DEBUG= -nologo -MD -Brepro" "-DCMAKE_ASM_FLAGS= -nologo -MD -Brepro" "-DCMAKE_ASM_FLAGS_DEBUG= -nologo -MD
-Brepro" "-DCMAKE_BUILD_TYPE=Debug" "--no-warn-unused-cli"
Not searching for unused variables given on the command line.
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.17763.
-- The C compiler identification is unknown
-- Configuring incomplete, errors occurred!

--- stderr
CMake Deprecation Warning at CMakeLists.txt:10 (cmake_policy):
The OLD behavior for policy CMP0091 will be removed from a future version
of CMake.

The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances.  Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.

CMake Error at CMakeLists.txt:14 (enable_language):
No CMAKE_C_COMPILER could be found.

thread 'main' panicked at C:\Users\mgm\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\cmake-0.1.54\src\lib.rs:1119:5:

command did not execute successfully, got: exit code: 1

build script failed, must exit now
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

My list of environment Path variables not contain "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\bin".
Other comments are also not clear how to solve. Help, pls.

The cmake-rs crate uses heuristics to locate the default msvc cl compiler. It doesn't have to be in your PATH. The error is from vcruntime_c11_stdatomic.h, which appears that msvc requires an experimental flag.

You can try setting the CC and CXX compilers.
In cmd.exe:

set CC=clang
set CXX=clang

If you have Ninja installed, you can also set it as the CMAKE_GENERATOR env variable (for good measure):

set CMAKE_GENERATOR=Ninja

Then cargo clean && cargo run.

1 Like

, thanks for help, after reboot:

from cmd.exe

C:\Windows\system32>set

CC=clang
CXX=clang
LIBCLANG_PATH=C:\Program Files\LLVM\lib

Path=

C:\Program Files\CMake\bin;
C:\Program Files\NASM;
C:\Program Files\LLVM\bin

cargo run

... \tls_client_01> cargo run
Compiling aws-lc-sys v0.28.2
warning: aws-lc-sys@0.28.2: Building with: CMake
warning: aws-lc-sys@0.28.2: Symbol Prefix: Some("aws_lc_0_28_2")
warning: aws-lc-sys@0.28.2: Environment Variable found 'CMAKE': 'cmake'
warning: aws-lc-sys@0.28.2: CMAKE environment variable set: cmake
warning: aws-lc-sys@0.28.2: Compilation of 'c11.c' succeeded - Ok(["C:\my_all_folders\tls_client_01\target\debug\build\aws-lc-sys-3a085190e471557f\out\out-c11\e1bacabfea
35bee3-c11.o"]).
warning: aws-lc-sys@0.28.2: Environment Variable found 'CC': 'clang'
warning: aws-lc-sys@0.28.2: Setting CC_x86_64_pc_windows_msvc: clang
warning: aws-lc-sys@0.28.2: Environment Variable found 'CXX': 'clang'
warning: aws-lc-sys@0.28.2: Setting CXX_x86_64_pc_windows_msvc: clang
error: failed to run custom build command for aws-lc-sys v0.28.2

Caused by:
process didn't exit successfully: C:\my_all_folders\tls_client_01\target\debug\build\aws-lc-sys-850851bb3dd990bf\build-script-main (exit code: 101)
--- stdout
cargo:rerun-if-env-changed=AWS_LC_SYS_NO_PREFIX_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=AWS_LC_SYS_NO_PREFIX
cargo:rerun-if-env-changed=AWS_LC_SYS_PREGENERATING_BINDINGS_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=AWS_LC_SYS_PREGENERATING_BINDINGS
cargo:rerun-if-env-changed=AWS_LC_SYS_EXTERNAL_BINDGEN_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=AWS_LC_SYS_EXTERNAL_BINDGEN
cargo:rerun-if-env-changed=AWS_LC_SYS_NO_ASM_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=AWS_LC_SYS_NO_ASM
...
...
OPT_LEVEL = Some(0)
OUT_DIR = Some(C:\my_all_folders\tls_client_01\t
arget\debug\build\aws-lc-sys-3a085190e471557f\out)
TARGET = Some(x86_64-pc-windows-msvc)
cargo:rerun-if-env-changed=VCINSTALLDIR
...
...
PATH = Some(...
C:\Program Files\CMake\bin;
C:\ProgramFiles\NASM;
C:\Program Files\LLVM\bin;;
...)
cargo:rerun-if-env-changed=INCLUDE
INCLUDE = None
...
...
HOST_CMAKE_PREFIX_PATH = None
CMAKE_PREFIX_PATH = None
CMAKE_x86_64-pc-windows-msvc = None
CMAKE_x86_64_pc_windows_msvc = None
HOST_CMAKE = None
CMAKE = Some("cmake")
running: "cmake" "C:\Users\mgm\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\aws-lc-sys-0.28.2" "-G" "Visual Studio 17
2022" "-Thost=x64" "-Ax64" "-DBUILD_SHARED_LIBS=0" "-DBORINGSSL_PREFIX=aws_lc_0_28_2_" "-DBORINGSSL_PREFIX_HEADERS=C:\Users\mgm\.c
argo\registry\src\index.crates.io-1949cf8c6b5b557f\aws-lc-sys-0.28.2\generated-include" "-DBUILD_TESTING=OFF" "-DBUILD_TOOL=OFF" "
-DBUILD_LIBSSL=OFF" "-DDISABLE_PERL=ON" "-DDISABLE_GO=ON" "-DCMAKE_C_STANDARD=11" "-DCMAKE_INSTALL_PREFIX=C:\my_all_folders\tls_client_01\target\debug\build\aws-lc-sys-3a08
5190e471557f\out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -m64 --target=x86_64-pc-windows-msvc" "-DCMAKE_C_FLAGS_DEBUG=
-ffunction-sections -fdata-sections -m64 --target=x86_64-pc-windows-msvc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -m64
--target=x86_64-pc-windows-msvc" "-DCMAKE_CXX_FLAGS_DEBUG= -ffunction-sections -fdata-sections -m64 --target=x86_64-pc-windows-msvc" "-
DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -m64 --target=x86_64-pc-windows-msvc" "-DCMAKE_ASM_FLAGS_DEBUG= -ffunction-sectio
ns -fdata-sections -m64 --target=x86_64-pc-windows-msvc" "-DCMAKE_BUILD_TYPE=Debug" "--no-warn-unused-cli"
Not searching for unused variables given on the command line.
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.17763.
-- The C compiler identification is unknown
-- Configuring incomplete, errors occurred!

--- stderr
CMake Deprecation Warning at CMakeLists.txt:10 (cmake_policy):
The OLD behavior for policy CMP0091 will be removed from a future version
of CMake.

The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances.  Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.

CMake Error at CMakeLists.txt:14 (enable_language):
No CMAKE_C_COMPILER could be found.

thread 'main' panicked at C:\Users\mgm\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\cmake-0.1.54\src\lib.rs:1119:5:

command did not execute successfully, got: exit code: 1

build script failed, must exit now
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

how to solve this
CMake Deprecation Warning at CMakeLists.txt:10 (cmake_policy):
The OLD behavior for policy CMP0091 will be removed from a future version
of CMake.
CMake Error at CMakeLists.txt:14 (enable_language):
No CMAKE_C_COMPILER could be found.
reinstall to a new version?

where to watch this
Warning at
CMakeLists.txt:10
CMakeLists.txt:14

This seems related to several issues opened in aws-lc-rs:

I would still try with installing Ninja and setting it as the CMAKE_GENERATOR, and would try with both clang and clang-cl.

set CC=clang
set CXX=clang
set CMAKE_GENERATOR=Ninja
cargo clean && cargo run

# if that didn’t work

set CC=clang-cl
set CXX=clang-cl
set CMAKE_GENERATOR=Ninja
cargo clean && cargo run

If both didn’t work I would report it upstream as well (in one of the open issues).

1 Like
reinstall llvm from version `15.0.6` to `20.1.0`

vs powershell

... \tls_client_01> llvm-cov --version
LLVM (http://llvm.org/):
LLVM version 20.1.0
Optimized build.

cmd.exe

C:\Windows\system32>set
...
CC=clang
CMAKE_GENERATOR=Ninja
CXX=clang
LIBCLANG_PATH=C:\Program Files\LLVM\lib
...
Path= ...;
C:\Program Files\NASM;
C:\Program Files\LLVM\bin;
C:\ProgramFiles\CMake\bin;
...

cargo run

... \tls_client_01> cargo run
Compiling aws-lc-sys v0.28.2
warning: aws-lc-sys@0.28.2: Building with: CMake
warning: aws-lc-sys@0.28.2: Symbol Prefix: Some("aws_lc_0_28_2")
warning: aws-lc-sys@0.28.2: Environment Variable found 'CMAKE': 'cmake'
warning: aws-lc-sys@0.28.2: CMAKE environment variable set: cmake
warning: aws-lc-sys@0.28.2: Environment Variable found 'CMAKE_GENERATOR': 'Ninja'
warning: aws-lc-sys@0.28.2: Setting CMAKE_GENERATOR: Ninja
warning: aws-lc-sys@0.28.2: Compilation of 'c11.c' succeeded - Ok(["C:\my_all_folders\tls_client_01\target\debug\build\aws-lc-sys-3a085190e471557f\out\out-c11\e1bacabfea35
bee3-c11.o"]).
warning: aws-lc-sys@0.28.2: Environment Variable found 'CC': 'clang'
warning: aws-lc-sys@0.28.2: Setting CC_x86_64_pc_windows_msvc: clang
warning: aws-lc-sys@0.28.2: Environment Variable found 'CXX': 'clang'
warning: aws-lc-sys@0.28.2: Setting CXX_x86_64_pc_windows_msvc: clang
error: failed to run custom build command for aws-lc-sys v0.28.2

Caused by:
process didn't exit successfully: C:\my_all_folders\tls_client_01\target\debug\build\aws-lc-sys-850851bb3dd990bf\build-script-main (exit code: 101)

--- stdout
cargo:rerun-if-env-changed=AWS_LC_SYS_NO_PREFIX_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=AWS_LC_SYS_NO_PREFIX
...
...
cargo:warning=Compilation of 'c11.c' succeeded - Ok(["C:\my_all_folders\tls_client_01\target\debug\build\aws-lc-sys-3a085190e471557f\out\out-c11\e1bacabfea35bee3-c11.o"]
).
cargo:rerun-if-env-changed=AWS_LC_SYS_CC_x86_64_pc_windows_msvc
cargo:rerun-if-env-changed=AWS_LC_SYS_CC
...
...
CMAKE_PREFIX_PATH = None
CMAKE_x86_64-pc-windows-msvc = None
CMAKE_x86_64_pc_windows_msvc = None
HOST_CMAKE = None
CMAKE = Some("cmake")
running: "cmake" "C:\Users\mgm\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\aws-lc-sys-0.28.2" "-G" "Ninja" "-DBUILD_S
HARED_LIBS=0" "-DBORINGSSL_PREFIX=aws_lc_0_28_2_" "-DBORINGSSL_PREFIX_HEADERS=C:\Users\mgm\.cargo\registry\src\index.crates.io-19
49cf8c6b5b557f\aws-lc-sys-0.28.2\generated-include" "-DBUILD_TESTING=OFF" "-DBUILD_TOOL=OFF" "-DBUILD_LIBSSL=OFF" "-DDISABLE_PERL=ON"
"-DDISABLE_GO=ON" "-DCMAKE_C_STANDARD=11" "-DCMAKE_INSTALL_PREFIX=C:\my_all_folders\tls_client_01\target\debug\build\aws-lc-sys-3a085190e471557f\out" "-DCMAKE_C_FLAGS= -ffun
ction-sections -fdata-sections -m64 --target=x86_64-pc-windows-msvc" "-DCMAKE_C_COMPILER=clang" "-DCMAKE_CXX_FLAGS= -ffunction-sections
-fdata-sections -m64 --target=x86_64-pc-windows-msvc" "-DCMAKE_CXX_COMPILER=clang" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sectio
ns -m64 --target=x86_64-pc-windows-msvc" "-DCMAKE_ASM_COMPILER=clang" "-DCMAKE_BUILD_TYPE=Debug" "--no-warn-unused-cli"
Not searching for unused variables given on the command line.

--- stderr
CMake Error: Error: generator : Ninja
Does not match the generator used previously: Visual Studio 17 2022
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.

thread 'main' panicked at C:\Users\mgm\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\cmake-0.1.54\src\lib.rs:1119:5:

command did not execute successfully, got: exit code: 1

build script failed, must exit now
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

rename CMakeFiles directory to CMakeFiles_arch_01 and
C:\my_all_folders\tls_client_01\target\debug\build\aws-lc-sys-3a085190e471557f\out\build\CMakeCache.txt
to
... \CMakeCache_arch_01.txt

after restart (new CMakeFiles & CMakeCache.txt were created)
returned to old error:

CMake Deprecation Warning at CMakeLists.txt:10 (cmake_policy):
The OLD behavior for policy CMP0091 will be removed from a future version
of CMake.

with more comments also `clang-cl` did not work
set CC=clang-cl
set CXX=clang-cl
set CMAKE_GENERATOR=Ninja
cargo clean && cargo run

C:\my_all_folders\tls_client_01\src\main.rs
my_all_folders actually
has spaces in directory names,
is this not a problem by any chance?

What else can be done?
Thanks.

If you’re only getting this with clang and ninja, that means the build is succeeding. You can’t do much for this warning, it has to be fixed upstream.

1 Like

After some corrections and version updates,
also made a short path:

>cargo clean; cargo run

PS C:\rust_with_short_path\r01> cargo clean;
Removed 601 files, 78.4MiB total
PS C:\rust_with_short_path\r01> cargo run
Compiling getrandom v0.3.3
Compiling cfg-if v1.0.0
Compiling shlex v1.3.0
Compiling fs_extra v1.3.0
Compiling dunce v1.0.5
Compiling aws-lc-rs v1.13.1
Compiling zeroize v1.8.1
Compiling untrusted v0.7.1
Compiling rustls v0.23.27
Compiling untrusted v0.9.0
Compiling log v0.4.27
Compiling once_cell v1.21.3
Compiling subtle v2.6.1
Compiling rustls-pki-types v1.12.0
Compiling jobserver v0.1.33
Compiling cc v1.2.22
Compiling cmake v0.1.54
Compiling aws-lc-sys v0.29.0
error: could not find native static library aws_lc_0_29_0_crypto, perhaps an -L flag is missing?

warning: aws-lc-sys@0.29.0: Building with: CMake
warning: aws-lc-sys@0.29.0: Symbol Prefix: Some("aws_lc_0_29_0")
warning: aws-lc-sys@0.29.0: Environment Variable found 'CMAKE': 'cmake'
warning: aws-lc-sys@0.29.0: CMAKE environment variable set: cmake
warning: aws-lc-sys@0.29.0: Environment Variable found 'CMAKE_GENERATOR': 'Ninja'
warning: aws-lc-sys@0.29.0: Setting CMAKE_GENERATOR: Ninja
warning: aws-lc-sys@0.29.0: Compilation of 'c11.c' succeeded - Ok(["C:\rust_with_short_path\r01\target\debug\build\aws-lc-sys-57
da420fe85cde99\out\out-c11\e1bacabfea35bee3-c11.o"]).
warning: aws-lc-sys@0.29.0: Environment Variable found 'CC': 'clang'
warning: aws-lc-sys@0.29.0: Setting CC_x86_64_pc_windows_msvc: clang
warning: aws-lc-sys@0.29.0: Environment Variable found 'CXX': 'clang'
warning: aws-lc-sys@0.29.0: Setting CXX_x86_64_pc_windows_msvc: clang
error: could not compile aws-lc-sys (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
PS C:\rust_with_short_path\r01>

^___ image

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

error: could not compile aws-lc-sys (lib) due to 1 previous error

how to fix error?