From a90fc6ffe96f689409567c19a95ef196e8f097e7 Mon Sep 17 00:00:00 2001 From: HenryOwenz Date: Tue, 31 Dec 2024 18:07:23 -0600 Subject: [PATCH] feat: enhance cross-platform compilation support for polycrypt-rs v0.4.5-beta.1 - Add musl target support for Linux cross-compilation - Configure cargo for x86_64-unknown-linux-musl target - Add build-linux target in Makefile for cross-compilation - Add build-all target to compile for both native and Linux - Update cleanup process to handle cross-compiled artifacts - Improve platform-specific library handling - Add CARGO_TARGET environment variable for Mac cross-compilation BREAKING CHANGES: - Requires musl-tools for Linux builds - Changes build process to support cross-compilation --- .cargo/config.toml | 3 ++- Makefile | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 0519ecb..04d4a8f 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1 +1,2 @@ - \ No newline at end of file +[target.x86_64-unknown-linux-musl] +linker = "x86_64-linux-musl-gcc" \ No newline at end of file diff --git a/Makefile b/Makefile index 74e7d4e..bd6900d 100644 --- a/Makefile +++ b/Makefile @@ -26,10 +26,14 @@ else endif ifeq ($(UNAME_S),Darwin) LIB_EXT := dylib + # For cross-compilation from Mac + CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER := x86_64-linux-musl-gcc + export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER endif endif LIB_NAME := libpolycrypt_rs.$(LIB_EXT) +LINUX_LIB_NAME := libpolycrypt_rs.so # Colors CYAN := \033[36m @@ -60,6 +64,24 @@ build: @echo "$(GREEN)Library copied successfully.$(RESET_COLOR)" @echo "$(DASH_LINE)" +# Add cross-compilation target +build-linux: + @echo "$(DASH_LINE)" + @echo "$(CYAN)Cross-compiling for Linux x86_64...$(RESET_COLOR)" + @echo "$(DASH_LINE)" + @rustup target add x86_64-unknown-linux-musl + @RUSTFLAGS="-C target-feature=-crt-static" $(CARGO) build --release --target x86_64-unknown-linux-musl + @echo "$(GREEN)Linux build completed successfully.$(RESET_COLOR)" + @echo "$(DASH_LINE)" + @echo "$(CYAN)Copying $(LINUX_LIB_NAME) to staging directory...$(RESET_COLOR)" + @mkdir -p $(RELEASE_DIR)/linux + @cp $(TARGET_DIR)/x86_64-unknown-linux-musl/release/$(LINUX_LIB_NAME) $(RELEASE_DIR)/linux/ + @echo "$(GREEN)Linux library copied successfully.$(RESET_COLOR)" + @echo "$(DASH_LINE)" + +# Add a combined build target for both native and Linux +build-all: build build-linux + # Build for debug debug: @echo "$(DASH_LINE)" @@ -154,6 +176,7 @@ clean: @rm -f $(GO_EXAMPLES_DIR)/polycrypt/libpolycrypt_rs.* @rm -f $(GO_EXAMPLES_DIR)/polycrypt_ffi_go @rm -f $(PYTHON_EXAMPLES_DIR)/polycrypt/libpolycrypt_rs.* + @rm -rf $(RELEASE_DIR)/linux @echo "$(DASH_LINE)" @echo "$(GREEN)Cleaning completed.$(RESET_COLOR)" @echo "$(DASH_LINE)"