Add commands for working with Orca source code #79

Merged
MartinFouilleul merged 1 commits from src-install into main 2023-09-16 15:55:37 +00:00
Owner

Adds the source command with cflags and vendor commands:

>orca source -h 
usage: orca source [-h] {cflags,vendor} ...

options:
  -h, --help       show this help message and exit

commands:
  {cflags,vendor}
    cflags         Get help setting up a C or C++ compiler to compile the Orca source.
    vendor         Copy the Orca source code into your project.

vendor copies the Orca source code into a directory of your choosing. It tracks which version of Orca the source came from, and uses a checksum to detect if any files were modified while vendored to avoid stomping on important local changes.

cflags prints info like this:

>orca source cflags
To compile Orca as part of your C or C++ project, you must:
> Put the following directory on your include search path:
  src
> Compile the following file as a single translation unit:
  src\orca.c

In addition, if you wish to use our minimal libc shim, you must do the following:
> Put the following directory on your SYSTEM include search path:
  src\libc-shim\include
> Compile the following files as separate translation units:
  src\libc-shim\src\*.c

Finally, the following clang flags are required:
> --target=wasm32         (to compile to wasm)
> -D__ORCA__              (to signal that the Orca source code is being compiled to run on Orca itself)
> -fno-builtin            (?????????? TODO ??????????)
> --Wl,--no-entry         (to prevent wasm-ld from looking for a _start symbol)
> --Wl,--export-dynamic   (to expose your module's functions to Orca)

And the following clang flags are recommended:
> -g -O2                  (to compile with optimizations and debug info)
> -mbulk-memory           (to enable more efficient memory instructions)
> --no-standard-libraries (if using our libc shim)

Complete clang example:

clang --target=wasm32 -D__ORCA__ -fno-builtin --Wl,--no-entry --Wl,--export-dynamic -g -O2 -mbulk-memory --no-standard-libraries 
-isystem src\libc-shim\include -I src src\orca.c src\libc-shim\src\*.c your-main.c

Task completed successfully.

Resolves #43.

Adds the `source` command with `cflags` and `vendor` commands: ``` >orca source -h usage: orca source [-h] {cflags,vendor} ... options: -h, --help show this help message and exit commands: {cflags,vendor} cflags Get help setting up a C or C++ compiler to compile the Orca source. vendor Copy the Orca source code into your project. ``` `vendor` copies the Orca source code into a directory of your choosing. It tracks which version of Orca the source came from, and uses a checksum to detect if any files were modified while vendored to avoid stomping on important local changes. `cflags` prints info like this: ``` >orca source cflags To compile Orca as part of your C or C++ project, you must: > Put the following directory on your include search path: src > Compile the following file as a single translation unit: src\orca.c In addition, if you wish to use our minimal libc shim, you must do the following: > Put the following directory on your SYSTEM include search path: src\libc-shim\include > Compile the following files as separate translation units: src\libc-shim\src\*.c Finally, the following clang flags are required: > --target=wasm32 (to compile to wasm) > -D__ORCA__ (to signal that the Orca source code is being compiled to run on Orca itself) > -fno-builtin (?????????? TODO ??????????) > --Wl,--no-entry (to prevent wasm-ld from looking for a _start symbol) > --Wl,--export-dynamic (to expose your module's functions to Orca) And the following clang flags are recommended: > -g -O2 (to compile with optimizations and debug info) > -mbulk-memory (to enable more efficient memory instructions) > --no-standard-libraries (if using our libc shim) Complete clang example: clang --target=wasm32 -D__ORCA__ -fno-builtin --Wl,--no-entry --Wl,--export-dynamic -g -O2 -mbulk-memory --no-standard-libraries -isystem src\libc-shim\include -I src src\orca.c src\libc-shim\src\*.c your-main.c Task completed successfully. ``` Resolves #43.
Collaborator

The wording on orca source cflags suggests some options are optional when they might not.

For instance, compiling the libc-shim is necessary because it's used by the stb headers. What's optional is using it in your app (so you can omit the -isystem flag). We could just include all the libc-shim C files in orca.c to simplify the compile command though.

I think -mbulk-memory is also required for our libc shims to work (eg memset/memcpy etc)?

Currently I think --no-standard-libraries is also required or you'll get linking errors if you try to use a stdlib function. (This might change if we later allow compiling with emscripten?)

-fno-builtin avoids clang recognizing stdlib functions and deciding to replace it with its own builtins instead of our libc-shim ones. That was a problem when we had hand-rolled memset etc. Now that we enable -mbulk-memory it seems to not be needed anymore.

The wording on `orca source cflags` suggests some options are optional when they might not. For instance, compiling the `libc-shim` is necessary because it's used by the stb headers. What's optional is using it in your app (so you can omit the `-isystem` flag). We could just include all the libc-shim C files in orca.c to simplify the compile command though. I think `-mbulk-memory` is also _required_ for our libc shims to work (eg memset/memcpy etc)? Currently I think `--no-standard-libraries` is also required or you'll get linking errors if you try to use a stdlib function. (This might change if we later allow compiling with emscripten?) `-fno-builtin` avoids clang recognizing stdlib functions and deciding to replace it with its own builtins instead of our libc-shim ones. That was a problem when we had hand-rolled `memset` etc. Now that we enable `-mbulk-memory` it seems to not be needed anymore.
Author
Owner

Oh, we depend on stb_truetype for core Orca, don't we? I forgot, I thought we just needed stb_image for demos.

I'm hoping to test soon with Emscripten since I would rather test that out sooner rather than later. I expect someone to do that for the jam.

I'll test these flags when I have a chance and make sure this is all more accurate.

Oh, we depend on stb_truetype for core Orca, don't we? I forgot, I thought we just needed stb_image for demos. I'm hoping to test soon with Emscripten since I would rather test that out sooner rather than later. I expect _someone_ to do that for the jam. I'll test these flags when I have a chance and make sure this is all more accurate.
bvisness force-pushed src-install from 5e27ec4e84 to ed0e6f8f84 2023-09-11 23:12:30 +00:00 Compare
MartinFouilleul force-pushed src-install from 7c96a93939 to 29cb9f50e4 2023-09-16 15:55:22 +00:00 Compare
MartinFouilleul merged commit 29cb9f50e4 into main 2023-09-16 15:55:37 +00:00
MartinFouilleul deleted branch src-install 2023-09-16 15:55:37 +00:00
Sign in to join this conversation.
No reviewers
No Label
macOS
windows
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: hmn/orca#79
No description provided.