This commit is contained in:
parent
aa2ff7b2f0
commit
2f3113f55d
11742 changed files with 1223940 additions and 0 deletions
|
|
@ -0,0 +1,26 @@
|
|||
module C = Configurator.V1
|
||||
|
||||
let unix = {|
|
||||
#include <math.h>
|
||||
void *addr = &sin;
|
||||
int main(void) {
|
||||
return 0;
|
||||
}
|
||||
|}
|
||||
|
||||
let windows = {|
|
||||
#include <winsock2.h>
|
||||
void *addr = &gethostname;
|
||||
int main(void) {
|
||||
return 0;
|
||||
}
|
||||
|}
|
||||
|
||||
let main c =
|
||||
let code = if Sys.os_type = "Win32" then windows else unix in
|
||||
let b = C.c_test c code in
|
||||
let f = open_out_bin "out" in
|
||||
output_char f (if b then '1' else '0');
|
||||
close_out f
|
||||
|
||||
let () = C.main ~name:"configurator-c-libraries" main
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(executable
|
||||
(name discover)
|
||||
(libraries dune.configurator))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 2.8)
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
Test that configurator always picks the value of the `c_libraries`
|
||||
flag from `ocamlc -config`. If not, there's a failure to link a
|
||||
configuration test program that uses functions from these libraries.
|
||||
For that, we need functions outside of libc. On Unix, that would be
|
||||
`sin(3)` that requires the `-lm` flag for the math library, and on
|
||||
Windows `gethostname` that requires WinSock2 (`ws2_32.dll`).
|
||||
|
||||
link successfully
|
||||
==================================
|
||||
|
||||
$ dune exec -- ./discover.exe
|
||||
$ cat out
|
||||
1
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
let () =
|
||||
let module C = Configurator.V1 in
|
||||
C.main ~name:"foo" (fun _c ->
|
||||
C.Flags.write_lines "foo" ["asdf"])
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(executable
|
||||
(name discover)
|
||||
(modules discover)
|
||||
(libraries dune.configurator))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 1.1)
|
||||
|
|
@ -0,0 +1 @@
|
|||
$ dune exec ./discover.exe
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(executable
|
||||
(name run)
|
||||
(libraries dune.configurator))
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
module Configurator = Configurator.V1
|
||||
|
||||
let () =
|
||||
Configurator.main ~name:"c_test" (fun t ->
|
||||
let c_result =
|
||||
Configurator.c_test t {c|
|
||||
#include <stdio.h>
|
||||
int main(void)
|
||||
{
|
||||
printf("Hello, World!");
|
||||
return 0;
|
||||
}
|
||||
|c} in
|
||||
assert c_result;
|
||||
print_endline "Successfully compiled c program"
|
||||
)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(executable
|
||||
(name run)
|
||||
(libraries dune.configurator))
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
module Configurator = Configurator.V1
|
||||
|
||||
let () =
|
||||
begin match Sys.getenv "INSIDE_DUNE" with
|
||||
| exception Not_found -> failwith "INSIDE_DUNE is not passed"
|
||||
| "1" -> print_endline "INSIDE_DUNE is from an old dune"
|
||||
| dir -> print_endline "INSIDE_DUNE is present";
|
||||
let config_path = ".dune/configurator.v2" in
|
||||
Printf.printf "%s file is %s\n" config_path
|
||||
(if Sys.file_exists (Filename.concat dir config_path) then
|
||||
"present"
|
||||
else
|
||||
"not present")
|
||||
end;
|
||||
Configurator.main ~name:"config" (fun t ->
|
||||
match Configurator.ocaml_config_var t "version" with
|
||||
| None -> failwith "version is absent"
|
||||
| Some _ -> print_endline "version is present"
|
||||
)
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 1.0)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(executable
|
||||
(name run)
|
||||
(libraries dune.configurator))
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
module Configurator = Configurator.V1
|
||||
|
||||
let () =
|
||||
let module C_define = Configurator.C_define in
|
||||
Configurator.main ~name:"c_test" (fun t ->
|
||||
C_define.import t
|
||||
~prelude:"#define CONFIGURATOR_TESTING \"foobar\"\n\
|
||||
#define CONFIGURATOR_NEG_INT -127\n"
|
||||
~includes:["caml/config.h"]
|
||||
[ "CAML_CONFIG_H", C_define.Type.Switch
|
||||
; "Page_log", C_define.Type.Int
|
||||
; "CONFIGURATOR_TESTING", C_define.Type.String
|
||||
; "CONFIGURATOR_NEG_INT", C_define.Type.Int
|
||||
; "sizeof(char)", C_define.Type.Int
|
||||
]
|
||||
|> List.iter (fun (n, v) ->
|
||||
Printf.printf "%s=%s\n"
|
||||
n (match v with
|
||||
| C_define.Value.String s -> s
|
||||
| Int i -> string_of_int i
|
||||
| Switch b -> string_of_bool b
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
Show that config values are present
|
||||
$ dune exec config/run.exe
|
||||
INSIDE_DUNE is present
|
||||
.dune/configurator.v2 file is present
|
||||
version is present
|
||||
|
||||
We're able to compile C program successfully
|
||||
$ dune exec c_test/run.exe
|
||||
Successfully compiled c program
|
||||
|
||||
Importing #define's from code is successful
|
||||
$ dune exec import-define/run.exe
|
||||
CAML_CONFIG_H=true
|
||||
Page_log=12
|
||||
CONFIGURATOR_TESTING=foobar
|
||||
CONFIGURATOR_NEG_INT=-127
|
||||
sizeof(char)=1
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
(cram
|
||||
(deps
|
||||
(package dune)
|
||||
(package dune-configurator)))
|
||||
|
||||
(cram
|
||||
(applies_to pkg-config-quoting)
|
||||
(deps %{bin:pkg-config}))
|
||||
|
||||
(cram
|
||||
(enabled_if
|
||||
(<> %{ocaml-config:system} win))
|
||||
(applies_to configurator.t))
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
(*
|
||||
* OWL - OCaml Scientific and Engineering Computing
|
||||
* Copyright (c) 2016-2022 Liang Wang <liang@ocaml.xyz>
|
||||
*)
|
||||
|
||||
module Configurator = Configurator.V1
|
||||
|
||||
let header = {|
|
||||
#define TEST "test"
|
||||
|}
|
||||
|
||||
let default_cflags c =
|
||||
let test =
|
||||
let headerfile =
|
||||
let file, fd =
|
||||
Filename.open_temp_file ~mode:[ Open_wronly ] "discover" "test.h"
|
||||
in
|
||||
output_string fd header;
|
||||
close_out fd;
|
||||
file
|
||||
in
|
||||
let platform =
|
||||
assert (Sys.file_exists headerfile);
|
||||
Configurator.C_define.import c ~includes:[ headerfile ] [ ("TEST", String) ]
|
||||
in
|
||||
match List.map snd platform with
|
||||
| [ String "test" ] -> `test
|
||||
| _ -> `unknown
|
||||
in
|
||||
match test with `test -> [] | _ -> assert false
|
||||
|
||||
let () =
|
||||
let flags_file = ref "" in
|
||||
let args = ["-target", Arg.Set_string flags_file , "flags file"] in
|
||||
Configurator.main ~args ~name:"test" (fun c ->
|
||||
let libs = [] in
|
||||
let cflags = default_cflags c in
|
||||
let conf : Configurator.Pkg_config.package_conf = { cflags; libs } in
|
||||
Configurator.Flags.write_sexp !flags_file conf.cflags)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(executable
|
||||
(name configure)
|
||||
(libraries dune.configurator))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(rule
|
||||
(targets c_flags.sexp)
|
||||
(action (run configure/configure.exe -target %{targets})))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 2.0)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
Test that dune-configurator's `C_define.import` is able to include
|
||||
custom header files correctly.
|
||||
|
||||
C_define.import functions properly
|
||||
====================================================================
|
||||
$ dune build ./c_flags.sexp
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module C = Configurator.V1
|
||||
|
||||
|
||||
let () =
|
||||
C.main ~name:"config_test" (fun t ->
|
||||
let pkg_config =
|
||||
match C.Pkg_config.get t with
|
||||
| None -> assert false
|
||||
| Some p -> p
|
||||
in
|
||||
let query package = ignore (C.Pkg_config.query pkg_config ~package) in
|
||||
query "dummy-pkg";
|
||||
)
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
(executable
|
||||
(name pkgconf)
|
||||
(modules pkgconf))
|
||||
|
||||
(env
|
||||
(_
|
||||
(binaries
|
||||
(./pkgconf.exe as pkgconf))))
|
||||
|
||||
(executable
|
||||
(name config_test)
|
||||
(libraries dune.configurator)
|
||||
(modules config_test))
|
||||
|
||||
(rule
|
||||
(alias default)
|
||||
(deps %{bin:pkgconf})
|
||||
(action
|
||||
(run ./config_test.exe -verbose)))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 3.8)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(* We'd like to use String.equal but that's OCaml >= 4.03 *)
|
||||
let not_flag x = not ("--print-errors" = x)
|
||||
|
||||
let () =
|
||||
let args = List.tl (Array.to_list Sys.argv) in
|
||||
let args = List.filter not_flag args in
|
||||
Format.printf "@[<v>%a@]@."
|
||||
(Format.pp_print_list Format.pp_print_string) args
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
$ unset PKG_CONFIG_ARGN
|
||||
$ unset PKG_CONFIG
|
||||
|
||||
These tests show that setting `PKG_CONFIG_ARGN` passes extra args to `pkg-config`
|
||||
|
||||
$ dune build 2>&1 | awk '/run:.*bin\/pkgconf/{a=1}/stderr/{a=0}a' | sed s/$(ocamlc -config | sed -n "/^target:/ {s/target: //; p; }")/\$TARGET/g
|
||||
run: $TESTCASE_ROOT/_build/default/.bin/pkgconf --personality $TARGET --print-errors dummy-pkg
|
||||
-> process exited with code 0
|
||||
-> stdout:
|
||||
| --personality
|
||||
| $TARGET
|
||||
| dummy-pkg
|
||||
run: $TESTCASE_ROOT/_build/default/.bin/pkgconf --personality $TARGET --cflags dummy-pkg
|
||||
-> process exited with code 0
|
||||
-> stdout:
|
||||
| --personality
|
||||
| $TARGET
|
||||
| --cflags
|
||||
| dummy-pkg
|
||||
run: $TESTCASE_ROOT/_build/default/.bin/pkgconf --personality $TARGET --libs dummy-pkg
|
||||
-> process exited with code 0
|
||||
-> stdout:
|
||||
| --personality
|
||||
| $TARGET
|
||||
| --libs
|
||||
| dummy-pkg
|
||||
|
||||
$ dune clean
|
||||
$ PKG_CONFIG_ARGN="--static" dune build 2>&1 | awk '/run:.*bin\/pkgconf/{a=1}/stderr/{a=0}a'
|
||||
run: $TESTCASE_ROOT/_build/default/.bin/pkgconf --static --print-errors dummy-pkg
|
||||
-> process exited with code 0
|
||||
-> stdout:
|
||||
| --static
|
||||
| dummy-pkg
|
||||
run: $TESTCASE_ROOT/_build/default/.bin/pkgconf --static --cflags dummy-pkg
|
||||
-> process exited with code 0
|
||||
-> stdout:
|
||||
| --static
|
||||
| --cflags
|
||||
| dummy-pkg
|
||||
run: $TESTCASE_ROOT/_build/default/.bin/pkgconf --static --libs dummy-pkg
|
||||
-> process exited with code 0
|
||||
-> stdout:
|
||||
| --static
|
||||
| --libs
|
||||
| dummy-pkg
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
module C = Configurator.V1
|
||||
|
||||
|
||||
let () =
|
||||
C.main ~name:"config_test" (fun t ->
|
||||
let pkg_config =
|
||||
match C.Pkg_config.get t with
|
||||
| None -> assert false
|
||||
| Some p -> p
|
||||
in
|
||||
let query package = ignore (C.Pkg_config.query pkg_config ~package) in
|
||||
query "gtk+-quartz-3.0";
|
||||
query "gtk+-quartz-3.0 >= 3.18";
|
||||
query "gtksourceview-3.0 >= 3.18"
|
||||
)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
(executable
|
||||
(name pkg_config)
|
||||
(public_name pkg-config)
|
||||
(modules pkg_config))
|
||||
|
||||
(executable
|
||||
(name config_test)
|
||||
(libraries dune.configurator)
|
||||
(modules config_test))
|
||||
|
||||
(alias
|
||||
(name default)
|
||||
(deps (package pkg-config))
|
||||
(action (run ./config_test.exe -verbose)))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 1.7)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(* We'd like to use String.equal but that's OCaml >= 4.03 *)
|
||||
let not_flag x = not ("--print-errors" = x)
|
||||
|
||||
let () =
|
||||
let args = List.tl (Array.to_list Sys.argv) in
|
||||
let args = List.filter not_flag args in
|
||||
Format.printf "@[<v>%a@]@."
|
||||
(Format.pp_print_list Format.pp_print_string) args
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
These tests show how various pkg-config invocations get quotes (and test specifying a custom PKG_CONFIG):
|
||||
$ PKG_CONFIG=$PWD/_build/install/default/bin/pkg-config dune build 2>&1 | awk '/run:.*bin\/pkg-config/{a=1}/stderr/{a=0}a'
|
||||
run: $TESTCASE_ROOT/_build/install/default/bin/pkg-config --print-errors gtk+-quartz-3.0
|
||||
-> process exited with code 0
|
||||
-> stdout:
|
||||
| gtk+-quartz-3.0
|
||||
run: $TESTCASE_ROOT/_build/install/default/bin/pkg-config --cflags gtk+-quartz-3.0
|
||||
-> process exited with code 0
|
||||
-> stdout:
|
||||
| --cflags
|
||||
| gtk+-quartz-3.0
|
||||
run: $TESTCASE_ROOT/_build/install/default/bin/pkg-config --libs gtk+-quartz-3.0
|
||||
-> process exited with code 0
|
||||
-> stdout:
|
||||
| --libs
|
||||
| gtk+-quartz-3.0
|
||||
run: $TESTCASE_ROOT/_build/install/default/bin/pkg-config --print-errors 'gtk+-quartz-3.0 >= 3.18'
|
||||
-> process exited with code 0
|
||||
-> stdout:
|
||||
| gtk+-quartz-3.0 >= 3.18
|
||||
run: $TESTCASE_ROOT/_build/install/default/bin/pkg-config --cflags 'gtk+-quartz-3.0 >= 3.18'
|
||||
-> process exited with code 0
|
||||
-> stdout:
|
||||
| --cflags
|
||||
| gtk+-quartz-3.0 >= 3.18
|
||||
run: $TESTCASE_ROOT/_build/install/default/bin/pkg-config --libs 'gtk+-quartz-3.0 >= 3.18'
|
||||
-> process exited with code 0
|
||||
-> stdout:
|
||||
| --libs
|
||||
| gtk+-quartz-3.0 >= 3.18
|
||||
run: $TESTCASE_ROOT/_build/install/default/bin/pkg-config --print-errors 'gtksourceview-3.0 >= 3.18'
|
||||
-> process exited with code 0
|
||||
-> stdout:
|
||||
| gtksourceview-3.0 >= 3.18
|
||||
run: $TESTCASE_ROOT/_build/install/default/bin/pkg-config --cflags 'gtksourceview-3.0 >= 3.18'
|
||||
-> process exited with code 0
|
||||
-> stdout:
|
||||
| --cflags
|
||||
| gtksourceview-3.0 >= 3.18
|
||||
run: $TESTCASE_ROOT/_build/install/default/bin/pkg-config --libs 'gtksourceview-3.0 >= 3.18'
|
||||
-> process exited with code 0
|
||||
-> stdout:
|
||||
| --libs
|
||||
| gtksourceview-3.0 >= 3.18
|
||||
Loading…
Add table
Add a link
Reference in a new issue