Last active
November 24, 2021 21:25
-
-
Save toots/1260687647c139f7a1e862bea924e9b1 to your computer and use it in GitHub Desktop.
Test dune configurator with cross-compilers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module C = Configurator.V1 | |
let () = | |
C.main ~name:"test-dune-configurator" (fun c -> | |
let has_alsa = | |
C.c_test c | |
{| | |
#include <alsa/asoundlib.h> | |
int main() { | |
snd_pcm_t *pcm_handle; | |
return 0; | |
} | |
|} | |
in | |
C.C_define.gen_header_file c ~fname:"config.h" | |
[ | |
("HAS_ALSA", Switch has_alsa); | |
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(library | |
(name test_dune_configurator) | |
(modules test_dune_configurator) | |
(foreign_stubs | |
(extra_deps config.h) | |
(language c) | |
(names test_dune_configurator))) | |
(executable | |
(name print_conf) | |
(modules print_conf) | |
(libraries test_dune_configurator)) | |
(executable | |
(name discover) | |
(modules discover) | |
(libraries dune.configurator)) | |
(rule | |
(targets config.h) | |
(action | |
(run ./discover.exe))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(lang dune 2.8) | |
(name test-dune-configurator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let () = | |
Printf.printf "System has alsa: %d\n%!" (Test_dune_configurator.has_alsa ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <caml/misc.h> | |
#include <caml/mlvalues.h> | |
#include <caml/memory.h> | |
#include "config.h" | |
CAMLprim value ocaml_test_dune_configurator_has_alsa(value unit) { | |
CAMLparam0(); | |
#ifdef HAS_ALSA | |
CAMLreturn(Val_int(1)); | |
#else | |
CAMLreturn(Val_int(0)); | |
#endif | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
external has_alsa : unit -> int = "ocaml_test_dune_configurator_has_alsa" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment