Merge pull request #256 from XRPLF/fix/compile-result
Fix incorrect compilation result.
This commit is contained in:
@@ -29,25 +29,30 @@ export const compileCode = async (activeId: number) => {
|
|||||||
const file = state.files[activeId]
|
const file = state.files[activeId]
|
||||||
try {
|
try {
|
||||||
file.containsErrors = false
|
file.containsErrors = false
|
||||||
const res = await fetch(process.env.NEXT_PUBLIC_COMPILE_API_ENDPOINT, {
|
let res: Response
|
||||||
method: "POST",
|
try {
|
||||||
headers: {
|
res = await fetch(process.env.NEXT_PUBLIC_COMPILE_API_ENDPOINT, {
|
||||||
"Content-Type": "application/json",
|
method: "POST",
|
||||||
},
|
headers: {
|
||||||
body: JSON.stringify({
|
"Content-Type": "application/json",
|
||||||
output: "wasm",
|
},
|
||||||
compress: true,
|
body: JSON.stringify({
|
||||||
strip: state.compileOptions.strip,
|
output: "wasm",
|
||||||
files: [
|
compress: true,
|
||||||
{
|
strip: state.compileOptions.strip,
|
||||||
type: "c",
|
files: [
|
||||||
options: state.compileOptions.optimizationLevel || '-O2',
|
{
|
||||||
name: file.name,
|
type: "c",
|
||||||
src: file.content,
|
options: state.compileOptions.optimizationLevel || '-O2',
|
||||||
},
|
name: file.name,
|
||||||
],
|
src: file.content,
|
||||||
}),
|
},
|
||||||
});
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
throw Error("Something went wrong, check your network connection and try again!")
|
||||||
|
}
|
||||||
const json = await res.json();
|
const json = await res.json();
|
||||||
state.compiling = false;
|
state.compiling = false;
|
||||||
if (!json.success) {
|
if (!json.success) {
|
||||||
@@ -61,29 +66,34 @@ export const compileCode = async (activeId: number) => {
|
|||||||
}
|
}
|
||||||
throw errors
|
throw errors
|
||||||
}
|
}
|
||||||
state.logs.push({
|
try {
|
||||||
type: "success",
|
// Decode base64 encoded wasm that is coming back from the endpoint
|
||||||
message: `File ${state.files?.[activeId]?.name} compiled successfully. Ready to deploy.`,
|
const bufferData = await decodeBinary(json.output);
|
||||||
link: Router.asPath.replace("develop", "deploy"),
|
|
||||||
linkText: "Go to deploy",
|
// Import wabt from and create human readable version of wasm file and
|
||||||
});
|
// put it into state
|
||||||
// Decode base64 encoded wasm that is coming back from the endpoint
|
const ww = (await import('wabt')).default()
|
||||||
const bufferData = await decodeBinary(json.output);
|
|
||||||
file.compiledContent = ref(bufferData);
|
|
||||||
file.lastCompiled = new Date();
|
|
||||||
file.compiledValueSnapshot = file.content
|
|
||||||
// Import wabt from and create human readable version of wasm file and
|
|
||||||
// put it into state
|
|
||||||
import("wabt").then((wabt) => {
|
|
||||||
const ww = wabt.default();
|
|
||||||
const myModule = ww.readWasm(new Uint8Array(bufferData), {
|
const myModule = ww.readWasm(new Uint8Array(bufferData), {
|
||||||
readDebugNames: true,
|
readDebugNames: true,
|
||||||
});
|
});
|
||||||
myModule.applyNames();
|
myModule.applyNames();
|
||||||
|
|
||||||
const wast = myModule.toText({ foldExprs: false, inlineExport: false });
|
const wast = myModule.toText({ foldExprs: false, inlineExport: false });
|
||||||
state.files[state.active].compiledWatContent = wast;
|
|
||||||
toast.success("Compiled successfully!", { position: "bottom-center" });
|
file.compiledContent = ref(bufferData);
|
||||||
|
file.lastCompiled = new Date();
|
||||||
|
file.compiledValueSnapshot = file.content
|
||||||
|
file.compiledWatContent = wast;
|
||||||
|
} catch (error) {
|
||||||
|
throw Error("Invalid compilation result produced, check your code for errors and try again!")
|
||||||
|
}
|
||||||
|
|
||||||
|
toast.success("Compiled successfully!", { position: "bottom-center" });
|
||||||
|
state.logs.push({
|
||||||
|
type: "success",
|
||||||
|
message: `File ${state.files?.[activeId]?.name} compiled successfully. Ready to deploy.`,
|
||||||
|
link: Router.asPath.replace("develop", "deploy"),
|
||||||
|
linkText: "Go to deploy",
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@@ -96,12 +106,19 @@ export const compileCode = async (activeId: number) => {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
else if (err instanceof Error) {
|
||||||
|
state.logs.push({
|
||||||
|
type: "error",
|
||||||
|
message: err.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
state.logs.push({
|
state.logs.push({
|
||||||
type: "error",
|
type: "error",
|
||||||
message: "Something went wrong, check your connection try again later!",
|
message: "Something went wrong, come back later!",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
state.compiling = false;
|
state.compiling = false;
|
||||||
toast.error(`Error occurred while compiling!`, { position: "bottom-center" });
|
toast.error(`Error occurred while compiling!`, { position: "bottom-center" });
|
||||||
file.containsErrors = true
|
file.containsErrors = true
|
||||||
|
|||||||
Reference in New Issue
Block a user