update installation README, Makefile changes
This commit is contained in:
		
							parent
							
								
									2dd1250bf1
								
							
						
					
					
						commit
						b06241f8d3
					
				
					 3 changed files with 30 additions and 26 deletions
				
			
		
							
								
								
									
										51
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										51
									
								
								README.md
									
										
									
									
									
								
							|  | @ -43,32 +43,37 @@ Please specify the full version including patch in your Cargo.toml until 1.0 is | ||||||
| 
 | 
 | ||||||
| ## Installation | ## Installation | ||||||
| 
 | 
 | ||||||
| 1. Add this repo as a submodule: | This manual uses gnumake, though it should work similarly for other build systems. | ||||||
|     ```bash | 
 | ||||||
|     git submodule add https://git.berlin.ccc.de/servicepoint/servicepoint-binding-c.git | Add this repo as a submodule: | ||||||
|     git commit -m "add servicepoint-binding-c submodule" | 
 | ||||||
|     ``` | ```bash | ||||||
| 2. Add a build step for the servicepoint library. If you use make, this could look something like this: | git submodule add https://git.berlin.ccc.de/servicepoint/servicepoint-binding-c.git | ||||||
|     ``` | git commit -m "add servicepoint-binding-c submodule" | ||||||
|     dependencies: FORCE | ``` | ||||||
|     	cargo build --manifest-path=servicepoint-binding-c/Cargo.toml --release | 
 | ||||||
|     FORCE: ;  | Update your Makefile: | ||||||
|     ``` | 
 | ||||||
| 3. Link against the library. If you are on linux and linking statically: | ```Makefile | ||||||
|     ``` | # provide header and binary to CC | ||||||
|     ${CC} main.c \ | CFLAGS += -I servicepoint-binding-c/include -L servicepoint-binding-c/target/release | ||||||
|     	-I servicepoint-binding-c/include \ | # link statically against servicepoint, link against lzma dynamically | ||||||
|     	-L servicepoint-binding-c/target/release \ | CFLAGS += -Wl,-Bstatic -lservicepoint_binding_c -Wl,-Bdynamic -llzma | ||||||
|     	-Wl,-Bstatic -lservicepoint_binding_c \ | 
 | ||||||
|     	-Wl,-Bdynamic -llzma \ | # add target to build rust library - cargo will check for dependency changes | ||||||
|     	-o out/example | servicepoint-binding-c/target/release/libservicepoint.a: | ||||||
|     ``` | 	cargo build --manifest-path=servicepoint-binding-c/Cargo.toml --release | ||||||
|  | 
 | ||||||
|  | # add static lib as a dependency for your compilation | ||||||
|  | # if you build .so files separately, this should be part of your build step | ||||||
|  | my_bin: $(src) servicepoint-binding-c/target/release/libservicepoint.a | ||||||
|  | 	$(CC) $(src) $(CFLAGS) -o $@ | ||||||
|  | ``` | ||||||
| 
 | 
 | ||||||
| You have the choice of linking statically (recommended) or dynamically. | You have the choice of linking statically (recommended) or dynamically. | ||||||
| 
 | When linked dynamically, you have to provide the `cdylib` at runtime in the _same_ version, as there are no API/ABI | ||||||
| - The C example shows how to link statically against the `staticlib` variant. |  | ||||||
| - When linked dynamically, you have to provide the `cdylib` at runtime in the _same_ version, as there are no API/ABI |  | ||||||
|   guarantees yet. |   guarantees yet. | ||||||
|  | The Makefile in the example directory contains a bunch of additional compiler flags you might want to add depending on your use case. | ||||||
| 
 | 
 | ||||||
| ## Notes on differences to rust library | ## Notes on differences to rust library | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -101,7 +101,7 @@ clean-rust: | ||||||
| 
 | 
 | ||||||
| $(_unstripped_bins): out/%_unstripped: src/%.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(_sp_artifacts) | $(_unstripped_bins): out/%_unstripped: src/%.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(_sp_artifacts) | ||||||
| 	mkdir -p out || true | 	mkdir -p out || true | ||||||
| 	${CC} $< \
 | 	$(CC) $< \
 | ||||||
| 		-I $(SERVICEPOINT_HEADER_OUT) \
 | 		-I $(SERVICEPOINT_HEADER_OUT) \
 | ||||||
| 		-L $(RUST_TARGET_DIR) \
 | 		-L $(RUST_TARGET_DIR) \
 | ||||||
| 		$(CCFLAGS) \
 | 		$(CCFLAGS) \
 | ||||||
|  | @ -113,7 +113,7 @@ $(_bins): out/%: out/%_unstripped | ||||||
| $(_sp_artifacts): $(_rs_src) | $(_sp_artifacts): $(_rs_src) | ||||||
| 	mkdir -p $(SERVICEPOINT_HEADER_OUT) || true | 	mkdir -p $(SERVICEPOINT_HEADER_OUT) || true | ||||||
| 	# generate servicepoint header and library to link against | 	# generate servicepoint header and library to link against | ||||||
| 	${CARGO} rustc $(CARGOFLAGS) -- $(RUSTFLAGS) | 	$(CARGO) rustc $(CARGOFLAGS) -- $(RUSTFLAGS) | ||||||
| 
 | 
 | ||||||
| $(_run_programs): run_%: out/% FORCE | $(_run_programs): run_%: out/% FORCE | ||||||
| 	./$< | 	./$< | ||||||
|  |  | ||||||
|  | @ -37,7 +37,6 @@ | ||||||
|               xe |               xe | ||||||
|               xz |               xz | ||||||
|               libgcc |               libgcc | ||||||
|               musl |  | ||||||
|               libunwind |               libunwind | ||||||
|               pkgsStatic.musl |               pkgsStatic.musl | ||||||
|             ]; |             ]; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter