diff --git a/-/fifthtry.github.io/easy-contest/ec/Cargo.lock b/-/fifthtry.github.io/easy-contest/ec/Cargo.lock new file mode 100644 index 0000000..86c4c0d --- /dev/null +++ b/-/fifthtry.github.io/easy-contest/ec/Cargo.lock @@ -0,0 +1,276 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "chrono" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" +dependencies = [ + "num-traits", + "serde", +] + +[[package]] +name = "diesel" +version = "2.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03fc05c17098f21b89bc7d98fe1dd3cce2c11c2ad8e145f2a44fe08ed28eb559" +dependencies = [ + "bitflags", + "byteorder", + "diesel_derives", + "itoa", +] + +[[package]] +name = "diesel_derives" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d02eecb814ae714ffe61ddc2db2dd03e6c49a42e269b5001355500d431cce0c" +dependencies = [ + "diesel_table_macro_syntax", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "diesel_table_macro_syntax" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc5557efc453706fed5e4fa85006fe9817c224c3f480a34c7e5959fd700921c5" +dependencies = [ + "syn", +] + +[[package]] +name = "ec" +version = "0.1.0" +dependencies = [ + "bytes", + "ft-sdk", + "http", + "serde", + "serde_json", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "ft-sdk" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac01a07cfdb0d05928cfba5299f62fa141c41dad23541d080d0f1395dc203f43" +dependencies = [ + "bytes", + "chrono", + "diesel", + "ft-sys", + "http", + "serde", + "serde_json", + "serde_urlencoded", + "thiserror", +] + +[[package]] +name = "ft-sys" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626a184e388c1b125406a464b5d11d9f215ff3fe28f7078f04e3d8f6b452b7f5" +dependencies = [ + "bytes", + "chrono", + "diesel", + "ft-sys-shared", + "http", + "serde", + "serde_json", +] + +[[package]] +name = "ft-sys-shared" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b9ba40e9516fd4cf1a8d11b834ea7e9d4670db6594461ddfdae8b5bf9b1d53" +dependencies = [ + "bytes", + "http", + "serde", + "thiserror", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "proc-macro2" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "syn" +version = "2.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/-/fifthtry.github.io/easy-contest/ec/Cargo.toml b/-/fifthtry.github.io/easy-contest/ec/Cargo.toml new file mode 100644 index 0000000..c012267 --- /dev/null +++ b/-/fifthtry.github.io/easy-contest/ec/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "ec" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["cdylib"] + +[dependencies] +ft-sdk = "0.1.1" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +http = "1.0" +bytes = "1.0" diff --git a/-/fifthtry.github.io/easy-contest/ec/src/lib.rs b/-/fifthtry.github.io/easy-contest/ec/src/lib.rs new file mode 100644 index 0000000..bd1664b --- /dev/null +++ b/-/fifthtry.github.io/easy-contest/ec/src/lib.rs @@ -0,0 +1,10 @@ +extern crate self as ec; + +mod route; + +#[no_mangle] +pub extern "C" fn main_ft() { + let req = ft_sdk::http::current_request(); + let resp = route::route(req); + ft_sdk::http::send_response(resp); +} diff --git a/-/fifthtry.github.io/easy-contest/ec/src/route/mod.rs b/-/fifthtry.github.io/easy-contest/ec/src/route/mod.rs new file mode 100644 index 0000000..f701be4 --- /dev/null +++ b/-/fifthtry.github.io/easy-contest/ec/src/route/mod.rs @@ -0,0 +1,46 @@ +pub fn route(r: http::Request) -> http::Response { + use ft_sdk::Layout; + + match r.uri().path() { + // site + "/wasm-test/" => Dummy::page::(r), + t => ft_sdk::not_found!("no route for {t}"), + } +} + +struct Dummy {} + +impl ft_sdk::Layout for Dummy { + type Error = ft_sdk::Error; + + fn from_in(_in_: ft_sdk::In, _ty: ft_sdk::RequestType) -> Result { + ft_sdk::println!("from_in 1"); + + Ok(Self {}) + } + + fn json(&mut self, page: serde_json::Value) -> Result { + Ok(serde_json::json!({"page": page})) + } + + fn render_error(e: Self::Error) -> http::Response { + ft_sdk::println!("rendering error: {e:?}"); + ft_sdk::json_response(serde_json::json!({ + "error": e.to_string(), + })) + } +} + +#[derive(serde::Serialize)] +pub struct Hello { + msg: String, +} + +impl ft_sdk::Page for Hello { + fn page(_i: &mut Dummy) -> Result { + ft_sdk::println!("hello wasm"); + Ok(Hello { + msg: "hello from ft_sdk".into(), + }) + } +} diff --git a/-/fifthtry.github.io/easy-contest/flake.lock b/-/fifthtry.github.io/easy-contest/flake.lock new file mode 100644 index 0000000..7481460 --- /dev/null +++ b/-/fifthtry.github.io/easy-contest/flake.lock @@ -0,0 +1,96 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1711370797, + "narHash": "sha256-2xu0jVSjuKhN97dqc4bVtvEH52Rwh6+uyI1XCnzoUyI=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "c726225724e681b3626acc941c6f95d2b0602087", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1706487304, + "narHash": "sha256-LE8lVX28MV2jWJsidW13D2qrHU/RUUONendL2Q/WlJg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "90f456026d284c22b3e3497be980b2e47d0b28ac", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1711419061, + "narHash": "sha256-+5M/czgYGqs/jKmi8bvYC+JUYboUKNTfkRiesXopeXQ=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "4c11d2f698ff1149f76b69e72852d5d75f492d0c", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/-/fifthtry.github.io/easy-contest/flake.nix b/-/fifthtry.github.io/easy-contest/flake.nix new file mode 100644 index 0000000..b852f94 --- /dev/null +++ b/-/fifthtry.github.io/easy-contest/flake.nix @@ -0,0 +1,44 @@ +{ + description = "Fifthtry easy contest"; + + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + inputs.rust-overlay.url = "github:oxalica/rust-overlay"; + + outputs = { self, nixpkgs, rust-overlay }: + let + system = "x86_64-linux"; + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { + inherit system overlays; + }; + + toolchain = pkgs.rust-bin.stable.latest.default.override { + targets = [ "wasm32-unknown-unknown" ]; + extensions = [ "rustfmt" "clippy" "rust-src" ]; + }; + in + { + devShells.${system}.default = pkgs.mkShell { + name = "ec-shell"; + nativeBuildInputs = with pkgs; [ + pkg-config + postgresql_14 + openssl.dev + ]; + buildInputs = with pkgs; [ + diesel-cli + + toolchain + rust-analyzer-unwrapped + ]; + + shellHook = '' + source scripts/auto.sh + ''; + + RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library"; + }; + + formatter.${system} = pkgs.nixpkgs-fmt; + }; +} diff --git a/-/fifthtry.github.io/easy-contest/scripts/auto.sh b/-/fifthtry.github.io/easy-contest/scripts/auto.sh new file mode 100644 index 0000000..987f9be --- /dev/null +++ b/-/fifthtry.github.io/easy-contest/scripts/auto.sh @@ -0,0 +1,8 @@ +function build-wasm() { + pushd "ec" || return 1 + cargo build --target wasm32-unknown-unknown --release || return 1 + cp ./target/wasm32-unknown-unknown/release/ec.wasm ../ || return 1 + + popd || return 1 +} + diff --git a/ec/Cargo.lock b/ec/Cargo.lock new file mode 100644 index 0000000..86c4c0d --- /dev/null +++ b/ec/Cargo.lock @@ -0,0 +1,276 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "chrono" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" +dependencies = [ + "num-traits", + "serde", +] + +[[package]] +name = "diesel" +version = "2.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03fc05c17098f21b89bc7d98fe1dd3cce2c11c2ad8e145f2a44fe08ed28eb559" +dependencies = [ + "bitflags", + "byteorder", + "diesel_derives", + "itoa", +] + +[[package]] +name = "diesel_derives" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d02eecb814ae714ffe61ddc2db2dd03e6c49a42e269b5001355500d431cce0c" +dependencies = [ + "diesel_table_macro_syntax", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "diesel_table_macro_syntax" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc5557efc453706fed5e4fa85006fe9817c224c3f480a34c7e5959fd700921c5" +dependencies = [ + "syn", +] + +[[package]] +name = "ec" +version = "0.1.0" +dependencies = [ + "bytes", + "ft-sdk", + "http", + "serde", + "serde_json", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "ft-sdk" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac01a07cfdb0d05928cfba5299f62fa141c41dad23541d080d0f1395dc203f43" +dependencies = [ + "bytes", + "chrono", + "diesel", + "ft-sys", + "http", + "serde", + "serde_json", + "serde_urlencoded", + "thiserror", +] + +[[package]] +name = "ft-sys" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626a184e388c1b125406a464b5d11d9f215ff3fe28f7078f04e3d8f6b452b7f5" +dependencies = [ + "bytes", + "chrono", + "diesel", + "ft-sys-shared", + "http", + "serde", + "serde_json", +] + +[[package]] +name = "ft-sys-shared" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b9ba40e9516fd4cf1a8d11b834ea7e9d4670db6594461ddfdae8b5bf9b1d53" +dependencies = [ + "bytes", + "http", + "serde", + "thiserror", +] + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "proc-macro2" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "syn" +version = "2.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/ec/Cargo.toml b/ec/Cargo.toml new file mode 100644 index 0000000..c012267 --- /dev/null +++ b/ec/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "ec" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["cdylib"] + +[dependencies] +ft-sdk = "0.1.1" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +http = "1.0" +bytes = "1.0" diff --git a/ec/src/lib.rs b/ec/src/lib.rs new file mode 100644 index 0000000..bd1664b --- /dev/null +++ b/ec/src/lib.rs @@ -0,0 +1,10 @@ +extern crate self as ec; + +mod route; + +#[no_mangle] +pub extern "C" fn main_ft() { + let req = ft_sdk::http::current_request(); + let resp = route::route(req); + ft_sdk::http::send_response(resp); +} diff --git a/ec/src/route/mod.rs b/ec/src/route/mod.rs new file mode 100644 index 0000000..f701be4 --- /dev/null +++ b/ec/src/route/mod.rs @@ -0,0 +1,46 @@ +pub fn route(r: http::Request) -> http::Response { + use ft_sdk::Layout; + + match r.uri().path() { + // site + "/wasm-test/" => Dummy::page::(r), + t => ft_sdk::not_found!("no route for {t}"), + } +} + +struct Dummy {} + +impl ft_sdk::Layout for Dummy { + type Error = ft_sdk::Error; + + fn from_in(_in_: ft_sdk::In, _ty: ft_sdk::RequestType) -> Result { + ft_sdk::println!("from_in 1"); + + Ok(Self {}) + } + + fn json(&mut self, page: serde_json::Value) -> Result { + Ok(serde_json::json!({"page": page})) + } + + fn render_error(e: Self::Error) -> http::Response { + ft_sdk::println!("rendering error: {e:?}"); + ft_sdk::json_response(serde_json::json!({ + "error": e.to_string(), + })) + } +} + +#[derive(serde::Serialize)] +pub struct Hello { + msg: String, +} + +impl ft_sdk::Page for Hello { + fn page(_i: &mut Dummy) -> Result { + ft_sdk::println!("hello wasm"); + Ok(Hello { + msg: "hello from ft_sdk".into(), + }) + } +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7481460 --- /dev/null +++ b/flake.lock @@ -0,0 +1,96 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1711370797, + "narHash": "sha256-2xu0jVSjuKhN97dqc4bVtvEH52Rwh6+uyI1XCnzoUyI=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "c726225724e681b3626acc941c6f95d2b0602087", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1706487304, + "narHash": "sha256-LE8lVX28MV2jWJsidW13D2qrHU/RUUONendL2Q/WlJg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "90f456026d284c22b3e3497be980b2e47d0b28ac", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1711419061, + "narHash": "sha256-+5M/czgYGqs/jKmi8bvYC+JUYboUKNTfkRiesXopeXQ=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "4c11d2f698ff1149f76b69e72852d5d75f492d0c", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b852f94 --- /dev/null +++ b/flake.nix @@ -0,0 +1,44 @@ +{ + description = "Fifthtry easy contest"; + + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + inputs.rust-overlay.url = "github:oxalica/rust-overlay"; + + outputs = { self, nixpkgs, rust-overlay }: + let + system = "x86_64-linux"; + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { + inherit system overlays; + }; + + toolchain = pkgs.rust-bin.stable.latest.default.override { + targets = [ "wasm32-unknown-unknown" ]; + extensions = [ "rustfmt" "clippy" "rust-src" ]; + }; + in + { + devShells.${system}.default = pkgs.mkShell { + name = "ec-shell"; + nativeBuildInputs = with pkgs; [ + pkg-config + postgresql_14 + openssl.dev + ]; + buildInputs = with pkgs; [ + diesel-cli + + toolchain + rust-analyzer-unwrapped + ]; + + shellHook = '' + source scripts/auto.sh + ''; + + RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library"; + }; + + formatter.${system} = pkgs.nixpkgs-fmt; + }; +} diff --git a/manifest.json b/manifest.json index 6e2f6ba..c95e8b3 100644 --- a/manifest.json +++ b/manifest.json @@ -30,11 +30,41 @@ "checksum": "4AC02C312CD49078232DCEA74827AD05B49402125CA79BB0FEFE1B62173177E8", "size": 1063 }, + "ec/Cargo.lock": { + "name": "ec/Cargo.lock", + "checksum": "EBB625D8EE8203C7BD393051D72A21119486C34627948FF9C8A209210B7052B1", + "size": 6714 + }, + "ec/Cargo.toml": { + "name": "ec/Cargo.toml", + "checksum": "4BAF1502A57F2CB36A870E27F23B2846D93578313BC5DC7C08568981B2B3464F", + "size": 313 + }, + "ec/src/lib.rs": { + "name": "ec/src/lib.rs", + "checksum": "C5EA4D065FCB4D96B44F5E49BEA7E64C447105A938355ED74D479C365A2E1891", + "size": 203 + }, + "ec/src/route/mod.rs": { + "name": "ec/src/route/mod.rs", + "checksum": "64D24226621D43BCFCC31ED48F0BF4AFA060E76311D2DBF244D200C8DA7829DA", + "size": 1175 + }, "favicon.ico": { "name": "favicon.ico", "checksum": "65056A1D6C6AAE6E3DC4626E29F4BD4B628B17A8E9CC1D3A5E8FE9F6743F306B", "size": 15406 }, + "flake.lock": { + "name": "flake.lock", + "checksum": "C977FB32E3FDD322D72A4EA04470ED36CB33D590381A6878FA567CFB56A15765", + "size": 2461 + }, + "flake.nix": { + "name": "flake.nix", + "checksum": "240DA4EA5667250994F97689805295A0FB491A1962305D0E10871AEC9E9F48E6", + "size": 1083 + }, "index.ftd": { "name": "index.ftd", "checksum": "FB3923216E6D1BCDAD11344E1627D901F2B6B6DD25345574059DAA9D26297D37", @@ -54,8 +84,18 @@ "name": "rules.ftd", "checksum": "E45E5DF6FFE4BF062C1111417D0157A194C04948E8BAD77EB221699D9CB4FCB8", "size": 99 + }, + "scripts/auto.sh": { + "name": "scripts/auto.sh", + "checksum": "8838A1913C0C04DE52AA5920F724451EED317E9B1910231EE47846329ADF1DC9", + "size": 217 + }, + "todo.md": { + "name": "todo.md", + "checksum": "3F51194CC57AFBF677C47A3425228171822EFE28F4F9CC58F3216CFA09A7358B", + "size": 28 } }, "zip_url": "https://codeload.github.com/fifthtry/easy-contest/zip/refs/heads/main", - "checksum": "FB70F9F76BD19CF9E093F645F44F786D9B393A84041207C2C00EFD50805EA294" + "checksum": "A33388F0B77FD292203CBF467D5BE0AC4518CD954780EE87C53E75158A09D929" } diff --git a/scripts/auto.sh b/scripts/auto.sh new file mode 100644 index 0000000..987f9be --- /dev/null +++ b/scripts/auto.sh @@ -0,0 +1,8 @@ +function build-wasm() { + pushd "ec" || return 1 + cargo build --target wasm32-unknown-unknown --release || return 1 + cp ./target/wasm32-unknown-unknown/release/ec.wasm ../ || return 1 + + popd || return 1 +} +