votingworks / electionguard-kotlin-multiplatform

An implementation of ElectionGuard version 2.0.0 in Kotlin.
MIT License
9 stars 5 forks source link

Cryspen HACL Packages #200

Open danwallach opened 2 years ago

danwallach commented 2 years ago

Possibly interesting: https://github.com/cryspen/hacl-packages https://blog.cryspen.com/blog/hacl-0_6/

So far as I can tell, the only thing that's actually new, from our perspective, is that they've gone to the trouble of getting HACL compiling and packaged up on every platform we care about. They don't seem to yet have their builds hosted so you can have a binary-only dependency, but they've figured out how to build with all the right flags on every platform. That's still a win, in terms of removing stuff from our repository.

Also kinda interesting: they've got OCaml bindings (which come from the original work at Microsoft), Rust (a directory full of code, but it's labeled "work in progress, don't use in production"), and JavaScript (claimed in the README, but no code present).

danwallach commented 2 years ago

Possible cmake incantation to fetch the source code and do a build:

FetchContent_Declare(hacl
        DOWNLOAD_EXTRACT_TIMESTAMP TRUE
        URL https://github.com/cryspen/hacl-packages/archive/refs/tags/c-v0.6.0.zip
    )
FetchContent_MakeAvailable(hacl)
danwallach commented 1 year ago

Using the above code doesn't work. You ultimately get this:

CMake Error at CMakeLists.txt:54 (include):
  include could not find requested file:

    build/config.cmake

CMake Error at CMakeLists.txt:76 (include):
  include could not find requested file:

    build/config.cmake

So, if you go to the Cryspen page, it talks about using a tool called mach, which is their own build front-end tool (written in Python). That file does manage to get installed, but if you run it with build, here's the output:

% _deps/hacl-src/mach build
 [mach] Dependency checks ...
 [mach] Probing for cmake: Found
 [mach] Probing for ninja: Found

 [mach] Running config to write config.cmake and config.h ...
 [mach] Using config/config.json to configure ...
Traceback (most recent call last):
  File "/Users/dwallach/IdeaProjects/electionguard-kotlin-multiplatform/hacllib/build/_deps/hacl-src/mach", line 476, in <module>
    main()
  File "/Users/dwallach/IdeaProjects/electionguard-kotlin-multiplatform/hacllib/build/_deps/hacl-src/mach", line 472, in main
    args.func(args)
  File "/Users/dwallach/IdeaProjects/electionguard-kotlin-multiplatform/hacllib/build/_deps/hacl-src/mach", line 368, in build
    config = Config(json_config(), source_dir, include_dir, compiler=compiler)
  File "/Users/dwallach/IdeaProjects/electionguard-kotlin-multiplatform/hacllib/build/_deps/hacl-src/tools/configure.py", line 109, in __init__
    with open(config_file, "r") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'config/config.json'
>> _deps/hacl-src/mach: 1

Okay, so do we have a config/config.json file somewhere? Yes. It's in there (_deps/hacl-src/config/config.json).

Hmmm.

danwallach commented 1 year ago

Okay, but if I just cloned their repo, completely separate from ElectionGuard, and ran ./mach build, then everything just magically worked. This suggests that they're not quite making things work correctly for interfacing with FetchContent.

franziskuskiefer commented 1 year ago

For reference, here's an example for how to use HACL packages in CMake on a branch that fixes the config issue https://github.com/cryspen/hacl-packages/tree/franziskus/cmake-standalone-build/examples/cmake