Skip to content

Commit

Permalink
igvm_c: Fix linker issues with sample and tests and clean up output (#31
Browse files Browse the repository at this point in the history
)

It was reported on coconut-svsm/svsm#237 that on
certain environments, the C unit tests and sample fail to build due to
missing library dependencies. Also, the status of the build is hard to
determine due to the amount of warnings generated by cbindgen. See the
comment thread in that PR from @cclaudio.

The required list of libraries can be determined with the following
command:

```
cargo rustc --verbose --features "igvm-c" --manifest-path=igvm/Cargo.toml -- --print=native-static-libs
```
This PR updates the Makefile to reflect the output of this command. In
addition, the cbindgen `-q` flag is used to suppress warnings - it would
be good to fix the warnings but this would require the generation of
redundant additional output in the header files which is not ideal.

Finally, add a section to the README to describe how to install the
library.

---------

Signed-off-by: Roy Hopkins <[email protected]>
Co-authored-by: Chris Oo <[email protected]>
  • Loading branch information
roy-hopkins and chris-oo authored Feb 27, 2024
1 parent f060697 commit 5647d84
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions igvm_c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ $(TARGET_PATH)/test_data:
$(CARGO) build --manifest-path=$(IGVM_DIR)/igvm_c/test_data/Cargo.toml

include/igvm.h: $(RUST_SOURCE)
cbindgen -c $(API_DIR)/cbindgen_igvm.toml $(IGVM_DIR)/igvm -o "$(API_DIR)/include/igvm.h"
cbindgen -c $(API_DIR)/cbindgen_igvm_defs.toml $(IGVM_DIR)/igvm_defs -o "$(API_DIR)/include/igvm_defs.h"
cbindgen -q -c $(API_DIR)/cbindgen_igvm.toml $(IGVM_DIR)/igvm -o "$(API_DIR)/include/igvm.h"
cbindgen -q -c $(API_DIR)/cbindgen_igvm_defs.toml $(IGVM_DIR)/igvm_defs -o "$(API_DIR)/include/igvm_defs.h"

$(TARGET_PATH)/dump_igvm: $(API_DIR)/include/igvm.h $(API_DIR)/sample/dump_igvm.c $(TARGET_PATH)/libigvm.a
cc -g3 -O0 -I $(API_DIR) -L $(TARGET_PATH) -o $@ $^ -ligvm -lcunit
cc -g3 -O0 -I $(API_DIR) -L $(TARGET_PATH) -o $@ $^ -ligvm -ldl -pthread -lm -lutil -lrt

$(TARGET_PATH)/igvm_test: $(API_DIR)/include/igvm.h $(API_DIR)/tests/igvm_test.c $(TARGET_PATH)/libigvm.a
cc -g3 -O0 -I $(API_DIR) -L $(TARGET_PATH) -o $@ $^ -ligvm -lcunit
cc -g3 -O0 -I $(API_DIR) -L $(TARGET_PATH) -o $@ $^ -ligvm -lcunit -ldl -pthread -lm -lutil -lrt

$(TARGET_PATH)/igvm.bin: $(TARGET_PATH)/test_data
$(TARGET_PATH)/test_data $(TARGET_PATH)/igvm.bin
Expand Down
15 changes: 15 additions & 0 deletions igvm_c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ exported C functions.
The file `igvm.h` includes `igvm_defs.h` so only this file needs to be included
in C projects source files.

## Installing
Once built, the library can be installed with:

```bash
make -f Makefile install
```

By default, the library will be installed into `/usr` which will require root
privileges. Alternatively, the library can be installed in a different location
by setting `PREFIX`:

```bash
PREFIX=/path/to/installation make -f Makefile install
```

## Sample application
The C API build generates a test application named `dump_igvm`. This application
can take the path of a binary IGVM file as a parameter and will use the C API to
Expand Down

0 comments on commit 5647d84

Please sign in to comment.