From 1e0bbc7f39db6170c2a30e0215ed01074b1f388f Mon Sep 17 00:00:00 2001 From: Jonah Beckford <9566106-jonahbeckford@users.noreply.gitlab.com> Date: Thu, 13 Feb 2025 17:09:41 -0800 Subject: [PATCH] Processing to fix incompatible -O and gcc flags Two changes: 1. Accept BUILD_TINY_HTTPD_OPTLEVEL envvar to adjust the -O level. Defaults to 2. Can be negative to remove it entirely, which fixes errors with MSVC which will bail on incompatible options. 2. Do not use -fPIC with MSVC --- dune-project | 2 +- src/ws/dune | 27 ++++++++++++++++++++++++++- tiny_httpd.opam | 4 +--- tiny_httpd_camlzip.opam | 4 +--- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/dune-project b/dune-project index f56ce53f..08f02b88 100644 --- a/dune-project +++ b/dune-project @@ -1,4 +1,4 @@ -(lang dune 2.9) +(lang dune 3.2) (name tiny_httpd) (generate_opam_files true) diff --git a/src/ws/dune b/src/ws/dune index 19203d2f..b7702b7f 100644 --- a/src/ws/dune +++ b/src/ws/dune @@ -1,3 +1,28 @@ +; Set BUILD_TINY_HTTPD_OPTLEVEL to the -O level. +; Defaults to 2, which means -O2 is the default C optimization flag. +; Use -1 to remove the -O flag entirely. +(rule + (enabled_if (>= %{env:BUILD_TINY_HTTPD_OPTLEVEL=2} 0)) + (target optlevel.string) + (deps (env_var BUILD_TINY_HTTPD_OPTLEVEL)) + (action (with-stdout-to %{target} (echo "-O%{env:BUILD_TINY_HTTPD_OPTLEVEL=2}")))) +(rule + (enabled_if (< %{env:BUILD_TINY_HTTPD_OPTLEVEL=2} 0)) + (target optlevel.string) + (deps (env_var BUILD_TINY_HTTPD_OPTLEVEL)) + (action (with-stdout-to %{target} (echo "")))) + +; All compilers will include the optimization level. +; Non-MSVC compilers will include `-std=c99 -fPIC`. +(rule + (enabled_if (= %{ocaml-config:ccomp_type} msvc)) + (target cflags.sexp) + (action (with-stdout-to %{target} (echo "(%{read:optlevel.string})")))) +(rule + (enabled_if (not (= %{ocaml-config:ccomp_type} msvc))) + (target cflags.sexp) + (action (with-stdout-to %{target} (echo "(-std=c99 -fPIC %{read:optlevel.string})")))) + (library (name tiny_httpd_ws) (public_name tiny_httpd.ws) @@ -7,7 +32,7 @@ (foreign_stubs (language c) (names tiny_httpd_ws_stubs) - (flags :standard -std=c99 -fPIC -O2)) + (flags :standard (:include cflags.sexp))) (libraries (re_export tiny_httpd.core) threads)) diff --git a/tiny_httpd.opam b/tiny_httpd.opam index 07d095bd..b5806c05 100644 --- a/tiny_httpd.opam +++ b/tiny_httpd.opam @@ -11,7 +11,7 @@ tags: [ homepage: "https://github.com/c-cube/tiny_httpd/" bug-reports: "https://github.com/c-cube/tiny_httpd/issues" depends: [ - "dune" {>= "2.9"} + "dune" {>= "3.2"} "seq" "base-threads" "result" @@ -38,11 +38,9 @@ build: [ name "-j" jobs - "--promote-install-files=false" "@install" "@runtest" {with-test} "@doc" {with-doc} ] - ["dune" "install" "-p" name "--create-install-files" name] ] dev-repo: "git+https://github.com/c-cube/tiny_httpd.git" diff --git a/tiny_httpd_camlzip.opam b/tiny_httpd_camlzip.opam index 01453b61..830fd19a 100644 --- a/tiny_httpd_camlzip.opam +++ b/tiny_httpd_camlzip.opam @@ -8,7 +8,7 @@ license: "MIT" homepage: "https://github.com/c-cube/tiny_httpd/" bug-reports: "https://github.com/c-cube/tiny_httpd/issues" depends: [ - "dune" {>= "2.9"} + "dune" {>= "3.2"} "tiny_httpd" {= version} "camlzip" {>= "1.06"} "iostream-camlzip" {>= "0.2.1"} @@ -24,11 +24,9 @@ build: [ name "-j" jobs - "--promote-install-files=false" "@install" "@runtest" {with-test} "@doc" {with-doc} ] - ["dune" "install" "-p" name "--create-install-files" name] ] dev-repo: "git+https://github.com/c-cube/tiny_httpd.git"