Module: Vcvars
- Defined in:
- lib/vcvars.rb,
lib/vcvars/cli.rb,
lib/vcvars/rake.rb,
lib/vcvars/doctor.rb,
lib/vcvars/locator.rb,
lib/vcvars/version.rb,
lib/vcvars/scaffold.rb,
lib/vcvars/environment.rb
Overview
vcvars — locate Visual Studio and load the MSVC build environment so that native C extensions build under an mswin (MSVC) Ruby without first opening a “Developer Command Prompt”.
require "vcvars"
Vcvars.activate! # cl.exe / nmake.exe now on PATH in this process
Or, in a Rakefile that uses rake-compiler:
require "vcvars/rake" # auto-activates; then Rake::ExtensionTask.new ...
Defined Under Namespace
Modules: Doctor, Environment, Locator Classes: CLI, Error, Scaffold
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
-
.activate!(arch: Locator.default_arch, force: false) ⇒ Object
Locate VS and import the MSVC environment into this process’s ENV.
-
.active? ⇒ Boolean
Is a developer environment already active in this process?.
-
.enhance_compile_task!(task_name = "compile") ⇒ Object
Optional belt-and-suspenders: call AFTER defining your compile task to also guarantee activation as a task dependency (covers sub-rake invocations that bypass the load-time activation above).
-
.env(arch: Locator.default_arch) ⇒ Object
The MSVC environment variables vcvars would add/change (without mutating ENV).
-
.locate(arch: Locator.default_arch) ⇒ Object
Locate the Visual Studio installation.
-
.mswin? ⇒ Boolean
True when the running Ruby is a native MSVC (mswin) build.
Class Method Details
.activate!(arch: Locator.default_arch, force: false) ⇒ Object
Locate VS and import the MSVC environment into this process’s ENV. No-op (returns false) if a developer environment is already active.
30 31 32 |
# File 'lib/vcvars.rb', line 30 def activate!(arch: Locator.default_arch, force: false) Environment.activate!(arch: arch, force: force) end |
.active? ⇒ Boolean
Is a developer environment already active in this process?
35 36 37 |
# File 'lib/vcvars.rb', line 35 def active? Environment.active? end |
.enhance_compile_task!(task_name = "compile") ⇒ Object
Optional belt-and-suspenders: call AFTER defining your compile task to also guarantee activation as a task dependency (covers sub-rake invocations that bypass the load-time activation above).
Rake::ExtensionTask.new("my_ext", spec)
Vcvars.enhance_compile_task!
35 36 37 38 39 40 41 |
# File 'lib/vcvars/rake.rb', line 35 def self.enhance_compile_task!(task_name = "compile") return unless mswin? return unless defined?(Rake) && Rake::Task.task_defined?(task_name) Rake::Task.define_task("vcvars:activate") { Vcvars.activate! } Rake::Task[task_name].enhance(["vcvars:activate"]) end |
.env(arch: Locator.default_arch) ⇒ Object
The MSVC environment variables vcvars would add/change (without mutating ENV).
45 46 47 |
# File 'lib/vcvars.rb', line 45 def env(arch: Locator.default_arch) Environment.delta(arch: arch) end |
.locate(arch: Locator.default_arch) ⇒ Object
Locate the Visual Studio installation. Returns a Locator::Installation or nil.
40 41 42 |
# File 'lib/vcvars.rb', line 40 def locate(arch: Locator.default_arch) Locator.find(arch: arch) end |
.mswin? ⇒ Boolean
True when the running Ruby is a native MSVC (mswin) build.
24 25 26 |
# File 'lib/vcvars.rb', line 24 def mswin? RbConfig::CONFIG["target_os"].to_s =~ /mswin/ ? true : false end |