Skip to content

Commit

Permalink
Begin CompileContracts with solcjs.
Browse files Browse the repository at this point in the history
  • Loading branch information
allisterb committed Nov 22, 2024
1 parent 6a30f92 commit b527d8e
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/Stratis.VS.SolidityProjectBuildTasks/CompileContracts.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
Expand All @@ -18,8 +20,24 @@ public class CompileContracts : Task

public override bool Execute()
{
Log.LogMessage(MessageImportance.High, "{0}:{1}", ExtDir, Contracts.Select(c => c.ItemSpec).ToArray());
return true;
var solcpath = Directory.Exists(Path.Combine(ProjectDir, "node_modules", "solc", "solc.js")) ? Path.Combine(ProjectDir, "node_modules", "solc", "solc.js") :
Path.Combine(ExtDir, "node_modules", "solc", "solc.js");
Log.LogMessage(MessageImportance.High, "Compiling {0} files in directory:{1}", Contracts.Count(), ProjectDir);


var psi = new ProcessStartInfo("cmd.exe", "/c node" + solcpath + " --base-path=\"" + ProjectDir + "\"")
{
WorkingDirectory = ProjectDir,
CreateNoWindow = true,
RedirectStandardOutput = false,
RedirectStandardInput = false,
RedirectStandardError = false,
};
var p = new Process()
{
StartInfo = psi
};
return false;
}
}
}
117 changes: 117 additions & 0 deletions src/Stratis.VS.SolidityProjectBuildTasks/SolidityCompilerIO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
namespace Stratis.VS.StratisEVM.SolidityCompilerIO
{
using System;
using System.Collections.Generic;

using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

public partial class SolidityCompilerInput
{
[JsonProperty("language")]
public string Language { get; set; }

[JsonProperty("sources")]
public Sources Sources { get; set; }

[JsonProperty("settings")]
public Settings Settings { get; set; }
}

public partial class Settings
{
[JsonProperty("remappings")]
public string[] Remappings { get; set; }

[JsonProperty("optimizer")]
public Optimizer Optimizer { get; set; }

[JsonProperty("evmVersion")]
public string EvmVersion { get; set; }

[JsonProperty("metadata")]
public Metadata Metadata { get; set; }

[JsonProperty("libraries")]
public Libraries Libraries { get; set; }

[JsonProperty("outputSelection")]
public OutputSelection OutputSelection { get; set; }
}

public partial class Libraries
{
[JsonProperty("myFile.sol")]
public LibrariesMyFileSol MyFileSol { get; set; }
}

public partial class LibrariesMyFileSol
{
[JsonProperty("MyLib")]
public string MyLib { get; set; }
}

public partial class Metadata
{
[JsonProperty("useLiteralContent")]
public bool UseLiteralContent { get; set; }
}

public partial class Optimizer
{
[JsonProperty("enabled")]
public bool Enabled { get; set; }

[JsonProperty("runs")]
public long Runs { get; set; }
}

public partial class OutputSelection
{
[JsonProperty("*")]
public Empty Empty { get; set; }

[JsonProperty("def")]
public Def Def { get; set; }
}

public partial class Def
{
[JsonProperty("MyContract")]
public string[] MyContract { get; set; }
}

public partial class Empty
{
[JsonProperty("")]
public string[] Purple { get; set; }
}

public partial class Sources
{
[JsonProperty("myFile.sol")]
public SourcesMyFileSol MyFileSol { get; set; }

[JsonProperty("mortal")]
public Mortal Mortal { get; set; }
}

public partial class Mortal
{
[JsonProperty("keccak256")]
public string Keccak256 { get; set; }

[JsonProperty("content")]
public string Content { get; set; }
}

public partial class SourcesMyFileSol
{
[JsonProperty("keccak256")]
public string Keccak256 { get; set; }

[JsonProperty("urls")]
public string[] Urls { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.6.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

</Project>

0 comments on commit b527d8e

Please sign in to comment.