I want to have a class library that will run under WinRT and also Windows Phone 8. What do I need to do?
+1 on Cerebrate's answer. portable class libraries is the way to go.
However, PCL aren't a magic wand and won't bridge many of the inconsistencies between WP8 and Win8. For more hardcore code sharing you'll need to consider sharing C# files, adding conditional compilation and many other tricks. Nokia has a great article on WP7 and WP8 code sharing that would apply to this case as well @ http://www.developer.nokia.com/Resources/Library/Lumia/#!co-development-and-porting-guide.html
There's also this great Nokia Wiki article with similar intents @ http://www.developer.nokia.com/Community/Wiki/Maintaining_a_WP7_and_WP8_version_of_a_same_Silverlight_application
To do that, you need to build your class library as a Portable Class Library, which creates an assembly that will run on multiple platforms. (Otherwise, assemblies for WinRT and Windows Phone 8 are essentially non-interchangeable.)
Visual Studio 2012 includes a project type that will let you do this easily; there is also a downloadable toolset that will let do this on VS 2010.
The framework functionality available is limited to a subset of that which is available on all of the platforms you are supporting.
Full details are available from MSDN, here: http://msdn.microsoft.com/en-us/library/gg597391.aspx