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

Investigate mono support #80

Closed
glennblock opened this issue Mar 10, 2013 · 45 comments
Closed

Investigate mono support #80

glennblock opened this issue Mar 10, 2013 · 45 comments

Comments

@glennblock
Copy link
Contributor

Figure out if we could get scriptcs working for mono. Roslyn allows you to pass host objects into the running script. Ideally this feature which script packs rely on will also work.

@pbgodwin
Copy link

Do we know if Roslyn will run on top of the Mono VM? I'm assuming that, if it is pure Managed Code as they say it is, we shouldn't see any issues, correct? If not, would the best course of action be to create a ScriptEngine/ScriptExecutor implementation that wraps around the Mono.CSharp or NRefactory APIs? I'll poke around at this when I can get back to my desk and get a *nix distro setup with MonoDevelop, because this interests me.

@jrusbatch
Copy link
Member

Roslyn will not run on Mono, unfortunately. The classes will need to be reimplemented without Roslyn.

nberardi pushed a commit to nberardi/scriptcs that referenced this issue Mar 11, 2013
nberardi pushed a commit to nberardi/scriptcs that referenced this issue Mar 11, 2013
@follesoe
Copy link

Mono has had a C# REPL, and C# scripting support for some time. It shouldn't be too hard to get it running on Mono.

Some relevant links:

http://www.mono-project.com/CsharpRepl
http://www.mono-project.com/CSharp_Compiler

However, according to the docs it looks like the Mono C# Compiler Service has some limitations:

The Mono.CSharp.dll assembly is a repackaging of Mono's C# compiler and provides access to the C# compiler as a service. It implements a C# eval. It allows applications to compile and execute C# statements and expressions at runtime.

This API is not yet final and will likely change as we get a better understanding of how developers will like to use the Mono C# Compiler Service. You can make a local copy of the Mono.CSharp.dll assembly and reference that locally as we are not commiting to the stability of this API yet.

The evaluator currently exposes a statement and expression API and will allow the consumer to execute statements or compute the value of expressions and get the results back. Support for compiling classes will appear in a future version."

But after looking at the sample code from http://blog.davidebbo.com/2012/02/quick-fun-with-monos-csharp-compiler-as.html it looks like Mono has full support compling C# code:

using System;
using System.IO;
using Mono.CSharp;

namespace MonoCompilerDemo
{
    public interface IFoo { string Bar(string s); }

