-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
86 lines (73 loc) · 2.26 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Define build mode (default to release)
BUILD_MODE ?= release # Set to 'debug' or 'release'
# Define project paths
C_SHARP_PROJECT = CSharpDemo
RUST_PROJECT = rust_test
# Define output paths based on build mode
ifeq ($(BUILD_MODE), debug)
RUST_OUTPUT_DIR = $(RUST_PROJECT)/target/debug
C_SHARP_OUTPUT_DIR = $(C_SHARP_PROJECT)/bin/Debug/net9.0
CARGO_BUILD_FLAG =
DOTNET_BUILD_FLAG =
else
RUST_OUTPUT_DIR = $(RUST_PROJECT)/target/release
C_SHARP_OUTPUT_DIR = $(C_SHARP_PROJECT)/bin/Release/net9.0
CARGO_BUILD_FLAG = --release
DOTNET_BUILD_FLAG = --configuration Release
endif
# Rust library name
RUST_LIB_NAME = librust_test
# Detect OS and set shared library extension
ifeq ($(OS), Windows_NT)
RUST_LIB_EXT = dll
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Linux)
RUST_LIB_EXT = so
else ifeq ($(UNAME_S), Darwin)
RUST_LIB_EXT = dylib
endif
endif
# Full path to the compiled Rust shared library
RUST_LIB_PATH = $(RUST_OUTPUT_DIR)/$(RUST_LIB_NAME).$(RUST_LIB_EXT)
# Build Rust library
.PHONY: rust
rust:
@echo "Building Rust library in $(BUILD_MODE) mode..."
cd $(RUST_PROJECT) && cargo build $(CARGO_BUILD_FLAG)
# Build C# project
.PHONY: csharp
csharp: rust
@echo "Building C# project in $(BUILD_MODE) mode..."
dotnet build $(C_SHARP_PROJECT) $(DOTNET_BUILD_FLAG)
# Copy Rust library to C# output folder
.PHONY: copy_rust_lib
copy_rust_lib: rust
@echo "Copying Rust library to C# output directory: $(C_SHARP_OUTPUT_DIR)"
mkdir -p $(C_SHARP_OUTPUT_DIR) # Ensure directory exists
cp $(RUST_LIB_PATH) $(C_SHARP_OUTPUT_DIR)/
# Clean both projects
.PHONY: clean
clean:
@echo "Cleaning Rust and C# projects..."
cd $(RUST_PROJECT) && cargo clean
dotnet clean $(C_SHARP_PROJECT)
# Run C# application
.PHONY: run
run: csharp copy_rust_lib
@echo "Running C# application in $(BUILD_MODE) mode..."
cd $(C_SHARP_PROJECT) && dotnet run $(DOTNET_BUILD_FLAG)
# Clean both projects (debug & release)
.PHONY: clean
clean:
@echo "Cleaning Rust and C# projects..."
cd $(RUST_PROJECT) && cargo clean
dotnet clean $(C_SHARP_PROJECT)
rm -rf $(C_SHARP_PROJECT)/bin $(C_SHARP_PROJECT)/obj
rm -rf $(RUST_PROJECT)/target
# Full build
.PHONY: all
all: rust csharp copy_rust_lib
# Run everything
.PHONY: full_run
full_run: all run