summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Puydt <jpuydt@debian.org>2023-06-21 10:35:25 +0200
committerJulien Puydt <jpuydt@debian.org>2023-06-21 10:35:25 +0200
commitde4c887ee8d818fef8c224241de67abc4bac656d (patch)
tree15c132dd53c2d2e23740ac5c8bb052aa65010376
Import jst-config_0.16.0.orig.tar.gz
[dgit import orig jst-config_0.16.0.orig.tar.gz]
-rw-r--r--.gitignore5
-rw-r--r--CONTRIBUTING.md67
-rw-r--r--LICENSE.md21
-rw-r--r--Makefile17
-rw-r--r--discover/discover.ml255
-rw-r--r--discover/dune2
-rw-r--r--dune-project1
-rw-r--r--jst-config.opam29
-rw-r--r--src/dune9
-rw-r--r--src/thread_id.h27
10 files changed, 433 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6c14091
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+_build
+*.install
+*.merlin
+_opam
+
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..45e1a22
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,67 @@
+This repository contains open source software that is developed and
+maintained by [Jane Street][js].
+
+Contributions to this project are welcome and should be submitted via
+GitHub pull requests.
+
+Signing contributions
+---------------------
+
+We require that you sign your contributions. Your signature certifies
+that you wrote the patch or otherwise have the right to pass it on as
+an open-source patch. The rules are pretty simple: if you can certify
+the below (from [developercertificate.org][dco]):
+
+```
+Developer Certificate of Origin
+Version 1.1
+
+Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
+1 Letterman Drive
+Suite D4700
+San Francisco, CA, 94129
+
+Everyone is permitted to copy and distribute verbatim copies of this
+license document, but changing it is not allowed.
+
+
+Developer's Certificate of Origin 1.1
+
+By making a contribution to this project, I certify that:
+
+(a) The contribution was created in whole or in part by me and I
+ have the right to submit it under the open source license
+ indicated in the file; or
+
+(b) The contribution is based upon previous work that, to the best
+ of my knowledge, is covered under an appropriate open source
+ license and I have the right under that license to submit that
+ work with modifications, whether created in whole or in part
+ by me, under the same open source license (unless I am
+ permitted to submit under a different license), as indicated
+ in the file; or
+
+(c) The contribution was provided directly to me by some other
+ person who certified (a), (b) or (c) and I have not modified
+ it.
+
+(d) I understand and agree that this project and the contribution
+ are public and that a record of the contribution (including all
+ personal information I submit with it, including my sign-off) is
+ maintained indefinitely and may be redistributed consistent with
+ this project or the open source license(s) involved.
+```
+
+Then you just add a line to every git commit message:
+
+```
+Signed-off-by: Joe Smith <joe.smith@email.com>
+```
+
+Use your real name (sorry, no pseudonyms or anonymous contributions.)
+
+If you set your `user.name` and `user.email` git configs, you can sign
+your commit automatically with git commit -s.
+
+[dco]: http://developercertificate.org/
+[js]: https://opensource.janestreet.com/
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..f45a250
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2019--2023 Jane Street Group, LLC <opensource-contacts@janestreet.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..1965878
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,17 @@
+INSTALL_ARGS := $(if $(PREFIX),--prefix $(PREFIX),)
+
+default:
+ dune build
+
+install:
+ dune install $(INSTALL_ARGS)
+
+uninstall:
+ dune uninstall $(INSTALL_ARGS)
+
+reinstall: uninstall install
+
+clean:
+ dune clean
+
+.PHONY: default install uninstall reinstall clean
diff --git a/discover/discover.ml b/discover/discover.ml
new file mode 100644
index 0000000..2bb831a
--- /dev/null
+++ b/discover/discover.ml
@@ -0,0 +1,255 @@
+open Base
+module C = Configurator.V1
+
+let eventfd_code = {|
+#include <sys/eventfd.h>
+
+int main()
+{
+ int fd = eventfd(0, 0);
+ return 0;
+}
+|}
+
+let posix_timers_code = {|
+#include <time.h>
+
+int main()
+{
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ clock_settime(CLOCK_REALTIME, &ts);
+ clock_getres(CLOCK_REALTIME, &ts);
+ return 0;
+}
+|}
+
+let clock_getcpuclockid_code = {|
+#include <time.h>
+
+int main()
+{
+ clock_getcpuclockid(0, CLOCK_REALTIME);
+ return 0;
+}
+|}
+
+type posix_timers =
+ | Available of { need_lrt : bool; getcpuclockid : bool }
+ | Not_available
+
+let timespec_code = {|
+#include <time.h>
+
+int main()
+{
+ struct timespec ts;
+ timespec_get(&ts, TIME_UTC);
+ return 0;
+}
+|}
+
+let timerfd_code = {|
+#include <sys/timerfd.h>
+
+int main()
+{
+ timerfd_create(0, 0);
+ return 0;
+}
+|}
+
+let wordexp_code = {|
+#include <wordexp.h>
+
+int main()
+{
+ wordexp_t w;
+ wordexp("", &w, 0);
+ return 0;
+}
+|}
+
+let thread_id_code ~thread_id_method ~thread_id_header = Printf.sprintf {|
+#define JSC_THREAD_ID_METHOD %d
+#include "%s"
+
+int main ()
+{
+ GET_THREAD_ID;
+ return 0;
+}
+|} thread_id_method thread_id_header
+
+let msg_nosignal_code = {|
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int main()
+{
+ send(0, "", 0, MSG_NOSIGNAL);
+ return 0;
+}
+|}
+
+let so_nosigpipe_code = {|
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int main()
+{
+ send(0, "", 0, SO_NOSIGPIPE);
+ return 0;
+}
+|}
+
+let fdatasync_code = {|
+#include <unistd.h>
+
+int main()
+{
+ fdatasync(0);
+ return 0;
+}
+|}
+
+let thread_cputime_code = {|
+#include <pthread.h>
+#include <time.h>
+
+int main()
+{
+ clockid_t clock;
+ pthread_getcpuclockid(pthread_self(), &clock);
+ return 0;
+}
+|}
+
+let recvmmsg_code = {|
+#define _GNU_SOURCE
+#include <sys/socket.h>
+
+int main () {
+ recvmmsg(0, 0, 0, 0, 0);
+ return 0;
+}
+|}
+
+let mkostemp_code = {|
+#define _GNU_SOURCE
+#include <stdlib.h>
+
+int main () {
+ mkostemp("", 0);
+ return 0;
+}
+|}
+
+let pthread_np = {|
+#define _GNU_SOURCE
+#include <pthread.h>
+#include <sys/types.h>
+
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
+#include <pthread_np.h>
+#endif
+
+int main()
+{
+ pthread_t tid;
+ cpu_set_t cpuset;
+
+ tid = pthread_self();
+ pthread_getaffinity_np(tid, sizeof(cpu_set_t), &cpuset);
+
+ return 0;
+}
+|}
+
+let readdir_dtype_code = {|
+#include <dirent.h>
+int main()
+{
+ int i = DT_BLK;
+ return 0;
+}
+|}
+
+let () =
+ C.main ~name:"config_h" (fun c ->
+ let posix_timers =
+ C.c_test c posix_timers_code
+ in
+ let clock_getcpuclockid =
+ C.c_test c clock_getcpuclockid_code
+ in
+ let thread_id_method =
+ let thread_id_header = Stdlib.Filename.concat (Stdlib.Sys.getcwd ()) "thread_id.h" in
+ List.find [1; 2] ~f:(fun thread_id_method ->
+ C.c_test c (thread_id_code ~thread_id_method ~thread_id_header))
+ |> Option.value ~default:(-1)
+ in
+
+ let linux =
+ let system = C.ocaml_config_var_exn c "system" in (* TODO: "uname -s" should be used instead *)
+ (* Possible values for this field: linux, linux_elf, linux_eabi, ... *)
+ String.is_prefix system ~prefix:"linux" || String.equal system "elf"
+ in
+
+ let simple_vars =
+ List.map ~f:(fun (v, code, c_flags, link_flags) ->
+ (v, C.C_define.Value.Switch (C.c_test c code ~c_flags ~link_flags)))
+ [ "EVENTFD" , eventfd_code , [] , []
+ ; "TIMESPEC" , timespec_code , ["-std=c11"] , []
+ ; "TIMERFD" , timerfd_code , [] , []
+ ; "WORDEXP" , wordexp_code , [] , []
+ ; "MSG_NOSIGNAL" , msg_nosignal_code , [] , []
+ ; "SO_NOSIGPIPE" , so_nosigpipe_code , [] , []
+ ; "FDATASYNC" , fdatasync_code , [] , []
+ ; "RECVMMSG" , recvmmsg_code , [] , []
+ ; "THREAD_CPUTIME" , thread_cputime_code , [] , ["-lpthread"]
+ ; "PTHREAD_NP" , pthread_np , [] , ["-lpthread"]
+ ; "MKOSTEMP" , mkostemp_code , [] , []
+ ; "READDIR_DTYPE" , readdir_dtype_code , [] , []
+ ]
+ in
+
+ let rlimit_vars =
+ if C.c_test c "#include <sys/resource.h>\nint main() { return 0; }" then
+ C.C_define.import c ~includes:["sys/resource.h"]
+ [ "RLIMIT_AS" , Switch
+ ; "RLIMIT_NICE", Switch
+ ]
+ else
+ [ "RLIMIT_AS" , Switch false
+ ; "RLIMIT_NICE", Switch false
+ ]
+ in
+
+ let ocaml_vars =
+ C.C_define.import c ~includes:["caml/config.h"]
+ [ "ARCH_BIG_ENDIAN", Switch
+ ; "ARCH_SIXTYFOUR" , Switch
+ ]
+ in
+
+ let vars =
+ List.concat
+ [ rlimit_vars
+ ; ocaml_vars
+ ; simple_vars
+ ; [
+ "POSIX_TIMERS" , Switch posix_timers
+ ; "CLOCK_GETCPUCLOCKID" , Switch clock_getcpuclockid
+ ; "THREAD_ID_METHOD", Int thread_id_method
+ ; "LINUX_EXT" , Switch linux
+ ]
+ ]
+ in
+
+ let jsc_vars =
+ List.map vars ~f:(fun (name, v) -> ("JSC_" ^ name, v))
+ in
+
+ C.C_define.gen_header_file c ~fname:"config.h" jsc_vars
+ )
diff --git a/discover/dune b/discover/dune
new file mode 100644
index 0000000..758aa79
--- /dev/null
+++ b/discover/dune
@@ -0,0 +1,2 @@
+(executables (names discover) (libraries base dune-configurator)
+ (preprocess (pps ppx_assert))) \ No newline at end of file
diff --git a/dune-project b/dune-project
new file mode 100644
index 0000000..eb10bcb
--- /dev/null
+++ b/dune-project
@@ -0,0 +1 @@
+(lang dune 1.10) \ No newline at end of file
diff --git a/jst-config.opam b/jst-config.opam
new file mode 100644
index 0000000..f6bde3d
--- /dev/null
+++ b/jst-config.opam
@@ -0,0 +1,29 @@
+opam-version: "2.0"
+version: "v0.16.0"
+maintainer: "Jane Street developers"
+authors: ["Jane Street Group, LLC"]
+homepage: "https://github.com/janestreet/jst-config"
+bug-reports: "https://github.com/janestreet/jst-config/issues"
+dev-repo: "git+https://github.com/janestreet/jst-config.git"
+doc: "https://ocaml.janestreet.com/ocaml-core/latest/doc/jst-config/index.html"
+license: "MIT"
+build: [
+ ["dune" "build" "-p" name "-j" jobs]
+]
+depends: [
+ "ocaml" {>= "4.14.0"}
+ "base" {>= "v0.16" & < "v0.17"}
+ "ppx_assert" {>= "v0.16" & < "v0.17"}
+ "dune" {>= "2.0.0"}
+ "dune-configurator"
+]
+available: arch != "arm32" & arch != "x86_32"
+synopsis: "Compile-time configuration for Jane Street libraries"
+description: "
+Defines compile-time constants used in Jane Street libraries such as Base, Core, and
+Async.
+
+This package has an unstable interface; it is intended only to share configuration between
+different packages from Jane Street. Future updates may not be backward-compatible, and we
+do not recommend using this package directly.
+"
diff --git a/src/dune b/src/dune
new file mode 100644
index 0000000..774c7e1
--- /dev/null
+++ b/src/dune
@@ -0,0 +1,9 @@
+(rule (targets config.h)
+ (deps (:first_dep ../discover/discover.exe) thread_id.h)
+ (action (run %{first_dep})))
+
+(install (section lib)
+ (files (config.h as config.h) (thread_id.h as thread_id.h)))
+
+(library (name config_h) (public_name jst-config)
+ (preprocess no_preprocessing)) \ No newline at end of file
diff --git a/src/thread_id.h b/src/thread_id.h
new file mode 100644
index 0000000..03ee5d3
--- /dev/null
+++ b/src/thread_id.h
@@ -0,0 +1,27 @@
+/* This file is used by both unix_stubs.c and config/discover.ml */
+
+#if !defined(JSC_THREAD_ID_METHOD)
+#warning "JSC_THREAD_ID_METHOD not defined"
+#endif
+
+#if JSC_THREAD_ID_METHOD == 1
+
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#define GET_THREAD_ID syscall(SYS_gettid)
+
+#elif JSC_THREAD_ID_METHOD == 2
+
+#include <sys/types.h>
+
+/* Advice from Philip Guenther on the ocaml-core mailing list is that we need to prototype
+ * this ourselves :(
+ * See: https://groups.google.com/forum/#!topic/ocaml-core/51knlnuJ8MM */
+extern pid_t getthrid(void);
+
+#define GET_THREAD_ID getthrid()
+
+#elif !(JSC_THREAD_ID_METHOD == -1)
+#warning "Unknown JSC_THREAD_ID_METHOD value"
+#endif