Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Processing to fix incompatible -O and gcc flags #94

Merged
merged 1 commit into from
Feb 16, 2025

Conversation

jonahbeckford
Copy link
Contributor

Main 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

Motivation

This is just a warning for most people:

tiny_httpd_ws_stubs.c
cl : Command line warning D9002 : ignoring unknown option '-std=c99'
cl : Command line warning D9002 : ignoring unknown option '-fPIC'

But if you compile with debug flags like I do, you can get:

File "DkFilesD/_opam/.opam-switch/build/tiny_httpd.0.17.0/src/ws/dune", line 10, characters 11-30:
10 |     (names tiny_httpd_ws_stubs)
                ^^^^^^^^^^^^^^^^^^^
          cl DkFilesD/_opam/.opam-switch/build/tiny_httpd.0.17.0/src/ws/tiny_httpd_ws_stubs.obj (exit 2)
(cd _build/default/DkFilesD/_opam/.opam-switch/build/tiny_httpd.0.17.0/src/ws && Y:/VS/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe -nologo -Gy- -MDd -DWIN32 -D_WINDOWS -Ob0 -Od -RTC1 -D_CRT_SECURE_NO_DEPRECATE -nologo -Gy- -MDd -DWIN32 -D_WINDOWS -Ob0 -Od -RTC1 -D_CRT_SECURE_NO_DEPRECATE -std=c99 -fPIC -O2 -I Y:/source/dksdk-foundations/build/d/st-d/o/lib/ocaml -I Y:/source/dksdk-foundations/build/d/st-d/o/lib/ocaml\threads -I ../../../hmap.0.8.1+dune/src -I ../../../iostream.0.3/src/core -I ../../../iostream.0.3/src/types -I ../../../seq.base/src -I ../core /Fotiny_httpd_ws_stubs.obj -c tiny_httpd_ws_stubs.c)
cl : Command line warning D9025 : overriding '/Od' with '/O2'
cl : Command line error D8016 : '/RTC1' and '/O2' command-line options are incompatible

All Changes

  1. No longer using unknown MSVC options like -fPIC with MSVC.

  2. BUILD_TINY_HTTPD_OPTLEVEL can influence and remove -O2.

  3. Had to bump up dune to 3.2 or else:

    Error: 'not' is only available since version 3.2 of the dune language. Please
    update your dune-project file to have (lang dune 3.2).
    

Testing

I used a different switch than what is in "Motivation" so it is easy to repeat.

With this PR (scroll to the right):

$ opam exec -- ocamlc -config-var native_c_compiler
cl -nologo -O2 -Gy- -MD    -D_CRT_SECURE_NO_DEPRECATE 

$ opam exec -- dune build -p tiny_httpd --display short
          cl src/ws/tiny_httpd_ws_stubs.obj
(cd _build/default/src/ws && Y:\VS\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe -nologo -O2 -Gy- -MD -D_CRT_SECURE_NO_DEPRECATE -O2 -I C:/Users/beckf/AppData/Local/Programs/DKMLNA~1/lib/ocaml -I C:/Users/beckf/AppData/Local/Programs/DKMLNA~1/lib/ocaml\threads -I Y:\source\MlFront_Archive\_opam\lib\hmap -I Y:\source\MlFront_Archive\_opam\lib\iostream -I Y:\source\MlFront_Archive\_opam\lib\logs -I Y:\source\MlFront_Archive\_opam\lib\seq -I ../core /Fotiny_httpd_ws_stubs.obj -c tiny_httpd_ws_stubs.c)

$ opam exec -- env BUILD_TINY_HTTPD_OPTLEVEL=1 dune build -p tiny_httpd --display short
          cl src/ws/tiny_httpd_ws_stubs.obj
(cd _build/default/src/ws && Y:\VS\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe -nologo -O2 -Gy- -MD -D_CRT_SECURE_NO_DEPRECATE -O1 -I C:/Users/beckf/AppData/Local/Programs/DKMLNA~1/lib/ocaml -I C:/Users/beckf/AppData/Local/Programs/DKMLNA~1/lib/ocaml\threads -I Y:\source\MlFront_Archive\_opam\lib\hmap -I Y:\source\MlFront_Archive\_opam\lib\iostream -I Y:\source\MlFront_Archive\_opam\lib\logs -I Y:\source\MlFront_Archive\_opam\lib\seq -I ../core /Fotiny_httpd_ws_stubs.obj -c tiny_httpd_ws_stubs.c)
cl : Command line warning D9025 : overriding '/O2' with '/O1'

$ opam exec -- env BUILD_TINY_HTTPD_OPTLEVEL=0 dune build -p tiny_httpd --display short
          cl src/ws/tiny_httpd_ws_stubs.obj
(cd _build/default/src/ws && Y:\VS\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe -nologo -O2 -Gy- -MD -D_CRT_SECURE_NO_DEPRECATE -O0 -I C:/Users/beckf/AppData/Local/Programs/DKMLNA~1/lib/ocaml -I C:/Users/beckf/AppData/Local/Programs/DKMLNA~1/lib/ocaml\threads -I Y:\source\MlFront_Archive\_opam\lib\hmap -I Y:\source\MlFront_Archive\_opam\lib\iostream -I Y:\source\MlFront_Archive\_opam\lib\logs -I Y:\source\MlFront_Archive\_opam\lib\seq -I ../core /Fotiny_httpd_ws_stubs.obj -c tiny_httpd_ws_stubs.c)
cl : Command line warning D9002 : ignoring unknown option '-O0'

$ opam exec -- env BUILD_TINY_HTTPD_OPTLEVEL=-1 dune build -p tiny_httpd --display short
          cl src/ws/tiny_httpd_ws_stubs.obj
(cd _build/default/src/ws && Y:\VS\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe -nologo -O2 -Gy- -MD -D_CRT_SECURE_NO_DEPRECATE -I C:/Users/beckf/AppData/Local/Programs/DKMLNA~1/lib/ocaml -I C:/Users/beckf/AppData/Local/Programs/DKMLNA~1/lib/ocaml\threads -I Y:\source\MlFront_Archive\_opam\lib\hmap -I Y:\source\MlFront_Archive\_opam\lib\iostream -I Y:\source\MlFront_Archive\_opam\lib\logs -I Y:\source\MlFront_Archive\_opam\lib\seq -I ../core /Fotiny_httpd_ws_stubs.obj -c tiny_httpd_ws_stubs.c)

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
@c-cube c-cube merged commit 1e0bbc7 into c-cube:main Feb 16, 2025
3 checks passed
@c-cube
Copy link
Owner

c-cube commented Feb 16, 2025

Very nice, thanks! Took me a second to get the rules but it's nicely done :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants