Skip to content

Commit

Permalink
Add scratch preset_id field for decomp.me
Browse files Browse the repository at this point in the history
Resolves #133
  • Loading branch information
encounter committed Nov 7, 2024
1 parent ebf6538 commit a119d9a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions objdiff-core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ pub struct ScratchConfig {
pub ctx_path: Option<PathBuf>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub build_ctx: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub preset_id: Option<u32>,
}

pub const CONFIG_FILENAMES: [&str; 3] = ["objdiff.json", "objdiff.yml", "objdiff.yaml"];
Expand Down
1 change: 1 addition & 0 deletions objdiff-gui/src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl ScratchConfigV1 {
c_flags: self.c_flags,
ctx_path: self.ctx_path,
build_ctx: self.build_ctx.then_some(true),
preset_id: None,
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions objdiff-gui/src/jobs/create_scratch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct CreateScratchConfig {
pub compiler_flags: String,
pub function_name: String,
pub target_obj: PathBuf,
pub preset_id: Option<u32>,
}

impl CreateScratchConfig {
Expand All @@ -45,6 +46,7 @@ impl CreateScratchConfig {
compiler_flags: scratch_config.c_flags.clone().unwrap_or_default(),
function_name,
target_obj: target_path.to_path_buf(),
preset_id: scratch_config.preset_id,
})
}

Expand Down Expand Up @@ -101,15 +103,18 @@ fn run_create_scratch(
let obj_path = project_dir.join(&config.target_obj);
let file = reqwest::blocking::multipart::Part::file(&obj_path)
.with_context(|| format!("Failed to open {}", obj_path.display()))?;
let form = reqwest::blocking::multipart::Form::new()
let mut form = reqwest::blocking::multipart::Form::new()
.text("compiler", config.compiler.clone())
.text("platform", config.platform.clone())
.text("compiler_flags", config.compiler_flags.clone())
.text("diff_label", config.function_name.clone())
.text("diff_flags", diff_flags)
.text("context", context.unwrap_or_default())
.text("source_code", "// Move related code from Context tab to here")
.part("target_obj", file);
.text("source_code", "// Move related code from Context tab to here");
if let Some(preset) = config.preset_id {
form = form.text("preset", preset.to_string());
}
form = form.part("target_obj", file);
let client = reqwest::blocking::Client::new();
let response = client
.post(formatcp!("{API_HOST}/api/scratch"))
Expand Down

0 comments on commit a119d9a

Please sign in to comment.