Skip to content

Commit

Permalink
Processing to fix incompatible -O and gcc flags
Browse files Browse the repository at this point in the history
Two changes:
1. Accept BUILD_TINY_HTTPD_OPTLEVEL envvar to adjust the -O<num> 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
  • Loading branch information
jonahbeckford authored and c-cube committed Feb 16, 2025
1 parent 1f60d61 commit 1e0bbc7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(lang dune 2.9)
(lang dune 3.2)
(name tiny_httpd)
(generate_opam_files true)

Expand Down
27 changes: 26 additions & 1 deletion src/ws/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
; Set BUILD_TINY_HTTPD_OPTLEVEL to the -O<num> level.
; Defaults to 2, which means -O2 is the default C optimization flag.
; Use -1 to remove the -O<num> 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)
Expand All @@ -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))
4 changes: 1 addition & 3 deletions tiny_httpd.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
4 changes: 1 addition & 3 deletions tiny_httpd_camlzip.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -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"

0 comments on commit 1e0bbc7

Please sign in to comment.