    class Program
    {
        static void Main(string[] args)
        {
            var evaluator = new Evaluator(
                new CompilerSettings(),
                new Report(new ConsoleReportPrinter()));

            // Make it reference our own assembly so it can use IFoo
            evaluator.ReferenceAssembly(typeof(IFoo).Assembly);

            // Feed it some code
            evaluator.Compile(
                @"
    public class Foo : MonoCompilerDemo.IFoo
    {
        public string Bar(string s) { return s.ToUpper(); }
    }");

            for (; ; )
            {
                string line = Console.ReadLine();
                if (line == null) break;

                object result;
                bool result_set;
                evaluator.Evaluate(line, out result, out result_set);
                if (result_set) Console.WriteLine(result);
            }
        }
    }
}

Adding Mono support would require isolating dependency on Roslyn. The Mono C# compiler is available as a NuGet package, and can be used as any .NET assembly, and do not require Mono. This makes it easier to test/work on Mono-support from standard .NET/VS environment: https://nuget.org/packages/Mono.CSharp

@follesoe
Copy link

I did a quick spike to test if I could get scriptcs running with Mono.CSharp as its back-end. I was able to compile/run simple scripts such as:

using System;

Func<int, int, int> add = (int a, int b) => a + b;

Console.WriteLine("add({0}, {1}) = {2}", 1, 2, add(1, 2));

The main issue (as far as I can tell), is how Mono.CSharp has Evaluator.Compile and Evaluator.Evaluate. When In Roslyn both simple expressions and things like class definitions are all feed into the Execute method, but for Mono.CSharp you need to Compile your classes before you can Evaluate expresions. Since the SessionWrapper.Execute method is feed the complete, concatenated script, you cannot (as far as I can tell) compile, nor evaluate it directly in Mono.CSharp.

The commit for my experiment is available at follesoe@cfd648f in the mono-experiments branch.

The branch is not intended for any PR etc, but I'll keep it around for reference if some one else want to further explore the possibility to use Mono.CSharp instead of Roslyn.

glennblock added a commit that referenced this issue Mar 13, 2013
Refactored roslyn out of core to fix #90 in preperation for #80
@glennblock
Copy link
Contributor Author

Thanks for doing the investigative work here @follesoe!

We just PR'd a signifiant change from @nberardi that refactors into a pluggable script engine model with Roslyn being the first of many possible engines. The road for Mono is now wide open.....

@follesoe
Copy link

Great work - when I have some time again I'll do another spike, based on the changes to the pluggable script enginge. Need to learn more about Mono.CSharp to understand what needs to be compiled vs evaluated.

@dragan
Copy link

dragan commented Mar 13, 2013

@follesoe Are you working on this outside of Windows?

@dragan
Copy link

dragan commented Mar 13, 2013

@follesoe Just an FYI, I'm working off your mono-experiments branch here.

@glennblock
Copy link
Contributor Author

@dragan I was hoping you'd join us! Thanks!

@glennblock
Copy link
Contributor Author

Welcome!

On Wed, Mar 13, 2013 at 2:31 PM, Dale Ragan notifications@github.comwrote:

@follesoe https://github.com/follesoe Just an FYI, I'm working off your
mono-experiments branch herehttps://github.com/dragan/scriptcs/tree/mono-experiments
.


Reply to this email directly or view it on GitHubhttps://github.com//issues/80#issuecomment-14869885
.

@dragan
Copy link

dragan commented Mar 14, 2013

Okay, played enough with this branch, going to start a new branch with the latest changes that pulled Roslyn out. Too much changed between this branch and that being merged into dev.

@follesoe
Copy link

@dragan Yeah - I did a new experiment on the plane yesterday, using the new architecture with external enginges. The new architecture makes it dead simple to plug-in new compilers. As far as I can tell, the hard part will be to understand/use Mono.CSharp correctly. I.e. when to Compile/Run/Evaluate some code. In Roslyn its a simple call to Execute - while in Mono you need to compile classes/methods etc, but can evaluate expressions. Not sure if one would need to parse the passed in Code first, before passing it to the evaluator.

@nberardi
Copy link

@dragan @follesoe if you see any rough spots with the current of the pluggable engine architecture please let me know. I spent a lot of time trying to reduce the interface so that it didn't make too make decisions on how an engine should operate.

@glennblock
Copy link
Contributor Author

Feel free to ping me as well.

On Thu, Mar 14, 2013 at 9:52 AM, Nick Berardi notifications@github.comwrote:

@dragan https://github.com/dragan @follesoehttps://github.com/follesoeif you see any rough spots with the current of the pluggable engine
architecture please let me know. I spent a lot of time trying to reduce the
interface so that it didn't make too make decisions on how an engine should
operate.


Reply to this email directly or view it on GitHubhttps://github.com//issues/80#issuecomment-14914275
.

@acken
Copy link

acken commented Mar 14, 2013

@follesoe @dragan AFAIK the mono c# repls don't support classes/methods/members. Maybe use the monodevelop/sharpdevelop ast parser or something similar?

EDIT: Giving it a bit more though it would be a lot easier to pull the eval part out and compile the rest as a whole. When talking to Marek I recall him saying that it supports being handed a file / class / function for compile.

@dragan
Copy link

dragan commented Mar 15, 2013

Currently blocked with the changes added for MEF recently. Issue #117 was created to replace MEF with Autofac so work can continue on Mono support.

@glennblock
Copy link
Contributor Author

@dragan PR is here: #118. Actually ended up using Autofac for all internal dependencies and the MEF (via the Autofac integration) for script packs. It's using MEF 4.0 though so should work fine with Mono.

@dragan
Copy link

dragan commented Mar 15, 2013

@glennblock Okay, as old Phil Robertson would say from Duck Dynasty, "Now we're cooking with peanut oil"! Everything is compiling under mono again. Time to start implementing and get the tests passing! You can watch my branch if interested.

@filipw
Copy link
Member

filipw commented Mar 15, 2013

@dragan it's merged now too

dragan added a commit to dragan/scriptcs that referenced this issue Mar 15, 2013
dragan added a commit to dragan/scriptcs that referenced this issue Mar 15, 2013
@glennblock
Copy link
Contributor Author

I love it when a plan comes together!

dragan added a commit to dragan/scriptcs that referenced this issue Mar 16, 2013
dragan added a commit to dragan/scriptcs that referenced this issue Mar 16, 2013
@dragan
Copy link

dragan commented Mar 17, 2013

@glennblock Mind bumping the Autofac version down to 2.6.3.862? I believe 3.0 was built with Client Profile and Mono doesn't support Client Profiles yet. We also need to talk about how you want to handle the registration based on runtime and etc. I also have another request to help with MonoDevelop loading the project files. It doesn't have support for common properties between projects. I've been dealing with it, but it's time to fix it.

@filipw
Copy link
Member

filipw commented Mar 17, 2013

@dragan yes Autofac 3 is a PCL. We talked about that yesterday, and there is no real reason why we use 3.0 (just happens to be the latest) and we sure can go down a version (that was the whole point of going to Autofac - to facilitate Mono)

@dragan
Copy link

dragan commented Mar 17, 2013

@filipw Great, yeah I just wanted to make sure that he didn't use the latest for a specific feature.

@glennblock
Copy link
Contributor Author

@dragan can you just do the change and submit it along with your PR?

dragan added a commit to dragan/scriptcs that referenced this issue Mar 17, 2013
@dragan
Copy link

dragan commented Mar 17, 2013

@glennblock Done, ignore the typo in the commit message. ;-)

