diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000000000000000000000000000000000000..fce6e1915ac6b1fcd4b3b3c42b59d49863b468b0 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,8 @@ +[target.x86_64-apple-darwin] +linker = "o64-clang" +rustflags = [ + "-C", + "link-arg=-mmacosx-version-min=10.12", + "-C", + "target-feature=+crt-static", +] diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f3d33e668933d820a6e1ae11cacb946655fa2435..42a29286b7db861db31593efd6460f0c6d81c83c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,21 +1,19 @@ # Official language image. Look for the different tagged releases at: # https://hub.docker.com/r/library/rust/tags/ -image: "rust:latest" - stages: - - build_and_package + - build_linux + - build_macos - release -build_and_package: - stage: build_and_package +build_linux: + stage: build_linux image: rust:slim-buster script: - # Build the project + # Build the project for Linux - cargo build --release - # Install cargo-deb - - cargo install cargo-deb # Create Debian package + - cargo install cargo-deb - cargo deb --no-build - ls target/debian/*.deb | head -n 1 > debian_package.txt artifacts: @@ -24,15 +22,40 @@ build_and_package: - target/debian/*.deb - debian_package.txt cache: - key: - files: - - Cargo.lock + key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG" paths: - target/release - target/debian only: - tags +build_macos: + stage: build_macos + image: poka/rust-osxcross:1.0.2 + script: + # Install the required dependencies + - rustup target add x86_64-apple-darwin + # Build the project for macOS + - cargo build --release --target x86_64-apple-darwin + # Create the macOS bundle + - rm -rf target/macos + - mkdir -p target/macos + - cargo bundle --release --target x86_64-apple-darwin + # Zip the gcli.app before moving it + - cd target/x86_64-apple-darwin/release/bundle/osx + - echo -e "Unzip gcli.zip and move the gcli.app folder to /Applications/ folder.\nenjoy" > instructions.txt + - zip -r gcli.zip gcli.app instructions.txt + - mv gcli.zip ../../../../macos/ # target/macos/ + artifacts: + paths: + - target/macos + cache: + key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG" + paths: + - target/macos + only: + - tags + release: stage: release image: registry.gitlab.com/gitlab-org/release-cli:latest @@ -42,26 +65,23 @@ release: - git fetch --tags - LAST_VERSION=$(git tag --sort=-v:refname | sed -n '2p') - git log --pretty="format:- %s ([%h]($CI_PROJECT_URL/-/commit/%h)) " HEAD...$LAST_VERSION --reverse > release_description.txt - # Define release parameters release: - # Release name and description using the tag name name: "v$CI_COMMIT_TAG" description: "Latest changes:\n$(cat release_description.txt)" - # Set the tag for the release tag_name: "$CI_COMMIT_TAG" - # Attach the artifact to the release assets: links: - name: "gcli v$CI_COMMIT_TAG for Linux (binary)" - url: "$CI_PROJECT_URL/-/jobs/artifacts/$CI_COMMIT_TAG/raw/target/release/gcli?job=build_and_package" + url: "$CI_PROJECT_URL/-/jobs/artifacts/$CI_COMMIT_TAG/raw/target/release/gcli?job=build_linux" - name: "gcli v$CI_COMMIT_TAG Debian Package" - url: "$CI_PROJECT_URL/-/jobs/artifacts/$CI_COMMIT_TAG/raw/$(cat debian_package.txt)?job=build_and_package" - # Trigger release creation only for tagged commits + url: "$CI_PROJECT_URL/-/jobs/artifacts/$CI_COMMIT_TAG/raw/$(cat debian_package.txt)?job=build_linux" + - name: "gcli v$CI_COMMIT_TAG for macOS" + url: "$CI_PROJECT_URL/-/jobs/artifacts/$CI_COMMIT_TAG/raw/target/macos/gcli.zip?job=build_macos" only: - tags - # Not necessary but clearly shows the dependency dependencies: - - build_and_package + - build_linux + - build_macos artifacts: paths: - debian_package.txt diff --git a/Cargo.lock b/Cargo.lock index 444763b3e939217442dbc922cc3d7e0fabf91c2d..bba7cba22925f0fea43fb97765e10548195e500d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2092,7 +2092,7 @@ dependencies = [ [[package]] name = "gcli" -version = "0.2.11" +version = "0.2.12" dependencies = [ "age", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index af0852cfe15638914bebccee05ef3dfd230edac6..60d8d98e7921eaae18012fdddf1cb227f8accd42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,8 @@ rust-version = "1.75.0" license = "AGPL-3.0-only" name = "gcli" repository = "https://git.duniter.org/clients/rust/gcli-v2s" -version = "0.2.11" +description = "A command-line interface for Duniter v2s uses" +version = "0.2.12" [dependencies] # subxt is main dependency @@ -58,3 +59,8 @@ default = ["gdev"] # default runtime is "gdev", gdev network is available gdev = [] gtest = [] g1 = [] + +[package.metadata.bundle] +name = "gcli" +identifier = "com.axiomteam.gcli" +icon = ["gcli.png"] diff --git a/Dockerfile.ci b/Dockerfile.ci new file mode 100644 index 0000000000000000000000000000000000000000..0ed562c5fe500452004e7ab60e0fa979b66dade2 --- /dev/null +++ b/Dockerfile.ci @@ -0,0 +1,48 @@ +# Stage 1: Build environment with all dependencies +FROM rust:slim-bookworm as builder + +# Install necessary dependencies +RUN apt-get update && apt-get install -y \ + clang \ + llvm \ + make \ + file \ + git \ + curl \ + cmake \ + python3 \ + python3-dev \ + python3-pip + +# Clone osxcross repository and set up +RUN git clone https://github.com/tpoechtrager/osxcross.git /opt/osxcross && \ + cd /opt/osxcross && \ + ./tools/get_dependencies.sh && \ + cd /opt/osxcross/tarballs && \ + curl -LO https://github.com/joseluisq/macosx-sdks/releases/download/10.12/MacOSX10.12.sdk.tar.xz && \ + cd /opt/osxcross && \ + UNATTENDED=yes ./build.sh + +# Stage 2: Create the final image with only the necessary files +FROM rust:slim-bookworm + +# Install cargo-bundle +RUN cargo install cargo-bundle + +RUN apt-get update && apt-get install -y --no-install-recommends clang zip; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/*; + +# Copy cargo plugins from the builder stage +COPY --from=builder /opt/osxcross/target /opt/osxcross/target + +# Set environment variables for osxcross and Rust +ENV PATH="/opt/osxcross/target/bin:/usr/local/cargo/bin:$PATH" +ENV CC="o64-clang" +ENV CXX="o64-clang++" + +# Add rust target for macOS +RUN rustup target add x86_64-apple-darwin + +# Define the entrypoint +CMD ["bash"]