Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
- uses: ners/simply-nix@main
- uses: ryanccn/attic-action@v0
with:
endpoint: https://cache.ners.ch
Expand Down
2 changes: 1 addition & 1 deletion examples/ADT.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data Point a = Point a a deriving (Show)
-- data Either ... {- already defined in 'Data.Either'

-- Make some 'Storable' instances
mkStorable [t| forall a. Storable a => Storable (Point a) |]
mkMarshalable [t| forall a. Storable a => Storable (Point a) |]

-- Generate corresponding Rust types
extendContext (rustTyCtx [t| forall a. Point a |])
Expand Down
2 changes: 1 addition & 1 deletion examples/PreludeStuff.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ setCrateRoot []

-- Some ADTs
data Point a = Point a a deriving (Show)
mkStorable [t| forall a. Storable a => Storable (Point a) |]
mkMarshalable [t| forall a. Storable a => Storable (Point a) |]
extendContext (rustTyCtx [t| forall a. Point a |])

main = do
Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 47 additions & 29 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,68 @@
);
sourceFilter = root: with lib.fileset; toSource {
inherit root;
fileset = fileFilter (file: any file.hasExt [ "cabal" "hs" "hsc" "md" ]) root;
fileset = fileFilter
(file: any file.hasExt [ "cabal" "hs" "md" ])
root;
};
ghcsFor = pkgs: with lib; foldlAttrs
(acc: name: hp:
(acc: name: hp':
let
version = getVersion hp.ghc;
hp = tryEval hp';
version = getVersion hp.value.ghc;
majorMinor = versions.majorMinor version;
ghcName = "ghc${replaceStrings ["."] [""] majorMinor}";
in
if hp ? ghc && ! acc ? ${ghcName} && versionAtLeast version "9.2" && versionOlder version "9.11"
then acc // { ${ghcName} = hp; }
if hp.value ? ghc && ! acc ? ${ghcName} && versionAtLeast version "9.4" && versionOlder version "9.13"
then acc // { ${ghcName} = hp.value; }
else acc
)
{ }
pkgs.haskell.packages;
hpsFor = pkgs: { default = pkgs.haskellPackages; } // ghcsFor pkgs;
pname = "inline-rust";
src = sourceFilter ./.;
overlay = lib.composeManyExtensions [
(final: prev: {
haskell = prev.haskell // {
packageOverrides = lib.composeManyExtensions [
prev.haskell.packageOverrides
(hfinal: hprev: with prev.haskell.lib.compose; {
language-rust = hfinal.callCabal2nix "language-rust" inputs.language-rust { };
${pname} = addBuildDepend prev.cargo (hfinal.callCabal2nix pname src { });
})
];
};
})
];
pnames = [ pname ];
haskell-overlay = final: prev: hfinal: hprev: with prev.haskell.lib.compose; {
language-rust = hfinal.callCabal2nix "language-rust" inputs.language-rust { };
${pname} = addBuildDepend prev.cargo (hfinal.callCabal2nix pname (sourceFilter ./.) { });
};
overlay = final: prev: {
haskell = prev.haskell // {
packageOverrides = lib.composeManyExtensions [
prev.haskell.packageOverrides
(haskell-overlay final prev)
];
};
};
in
{
overlays = {
default = overlay;
haskell = haskell-overlay;
};
}
//
foreach inputs.nixpkgs.legacyPackages
(system: pkgs':
let
pkgs = pkgs'.extend overlay;
hps = hpsFor pkgs;
libs = pkgs.buildEnv {
name = "${pname}-libs";
paths = map (hp: hp.${pname}) (attrValues hps);
paths =
lib.mapCartesianProduct
({ hp, pname }: hp.${pname})
{ hp = attrValues hps; pname = pnames; };
pathsToLink = [ "/lib" ];
};
docs = pkgs.haskell.lib.documentationTarball hps.default.${pname};
sdist = pkgs.haskell.lib.sdistTarball hps.default.${pname};
docs = pkgs.buildEnv {
name = "${pname}-docs";
paths = map (pname: pkgs.haskell.lib.documentationTarball hps.default.${pname}) pnames;
};
sdist = pkgs.buildEnv {
name = "${pname}-sdist";
paths = map (pname: pkgs.haskell.lib.sdistTarball hps.default.${pname}) pnames;
};
docsAndSdist = pkgs.linkFarm "${pname}-docsAndSdist" { inherit docs sdist; };
in
{
Expand All @@ -80,18 +98,18 @@
devShells.${system} =
foreach hps (ghcName: hp: {
${ghcName} = hp.shellFor {
packages = ps: [ hp.${pname} ];
packages = ps: map (pname: ps.${pname}) pnames;
nativeBuildInputs = with pkgs'; with haskellPackages; [
pkgs'.haskellPackages.cabal-install
fourmolu
haskell-language-server
cabal-gild
cabal-install
cargo
fourmolu
rustc
] ++ lib.optionals (lib.versionAtLeast (lib.getVersion hp.ghc) "9.4") [
hp.haskell-language-server
];
};
});
}
) // {
overlays.default = overlay;
};
);
}
25 changes: 18 additions & 7 deletions inline-rust.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,25 @@ source-repository head

library
hs-source-dirs: src
ghc-options: -Wall
ghc-options: -Wall -ddump-splices -ddump-to-file -g
default-language: Haskell2010

exposed-modules: Language.Rust.Inline
Language.Rust.Inline.TH
other-modules: Language.Rust.Inline.Context
Language.Rust.Inline.Context.Prelude
Language.Rust.Inline.Context.ByteString
Language.Rust.Inline.Context.Marshalable
Language.Rust.Inline.Context.Prelude
Language.Rust.Inline.Context.Vector
Language.Rust.Inline.Internal
Language.Rust.Inline.Marshal
Language.Rust.Inline.Parser
Language.Rust.Inline.Pretty
Language.Rust.Inline.Internal
Language.Rust.Inline.Storable.Tuple
Language.Rust.Inline.TH.Marshalable
Language.Rust.Inline.TH.ReprC
Language.Rust.Inline.TH.Storable
Language.Rust.Inline.TH.Utilities
Language.Rust.Inline.TH.ReprC

other-extensions: DeriveDataTypeable
, CPP
Expand All @@ -62,7 +66,7 @@ library

test-suite spec
hs-source-dirs: tests
ghc-options: -threaded
ghc-options: -threaded -ddump-splices -ddump-to-file -g

if os(windows)
extra-libraries:
Expand All @@ -75,7 +79,11 @@ test-suite spec
main-is: Main.hs

type: exitcode-stdio-1.0
default-language: Haskell2010
default-language: Haskell2010
default-extensions: ExplicitForAll
, QuasiQuotes
, ScopedTypeVariables
, TemplateHaskell
other-modules: SimpleTypes
, GhcUnboxedTypes
, PointerTypes
Expand All @@ -85,10 +93,13 @@ test-suite spec
, Submodule
, Submodule.Submodule
, ByteStrings
, Vectors
, ForeignPtr
build-depends: base
build-depends: async
, base
, inline-rust
, language-rust
, hspec
, ghc-prim
, bytestring
, unliftio
Loading