--- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -53,38 +53,98 @@ needs: [test] strategy: matrix: - os: [ubuntu-latest, macOS-latest, windows-latest] + target: + # Tier 1 + - aarch64-unknown-linux-gnu + - i686-pc-windows-gnu + - i686-pc-windows-msvc + - i686-unknown-linux-gnu + - x86_64-apple-darwin + - x86_64-pc-windows-gnu + - x86_64-pc-windows-msvc + - x86_64-unknown-linux-gnu + + # Other + - x86_64-unknown-linux-musl include: - - os: ubuntu-latest - rust: stable - target: x86_64-unknown-linux-musl + - target: aarch64-unknown-linux-gnu + os: ubuntu-latest bin: jrsonnet - name: jrsonnet-linux-amd64 - - os: windows-latest - rust: stable - target: x86_64-pc-windows-msvc + name: jrsonnet-linux-gnu-aarch64 + - target: i686-pc-windows-gnu + os: windows-latest bin: jrsonnet.exe - name: jrsonnet-windows-amd64.exe - - os: macOS-latest - rust: stable - target: x86_64-apple-darwin + name: jrsonnet-windows-gnu-i686.exe + - target: i686-pc-windows-msvc + os: windows-latest + bin: jrsonnet.exe + name: jrsonnet-windows-msvc-i686.exe + - target: i686-unknown-linux-gnu + os: ubuntu-latest bin: jrsonnet + name: jrsonnet-linux-gnu-i686 + - target: x86_64-apple-darwin + os: macOS-latest + bin: jrsonnet name: jrsonnet-darwin-amd64 + - target: x86_64-pc-windows-gnu + os: windows-latest + bin: jrsonnet.exe + name: jrsonnet-windows-gnu-amd64.exe + - target: x86_64-pc-windows-msvc + os: windows-latest + bin: jrsonnet.exe + name: jrsonnet-windows-msvc-amd64.exe + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + bin: jrsonnet + name: jrsonnet-linux-gnu-amd64 + + - target: x86_64-unknown-linux-musl + os: ubuntu-latest + bin: jrsonnet + name: jrsonnet-linux-musl-amd64 runs-on: ${{ matrix.os }} steps: - name: Install stable toolchain uses: actions-rs/toolchain@v1 with: - toolchain: ${{ matrix.rust }} + toolchain: stable override: true target: ${{ matrix.target }} + - name: Checkout uses: actions/checkout@v2 + + - name: Linux x86 cross compiler + if: ${{ matrix.target == 'i686-unknown-linux-gnu' }} + run: sudo apt install gcc-multilib + + - name: Windows x86 cross compiler + if: ${{ matrix.target == 'i686-pc-windows-gnu' }} + uses: egor-tensin/setup-mingw@v2 + with: + platform: x86 + + - name: ARM cross compiler + if: ${{ matrix.target == 'aarch64-unknown-linux-gnu' }} + uses: actions-rs/cargo@v1 + with: + command: install + args: cross + + - name: Run ARM build + if: ${{ matrix.target == 'aarch64-unknown-linux-gnu' }} + shell: bash + run: cross --bin=jrsonnet --release --target ${{ matrix.target }} + - name: Run build + if: ${{ matrix.target != 'aarch64-unknown-linux-gnu' }} uses: actions-rs/cargo@v1 with: command: build args: --bin=jrsonnet --release --target ${{ matrix.target }} + - name: Package shell: bash run: | @@ -93,8 +153,10 @@ cp ${{ matrix.bin }} ../../../${{ matrix.name }} cd - + - name: Generate SHA-256 run: shasum -a 256 ${{ matrix.name }} > ${{ matrix.name }}.sha256 + - name: Publish uses: softprops/action-gh-release@v1 with: --- a/crates/jrsonnet-evaluator/src/builtin/mod.rs +++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs @@ -1,8 +1,8 @@ use crate::{ equals, error::{Error::*, Result}, - parse_args, primitive_equals, push, throw, with_state, ArrValue, Context, FuncVal, LazyVal, - Val, + parse_args, primitive_equals, push, throw, with_state, ArrValue, Context, EvaluationState, + FuncVal, LazyVal, Val, }; use format::{format_arr, format_obj}; use jrsonnet_interner::IStr; @@ -74,6 +74,7 @@ ("reverse".into(), builtin_reverse), ("id".into(), builtin_id), ("strReplace".into(), builtin_str_replace), + ("parseJson".into(), builtin_parse_json), ].iter().cloned().collect() }; } @@ -164,6 +165,20 @@ }) } +fn builtin_parse_json( + context: Context, + _loc: Option<&ExprLocation>, + args: &ArgsDesc, +) -> Result { + parse_args!(context, "parseJson", args, 1, [ + 0, s: ty!(string) => Val::Str; + ], { + let state = EvaluationState::default(); + let path = Rc::new(PathBuf::from("std.parseJson")); + state.evaluate_snippet_raw(path ,s) + }) +} + // faster fn builtin_slice(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result { parse_args!(context, "slice", args, 4, [ --- a/crates/jrsonnet-evaluator/src/lib.rs +++ b/crates/jrsonnet-evaluator/src/lib.rs @@ -809,6 +809,21 @@ } #[test] + fn parse_json() { + assert_json!( + r#"std.parseJson('{"a": -1,"b": 1,"c": 3.141,"d": []}')"#, + r#"{"a": -1,"b": 1,"c": 3.141,"d": []}"# + ); + // TODO: this should in fact fail as is no proper JSON syntax + assert_json!( + r#"std.parseJson("{a:-1, b:1, c:3.141, d:[]}")"#, + r#"{"a": -1,"b": 1,"c": 3.141,"d": []}"# + ); + // TODO: this is also no valid JSON + assert_json!(r#"std.parseJson('local x = 2; x * x')"#, r#"4"#); + } + + #[test] fn test() { assert_json!( r#"[[a, b] for a in [1,2,3] for b in [4,5,6]]"#,