Giter VIP home page Giter VIP logo

cranix's Introduction

Cranix: A High-Level Crane API Override ๐Ÿฆ€ โ„๏ธ

Cranix introduces new integrations to the Crane APIs.

Integrations

  • Mold: Enable by setting useMold = true.
  • Cranelift: Enable by setting useCranelift = true.
  • Workspace Package: To create your own Workspace Package derivation, simply add workspaceTargetName = "myBinName". Cranix handles the rest ๐Ÿฆ€.

APIs

  • craneLib.build{Sys}DepsOnly: A helper for craneLib.buildDepsOnly, including all previously explained integrations.
  • craneLib.build{Sys}Package: A helper for craneLib.buildPackageOnly, including all previously explained integrations.
  • craneLib.build{Sys}Bundle: Packs your system dependencies, package and nix run app. You're allowed to add args.cargoArtifacts.
  • craneLib.buildCranix{DepsOnly,Package,Bundle}: Make your own crane build process with cranix features.

Supported Systems

  • Windows x86_64 GNU ABI
  • Linux x86_64 GNU ABI

Feel free to add CARGO_{TRIPLE|COMMAND}_RUSTFLAG or nativeBuildInputs. They won't break anything in the new APIs.

Custom attrs

  • useCranelift
    • Description: Enable Mold backend for all build phases.
    • Type: Boolean
  • useMold
    • Description: Enable Mold backend for all build phases.
    • Type: Boolean
  • isLibTarget
    • Description: Build defined lib in workspace (For future implementations).
    • Type: Boolean
  • workspaceTargetName
    • Description: Workspace target name (Build bin by default).
    • Type: String

How to use

{
  description = "My Custom Rust Project";
  inputs = {
    flake-parts.url = "github:hercules-ci/flake-parts";
    flake-utils.url = "github:numtide/flake-utils";
    crane.url = "github:ipetkov/crane";
    cranix.url = "github:Lemin-n/cranix";
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    fenix.url = "github:nix-community/fenix/monthly";
  };
  outputs = {
    fenix,
    nixpkgs,
    flake-utils,
    crane,
    cranix,
    ...
  }:
    flake-utils.lib.eachDefaultSystem (system:
      with nixpkgs.lib; let
        toolchain = with fenix.packages.${system};
          combine [
            complete.cargo
            complete.clippy
            complete.rust-src
            complete.rustc
            complete.rustfmt
            complete.rust-std
            complete.rustc-codegen-cranelift-preview
            targets.x86_64-pc-windows-gnu.latest.rust-std
            targets.x86_64-unknown-linux-gnu.latest.rust-std
          ];
        craneLib = crane.lib.${system}.overrideToolchain toolchain;
        cranixLib = craneLib.overrideScope' (cranix.lib.${system}.craneOverride);

        commonArg = {
          src = ./.;
          doCheck = false;
        };
        linuxApp =
          cranixLib.buildLinuxBundle (commonArg //{
          useMold = true;
          useCranelift = true;
        });
        windowsApp =
          cranixLib.buildWindowsBundle commonArg;
      in {
        # nix build
        packages = rec {
          linux = linuxApp.pkg;
          windows = windowsApp.pkg;
          default = linux;
        };

        # nix run
        app rec {
          linux = linuxApp.app;
          windows = windowsApp.app;
          default = linux;
        }

        # nix develop
        devShells.default = cranixLib.devShell {
          packages = with nixpkgs.legacyPackages.${system}; [
            openssl.dev
            pkg-config
          ];
        };
      });
}

cranix's People

Contributors

lemin-n avatar

Stargazers

Beicker avatar  avatar krovuxdev avatar antx avatar L I N U X ( ใƒชใƒŠใƒƒใ‚ฏใ‚น ) avatar Sergio Alejandro Ribera Costa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.