Skip to content

Commit 1e0bbc7

Browse files
jonahbeckfordc-cube
authored andcommitted
Processing to fix incompatible -O and gcc flags
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
1 parent 1f60d61 commit 1e0bbc7

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

dune-project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(lang dune 2.9)
1+
(lang dune 3.2)
22
(name tiny_httpd)
33
(generate_opam_files true)
44

src/ws/dune

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
; Set BUILD_TINY_HTTPD_OPTLEVEL to the -O<num> level.
2+
; Defaults to 2, which means -O2 is the default C optimization flag.
3+
; Use -1 to remove the -O<num> flag entirely.
4+
(rule
5+
(enabled_if (>= %{env:BUILD_TINY_HTTPD_OPTLEVEL=2} 0))
6+
(target optlevel.string)
7+
(deps (env_var BUILD_TINY_HTTPD_OPTLEVEL))
8+
(action (with-stdout-to %{target} (echo "-O%{env:BUILD_TINY_HTTPD_OPTLEVEL=2}"))))
9+
(rule
10+
(enabled_if (< %{env:BUILD_TINY_HTTPD_OPTLEVEL=2} 0))
11+
(target optlevel.string)
12+
(deps (env_var BUILD_TINY_HTTPD_OPTLEVEL))
13+
(action (with-stdout-to %{target} (echo ""))))
14+
15+
; All compilers will include the optimization level.
16+
; Non-MSVC compilers will include `-std=c99 -fPIC`.
17+
(rule
18+
(enabled_if (= %{ocaml-config:ccomp_type} msvc))
19+
(target cflags.sexp)
20+
(action (with-stdout-to %{target} (echo "(%{read:optlevel.string})"))))
21+
(rule
22+
(enabled_if (not (= %{ocaml-config:ccomp_type} msvc)))
23+
(target cflags.sexp)
24+
(action (with-stdout-to %{target} (echo "(-std=c99 -fPIC %{read:optlevel.string})"))))
25+
126
(library
227
(name tiny_httpd_ws)
328
(public_name tiny_httpd.ws)
@@ -7,7 +32,7 @@
732
(foreign_stubs
833
(language c)
934
(names tiny_httpd_ws_stubs)
10-
(flags :standard -std=c99 -fPIC -O2))
35+
(flags :standard (:include cflags.sexp)))
1136
(libraries
1237
(re_export tiny_httpd.core)
1338
threads))

tiny_httpd.opam

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tags: [
1111
homepage: "https://github.com/c-cube/tiny_httpd/"
1212
bug-reports: "https://github.com/c-cube/tiny_httpd/issues"
1313
depends: [
14-
"dune" {>= "2.9"}
14+
"dune" {>= "3.2"}
1515
"seq"
1616
"base-threads"
1717
"result"
@@ -38,11 +38,9 @@ build: [
3838
name
3939
"-j"
4040
jobs
41-
"--promote-install-files=false"
4241
"@install"
4342
"@runtest" {with-test}
4443
"@doc" {with-doc}
4544
]
46-
["dune" "install" "-p" name "--create-install-files" name]
4745
]
4846
dev-repo: "git+https://github.com/c-cube/tiny_httpd.git"

tiny_httpd_camlzip.opam

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license: "MIT"
88
homepage: "https://github.com/c-cube/tiny_httpd/"
99
bug-reports: "https://github.com/c-cube/tiny_httpd/issues"
1010
depends: [
11-
"dune" {>= "2.9"}
11+
"dune" {>= "3.2"}
1212
"tiny_httpd" {= version}
1313
"camlzip" {>= "1.06"}
1414
"iostream-camlzip" {>= "0.2.1"}
@@ -24,11 +24,9 @@ build: [
2424
name
2525
"-j"
2626
jobs
27-
"--promote-install-files=false"
2827
"@install"
2928
"@runtest" {with-test}
3029
"@doc" {with-doc}
3130
]
32-
["dune" "install" "-p" name "--create-install-files" name]
3331
]
3432
dev-repo: "git+https://github.com/c-cube/tiny_httpd.git"

0 commit comments

Comments
 (0)