@dragan
Copy link

dragan commented Mar 17, 2013

Still work to do, but I have ScriptCS working under Mono. Need to get the NuGet package for Mono.CSharp updated before I can check things in. You can execute a simple .csx file that contains interfaces, classes, methods, and expressions. :-D

@glennblock
Copy link
Contributor Author

Great

-----Original Message-----
From: "Dale Ragan" notifications@github.com
Sent: ‎3/‎17/‎2013 10:31 AM
To: "scriptcs/scriptcs" scriptcs@noreply.github.com
Cc: "Glenn Block" glenn.block@gmail.com
Subject: Re: [scriptcs] Investigate mono support (#80)

@glennblock Done, ignore the typo in the commit message. ;-)

Reply to this email directly or view it on GitHub.

@glennblock
Copy link
Contributor Author

Awesome!

What are you planning around script packs?

-----Original Message-----
From: "Dale Ragan" notifications@github.com
Sent: ‎3/‎17/‎2013 11:13 AM
To: "scriptcs/scriptcs" scriptcs@noreply.github.com
Cc: "Glenn Block" glenn.block@gmail.com
Subject: Re: [scriptcs] Investigate mono support (#80)

Still work to do, but I have ScriptCS working under Mono. Need to get the NuGet package for Mono.CSharp updated before I can check things in. You can execute a simple .csx file that contains interfaces, classes, methods, and expressions. :-D

Reply to this email directly or view it on GitHub.

@glennblock
Copy link
Contributor Author

Update here. We need to move this forward ;-). In order to help we've taken a few steps.

  1. We've created a "mono" branch where all work can be done around mono.
  2. We've add a "mono" tag. (You can see this issue has it). We'd like all issues related to mono to be filed in this repo and we'll tag them with "mono".

We hope that both of these steps will give more visibility to the state of mono support and make it easier for others to contribute, like @migueldeicaza;-)

Have at it @dragan, @jden, @larsw et al!

@junosuarez
Copy link

Thanks @glennblock!

@glennblock
Copy link
Contributor Author

