Skip to content

Commit

Permalink
init rust
Browse files Browse the repository at this point in the history
  • Loading branch information
viperML committed Aug 4, 2024
1 parent f393803 commit 1033a5a
Show file tree
Hide file tree
Showing 14 changed files with 1,895 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
use nix
use flake

PATH_add "$PWD/node_modules/.bin"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
/node_modules
npm-debug.log*
*.tgz
neohome-rs/index.*
neohome-rs/*.node
target
8 changes: 7 additions & 1 deletion astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ export default defineConfig({
format: "file"
},
vite: {
assetsInclude: [
"**/*.node"
],
plugins: [
arraybuffer()
]
],
ssr: {
external: ["neohome-rs"]
}
},
trailingSlash: "never",
});
44 changes: 44 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
(fs.unions [
./src
./public
./neohome-rs
(fs.fileFilter (file: file.hasExt "ts") r)
(fs.fileFilter (file: file.hasExt "json") r)
]);
Expand All @@ -38,6 +39,28 @@
};
npmConfigHook = importNpmLock.npmConfigHook;

preBuild = ''
pushd neohome-rs
npm run build
popd
'';

cargoDeps = rustPlatform.importCargoLock {
lockFile = ./neohome-rs/Cargo.lock;
};

cargoRoot = "neohome-rs";

nativeBuildInputs = [
rustPlatform.cargoSetupHook
rustc
cargo
];

preInstall = ''
rm -rf $cargoRoot/target
'';

env =
{
ASTRO_TELEMETRY_DISABLED = true;
Expand All @@ -47,5 +70,26 @@
});
};
};

devShells.${system}.default = with pkgs;
mkShell {
packages = [
cargo
rustc
rust-analyzer-unwrapped
rustfmt

nodejs
yarn

tailwindcss
# nodePackages.wrangler
nodePackages."@astrojs/language-server"
nodePackages.typescript-language-server

ltex-ls
];
env.RUST_SRC_PATH = "${rustPlatform.rustLibSrc}";
};
};
}
271 changes: 271 additions & 0 deletions neohome-rs/Cargo.lock

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

19 changes: 19 additions & 0 deletions neohome-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
edition = "2021"
name = "neohome-rs"
version = "0.0.0"

[lib]
crate-type = ["cdylib"]

[dependencies]
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
napi = { version = "2.12.2", default-features = false, features = ["napi4"] }
napi-derive = "2.12.2"

[build-dependencies]
napi-build = "2.0.1"

[profile.release]
lto = true
strip = "symbols"
5 changes: 5 additions & 0 deletions neohome-rs/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extern crate napi_build;

fn main() {
napi_build::setup();
}
Loading

0 comments on commit 1033a5a

Please sign in to comment.