Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make ruby work again #650

Merged
merged 4 commits into from
Jun 7, 2024
Merged
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: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
PATH_add tools/

eval "$(mise activate bash)"
35 changes: 25 additions & 10 deletions .github/workflows/release_language_client_ruby.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ name: Release engine/language_client_ruby

on:
workflow_dispatch: {}
#push:
# branches:
# - sam/rust-llm

permissions:
contents: read
id-token: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
strategy:
Expand All @@ -23,6 +24,9 @@ jobs:
#- x64-mingw-ucrt

runs-on: ubuntu-latest
defaults:
run:
working-directory: engine/language_client_ruby
steps:
- uses: rubygems/configure-rubygems-credentials@main
with:
Expand All @@ -31,8 +35,6 @@ jobs:

- uses: actions/checkout@v4

- run: cd engine/language_client_ruby

- uses: oxidize-rb/actions/setup-ruby-and-rust@main
with:
rubygems: latest
Expand Down Expand Up @@ -103,13 +105,10 @@ jobs:
gem install rb_sys -v $version
fi

- run: |
echo "Switching to top-level workspace - we need to be able to resolve the root-level Cargo.toml"
cd ..
pwd

- name: Build gem
shell: bash
working-directory: engine
if: ${{ matrix.platform == 'x86_64-linux' }}
run: |
: Compile gem
echo "Docker Working Directory: $(pwd)"
Expand All @@ -123,6 +122,22 @@ jobs:
--build \
-- sudo yum install -y perl-IPC-Cmd

- name: Build gem
shell: bash
working-directory: engine
if: ${{ matrix.platform != 'x86_64-linux' }}
run: |
: Compile gem
echo "Docker Working Directory: $(pwd)"
set -x

rb-sys-dock \
--platform ${{ matrix.platform }} \
--mount-toolchains \
--directory language_client_ruby \
--ruby-versions 3.3,3.2,3.1,3.0,2.7 \
--build

#################################################################################################################
#
# END: these steps are copied from https://github.com/oxidize-rb/actions/blob/main/cross-gem/action.yml
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ $RECYCLE.BIN/
/dist
/node_modules
/out/
engine/language_client_ruby/**/*.bundle
engine/target/
Cargo.lock
Icon
Expand Down
2 changes: 1 addition & 1 deletion .mise.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[tools]
ruby = "3.3.0"
ruby = "3.1"
4 changes: 2 additions & 2 deletions engine/Cargo.lock

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

6 changes: 6 additions & 0 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,11 @@ license-file = "LICENSE"
[workspace.metadata.workspaces]
allow_branch = "canary"

[profile.dev]
lto = false

[profile.dev2]
inherits = "dev"

[profile.release]
lto = true
6 changes: 4 additions & 2 deletions engine/baml-lib/jsonish/src/jsonish/parser/markdown_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ pub fn parse<'a>(str: &'a str, options: &ParseOptions) -> Result<Vec<(String, Va
let mut remaining = str;
// Find regex for markdown blocks (```<tag><EOF|newline>)

let md_tag_start = regex::Regex::new(r"```([a-zA-Z0-9 ]+)(?:\n|$)").expect("Invalid regex");
let md_tag_end = regex::Regex::new(r"```(?:\n|$)").expect("Invalid regex");
let md_tag_start = regex::Regex::new(r"```([a-zA-Z0-9 ]+)(?:\n|$)")
.map_err(|e| anyhow::Error::from(e).context("Failed to build regex for md-tag-start"))?;
let md_tag_end = regex::Regex::new(r"```(?:\n|$)")
.map_err(|e| anyhow::Error::from(e).context("Failed to build regex for md-tag-end"))?;

let mut should_loop = true;

Expand Down
14 changes: 9 additions & 5 deletions engine/baml-runtime/src/cli/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,30 @@ impl GenerateArgs {
if generated.is_empty() {
let client_type = caller_type.into();
// Normally `baml_client` is added via the generator, but since we're not running the generator, we need to add it manually.
let output_dir = src_dir.join("..").join("baml_client");
let output_dir_relative_to_baml_src = PathBuf::from("..");
let generate_output = runtime.generate_client(
&client_type,
&internal_baml_codegen::GeneratorArgs::new(
&output_dir,
&output_dir_relative_to_baml_src.join("baml_client"),
&self.from,
all_files.iter(),
)?,
)?;
println!("Generated 1 baml_client at {}", output_dir.display());
println!(
"Generated 1 baml_client at {}",
generate_output.output_dir.display()
);

println!(
r#"
You can automatically generate a client by adding the following to any one of your BAML files:

generator my_client {{
output_type "{}"
output_dir "../"
output_dir "{}"
}}"#,
generate_output.client_type.to_string()
generate_output.client_type.to_string(),
output_dir_relative_to_baml_src.join("").display(),
);
} else {
println!("Generated {} baml_client", generated.len());
Expand Down
1 change: 0 additions & 1 deletion engine/language-client-codegen/askama.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ dirs = [
# whitespace can be either preserve, suppress, or minimize
# suppress and minimize are both too aggressive for us
whitespace = "preserve"
escape = "none"
4 changes: 2 additions & 2 deletions engine/language-client-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn relative_path_to_baml_src(path: &PathBuf, baml_src: &PathBuf) -> Result<PathB

impl GeneratorArgs {
pub fn new<'i>(
output_dir: impl Into<PathBuf>,
output_dir_relative_to_baml_src: impl Into<PathBuf>,
baml_src_dir: impl Into<PathBuf>,
input_files: impl IntoIterator<Item = (&'i PathBuf, &'i String)>,
) -> Result<Self> {
Expand All @@ -42,7 +42,7 @@ impl GeneratorArgs {
.collect::<Result<_>>()?;

Ok(Self {
output_dir_relative_to_baml_src: output_dir.into(),
output_dir_relative_to_baml_src: output_dir_relative_to_baml_src.into(),
baml_src_dir: baml_src.clone(),
// for the key, whhich is the name, just get the filename
input_file_map,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

file_map = {
{% for k in file_map %}
{{ k.0 }}: {{ k.1 }},
{% for (path, contents) in file_map %}
{{ path }}: {{ contents }},
{%- endfor %}
}

Expand Down
2 changes: 1 addition & 1 deletion engine/language-client-codegen/src/ruby/field_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl ToRuby for FieldType {
TypeValue::String => "String".to_string(),
TypeValue::Null => "NilClass".to_string(),
// TODO: Create Baml::Types::Image
TypeValue::Image => "Baml::Types::Image".to_string(),
TypeValue::Image => "Baml::Image".to_string(),
},
FieldType::Union(inner) => format!(
// https://sorbet.org/docs/union-types
Expand Down
Loading
Loading