Skip to content

Commit

Permalink
feat: enhance cross-platform compilation support for polycrypt-rs v0.…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
HenryOwenz committed Jan 1, 2025
1 parent f437d28 commit a90fc6f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)"
Expand Down Expand Up @@ -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)"
Expand Down

0 comments on commit a90fc6f

Please sign in to comment.