Allright all, Filip is moving the ball forward. He created a mono engine here (https://github.com/scriptcs-contrib/scriptcs-engine-mono) that has some basic functionality. There are still many challenges, for one thing we're really not happy with perf.

Adding @migueldeicaza in hopes someone from the mono team can jump in :-)

He needs your help!

ztone pushed a commit to ztone/scriptcs that referenced this issue May 4, 2014
ztone pushed a commit to ztone/scriptcs that referenced this issue May 4, 2014
ztone pushed a commit to ztone/scriptcs that referenced this issue May 4, 2014
Refactored roslyn out of core to fix scriptcs#90 in preperation for scriptcs#80
ztone pushed a commit to ztone/scriptcs that referenced this issue May 4, 2014
# By Nick Berardi (8) and others
# Via dschenkelman (6) and others
* dev:
  Added error messages with line number when using -debug in console
  # Deleted DebugFilePreProcessor.cs. No longer needed with support for debugging in VS
  # Updated FilePreProcessor.cs, FileProcessorTests.cs and RoslynScriptDebuggerEngine.cs to add #line directives after #loads
  fixed bug with #r not loading, and set #load to only be available at the top scriptcs#105 scriptcs#98 scriptcs#21
  removed IDisposable from ScriptPackSession
  Update ScriptCs.Engine.Roslyn.csproj
  Update ScriptCs.Engine.Roslyn.Tests.csproj
  Update ScriptCs.Engine.Roslyn.csproj
  moved ScriptHostFactory into Roslyn since the script host is Roslyn specific
  # Simplified code for IScriptEngine constructor convention. Thanks to @khellang for the code review.
  # Removed namespaces that are no longer used
  added [InheritedExport] back onto IScriptEngine
  refactored code to bring ScriptPackSession back into the core
  # Updated code base to get rid of MEF attributes and use RegistrationBuilder
  refactored roslyn out of core to fix scriptcs#90 in preperation for scriptcs#80
@adamralph
Copy link
Contributor

Can we close this?

@glennblock
Copy link
Contributor Author

YES!!!!!

@glennblock
Copy link
Contributor Author

This PR: #635 adds support for Mono to the core. Several other PRs follow which improve on the Mono support specifically dealing with multi-line and the REPL.

@filipw
Copy link
Member

filipw commented May 27, 2014

we can delete the mono branch too now

On 27 May 2014 09:31, Glenn Block notifications@github.com wrote:

This PR: #635 #635 adds
support for Mono to the core. Several other PRs follow which improve on the
Mono support specifically dealing with multi-line and the REPL.


Reply to this email directly or view it on GitHubhttps://github.com//issues/80#issuecomment-44243511
.

@glennblock
Copy link
Contributor Author

@filipw look when opened this, March 2013!

@adamralph
Copy link
Contributor

mono branch deleted (it was fully merged)

@mika76
Copy link

mika76 commented Apr 20, 2015

I see this was merged to core, but see no references to linux or OS X in docs. Did I miss it somewhere? How to install and run under different platforms?

@khellang
Copy link
Member

@mika76 You didn't see this empty page? 😝 https://github.com/scriptcs/scriptcs/wiki/Installing-on-Mac-and-Linux

@todthomson
Copy link

@mika76 check out the following:

https://github.com/scriptcs/scriptcs#building-from-source

https://github.com/scriptcs/scriptcs/wiki/Building-on-Mac-and-Linux

If you're a Mac / Homebrew (http://brew.sh/) user you can just brew install scriptcs.

@khellang
Copy link
Member

@mika76 The easiest way to get it is probably by installing SVM and getting it from there: https://github.com/scriptcs-contrib/svm/wiki/Installing-svm. It has instructions on installing on OSX and Linux 😄

@adamralph
Copy link
Contributor

@mika76
Copy link

mika76 commented Apr 20, 2015

Cool, thanks guys. May I recommend you put a link or description of that wiki page on the main pages (github readme and the github site) since it's all very Windows based. (I'm talking about installing and running, not so much building)

@adamralph
Copy link
Contributor

Agreed. I've already raised an issue to sort out the readme #1023

I've just raised an issue to update the website #1024

Thanks for prompting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests