I want to run the C API example but the command
RUSTFLAGS=“-C target-cpu=native” cargo +nightly build --release --features=x86_64-unix,high-level-c-api -p tfhe
require a Cargo.toml file to install the tfhe header used in the example. I am new to rust and I will be glad if a simple Cargo.toml file for this command is provided.
I believe
tfhe = { version = “0.4.1”, features = [ “boolean”, “shortint”, “integer”, “x86_64-unix” ] }
is suppose to be a part of the file but what are the other things in it and where do I place the file ?
Hello @nges_89952 normally you just need to clone the repository and checkout the 0.4.1 tag and then run the command given in the example to get the tfhe libs and headers which you will find in the target dir.
Let us know if you manage to get things working !
Cheers and happy new year
1 Like
Thank you for the response. I have cloned and checkout. Then I have added
tfhe = { version = “*”, features = [“boolean”, “shortint”, “integer”, “x86_64-unix”] }
to the Cargo.toml.
In the tfhe-rs folder, I run
RUSTFLAGS=“-C target-cpu=native” cargo +nightly build --release --features=x86_64-unix,high-level-c-api -p tfhe
but still it does not build.
The first errors gotten are like;
error[E0425]: cannot find function safe_serialize
in module crate::high_level_api
→ tfhe/src/c_api/high_level_api/utils.rs:280:44
|
280 | crate::high_level_api::safe_serialize(&sself.0, &mut buffer, serialized_size_limit)
| ^^^^^^^^^^^^^^ not found in crate::high_level_api
and ends with:
warning: tfhe
(lib) generated 3 warnings
error: could not compile tfhe
(lib) due to 90 previous errors; 3 warnings emitted
Hello @nges_89952 could you share your code maybe ? I’m a bit confused as to what you have locally
I want to build the tfhe header in other to use it with the C example here.
Use the C API - TFHE-rs
I have a main.c with that code example, I also have a CMakeLists.txt as provided but I have changed the TFHE_C_API value to
set(TFHE_C_API “./tfhe-rs/tfhe/src”)
If I run make, I get an error saying that #include <tfhe.h> does not exist.
I believe, I need to build this tfhe and link it from the github.
If I clone the github, and I try to build it, the error above occurs.
I am not sure whether, I am doing the right thing.
@nges_89952 I think the path should be
set(TFHE_C_API “./tfhe-rs/target/release”)
you should not need to modify the Cargo.toml in ./tfhe-rs/tfhe
And I can confirm I see the same error you indicate with the command line you shared
can you try
RUSTFLAGS="-C target-cpu=native" cargo +nightly build --release --features=x86_64-unix,high-level-c-api,safe-deserialization -p tfhe
to compile the C API ?
It seems to be a small mistake on our end, we will fix it, thanks for reporting your problem !
1 Like
Ok and thank you for your help. I shall be waiting for updates.
Did you try the updated command I sent @nges_89952 ?
Yes, it builds.
but when I try to run the example, I get compilation errors.
It looks like most of the functions declarations have changed eg
error: implicit declaration of function ‘config_builder_enable_default_uint128_small’; did you mean ‘config_builder_enable_default_integers_small’? [-Werror=implicit-function-declaration]
17 | config_builder_enable_default_uint128_small(&builder);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| config_builder_enable_default_integers_small
main.c:34:55: error: incompatible type for argument 1 of ‘fhe_uint128_try_encrypt_with_client_key_u128’
34 | ok = fhe_uint128_try_encrypt_with_client_key_u128(10, 20, client_key, &lhs);
( first argument ( 10) should be ‘struct U128’
In ./tfhe-rs do
git checkout tfhe-rs-0.4.1
The documentation you see is for 0.4.x
Then re run the c api build and then your c project build
It still does not build with the checkout of tfhe-rs-0.4.1. The exact same error as above
Ok thanks for checking, we’ll be fixing those issues !
You relaunched the c api build just to be sure ?
Yes, I have double checked and it gives me the same issue.
1 Like
Thank you for checking, hopefully it’s not too hard to fix, will keep you posted !
1 Like
Hello @nges_89952
You can check the code here https://github.com/zama-ai/tfhe-rs/blob/4e3ee6d0c1a5b897291039393f5fc4d7f9de1fd9/tfhe/docs/how_to/c_api.md
It’s in a PR that will be merged for the 0.4.x branch and we will have the same fix for our main branch.
Normally if you use the code from the file I linked it should work ok, let me know how that goes
Cheers
1 Like
I have updated the code and rebuild the code. I get the error below
[ 50%] Building C object CMakeFiles/my-executable.dir/main.c.o
make[2]: *** No rule to make target 'tfhe-rs/target/release/libtfhe.a', needed by 'my-executable'. Stop.
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/my-executable.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
@nges_89952
I think you may have an issue with the path, I re-did what the documentation says and it works
try to set the absolute path in
set(TFHE_C_API "/absolute_path/to/tfhe-rs/target/release")
The C API should be already built of course